condTimedWait fixed
authorAlex Kirhenshtein <alk@netxms.org>
Wed, 2 Feb 2005 22:32:17 +0000 (22:32 +0000)
committerAlex Kirhenshtein <alk@netxms.org>
Wed, 2 Feb 2005 22:32:17 +0000 (22:32 +0000)
file transfers fixed
agent upgrade script fixed

14 files changed:
contrib/installAgent.sh
include/nms_threads.h
include/nms_util.h
src/agent/core/session.cpp
src/libnetxms/main.cpp
src/libnxcl/comm.cpp
src/libnxcl/session.cpp
src/server/core/admin.cpp
src/server/core/email.cpp
src/server/core/session.cpp
src/server/libnxsrv/agent.cpp
src/server/tools/nxadm/comm.cpp
src/server/tools/nxadm/nxadm.h
tools/stub.sh

index 3443de0..f3b89cb 100755 (executable)
@@ -47,7 +47,7 @@ if [ $? != 0 ]; then
 fi
 
 # do configure
-./configure --prefix=$prefix --with-agent $configureAdd >/dev/null
+./configure --prefix=$prefix --with-agent $configureAdd 2>/dev/null >/dev/null
 if [ $? != 0 ]; then
        echo configure failed, duh
        exit 4
index 6cb7a47..f7da289 100644 (file)
@@ -375,9 +375,17 @@ inline BOOL ConditionWait(CONDITION cond, DWORD dwTimeOut)
                        struct timeval now;
                        struct timespec timeout;
 
+                       // FIXME there should be more accurate way
                        gettimeofday(&now, NULL);
                        timeout.tv_sec = now.tv_sec + (dwTimeOut / 1000);
-                       timeout.tv_nsec = ( now.tv_usec + ( dwTimeOut % 1000 ) * 1000) * 1000;
+
+                       timeout.tv_nsec = now.tv_usec * 1000;
+                       timeout.tv_nsec += (dwTimeOut % 1000) * 1000;
+                       if (timeout.tv_nsec >= 6000000)
+                       {
+                               timeout.tv_sec += timeout.tv_nsec / 6000000;
+                               timeout.tv_nsec = timeout.tv_nsec % 6000000;
+                       }
                        retcode = pthread_cond_timedwait(&cond->cond, &cond->mutex, &timeout);
 #endif
                }
index 643e2f0..162332f 100644 (file)
@@ -170,6 +170,7 @@ typedef struct _dir_struc
 extern "C"
 {
 #endif
+       int SendEx(int, const void *, size_t, int);
 #if defined(_WIN32) || !(HAVE_DECL___BSWAP_64)
    QWORD LIBNETXMS_EXPORTABLE __bswap_64(QWORD qwVal);
 #endif
index 401b66d..ce3f735 100644 (file)
@@ -239,7 +239,7 @@ void CommSession::WriteThread(void)
          break;
 
       DebugPrintf("Sending message %s", CSCPMessageCodeName(ntohs(pMsg->wCode), szBuffer));
-      if (send(m_hSocket, (const char *)pMsg, ntohl(pMsg->dwSize), 0) <= 0)
+      if (SendEx(m_hSocket, (const char *)pMsg, ntohl(pMsg->dwSize), 0) <= 0)
       {
          free(pMsg);
          break;
index 3bc85d0..333f841 100644 (file)
@@ -135,3 +135,22 @@ int _fini(void)
 }
 
 #endif
+
+int LIBNETXMS_EXPORTABLE SendEx(int nSocket, const void *pBuff,
+               size_t nSize, int nFlags)
+{
+       int nLeft = nSize;
+       int nRet;
+
+       do
+       {
+               nRet = send(nSocket, ((char *)pBuff) + (nSize - nLeft), nLeft, nFlags);
+               if (nRet <= 0)
+               {
+                       break;
+               }
+               nLeft -= nRet;
+       } while (nLeft > 0);
+
+       return nLeft == 0 ? nSize : nRet;
+}
index 243d240..30d25c4 100644 (file)
@@ -23,6 +23,9 @@
 
 #include "libnxcl.h"
 
+// for TCP_NODELAY
+//#include "netinet/tcp.h"
+
 
 //
 // Network receiver thread
@@ -208,6 +211,10 @@ DWORD LIBNXCL_EXPORTABLE NXCConnect(TCHAR *pszServer, TCHAR *pszLogin,
       // Create socket
       if ((hSocket = socket(AF_INET, SOCK_STREAM, 0)) != -1)
       {
+                       // enable TCP_NODELAY
+                       //int nVal = 1;
+                       //setsockopt(hSocket, IPPROTO_TCP, TCP_NODELAY, &nVal, sizeof(nVal));
+
          // Connect to target
          if (connect(hSocket, (struct sockaddr *)&servAddr, sizeof(struct sockaddr_in)) == 0)
          {
index 006bf62..a9ed010 100644 (file)
@@ -184,7 +184,7 @@ BOOL NXCL_Session::SendMsg(CSCPMessage *pMsg)
 
    DebugPrintf(_T("SendMsg(\"%s\"), id:%ld)"), CSCPMessageCodeName(pMsg->GetCode(), szBuffer), pMsg->GetId());
    pRawMsg = pMsg->CreateMessage();
-   bResult = (send(m_hSocket, (char *)pRawMsg, ntohl(pRawMsg->dwSize), 0) == (int)ntohl(pRawMsg->dwSize));
+   bResult = (SendEx(m_hSocket, (char *)pRawMsg, ntohl(pRawMsg->dwSize), 0) == (int)ntohl(pRawMsg->dwSize));
    free(pRawMsg);
    return bResult;
 }
index 14e6eaa..83e5ec2 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: admin.cpp,v 1.6 2005-01-18 15:51:42 alk Exp $ */
+/* $Id: admin.cpp,v 1.7 2005-02-02 22:32:16 alk Exp $ */
 
 /* 
 ** NetXMS - Network Management System
 #define SEND_ERROR() \
    { \
       wCmd = LA_RESP_ERROR; \
-      send(sock, (char *)&wCmd, sizeof(WORD), 0); \
+      SendEx(sock, (char *)&wCmd, sizeof(WORD), 0); \
    }
 #define SEND_SUCCESS() \
    { \
       wCmd = LA_RESP_SUCCESS; \
-      send(sock, (char *)&wCmd, sizeof(WORD), 0); \
+      SendEx(sock, (char *)&wCmd, sizeof(WORD), 0); \
    }
 
 
@@ -74,10 +74,10 @@ static BOOL SendString(SOCKET sock, char *szString)
    WORD wLen;
 
    wLen = strlen(szString);
-   if (send(sock, (char *)&wLen, sizeof(WORD), 0) != 2)
+   if (SendEx(sock, (char *)&wLen, sizeof(WORD), 0) != 2)
       return FALSE;
 
-   return send(sock, szString, wLen, 0) == wLen;
+   return SendEx(sock, szString, wLen, 0) == wLen;
 }
 
 
@@ -150,7 +150,7 @@ static THREAD_RESULT THREAD_CALL ProcessingThread(void *pArg)
             break;
          case LA_CMD_GET_FLAGS:
             // Send value of application flags
-            send(sock, (char *)&g_dwFlags, sizeof(DWORD), 0);
+            SendEx(sock, (char *)&g_dwFlags, sizeof(DWORD), 0);
             break;
          case LA_CMD_SET_FLAGS:
             iError = recv(sock, (char *)&dwTemp, sizeof(DWORD), 0);
@@ -254,5 +254,8 @@ THREAD_RESULT THREAD_CALL LocalAdminListener(void *pArg)
 /*
 
 $Log: not supported by cvs2svn $
+Revision 1.6  2005/01/18 15:51:42  alk
++ sockets reuse (*nix only)
+
 
 */
index 9aafc27..7854d9d 100644 (file)
@@ -146,7 +146,7 @@ static DWORD SendMail(char *pszRcpt, char *pszSubject, char *pszText)
                   if (!memcmp(szBuffer,"220",3))
                   {
                      iState = STATE_HELLO;
-                     send(hSocket, "HELO netxms\r\n", 13, 0);
+                     SendEx(hSocket, "HELO netxms\r\n", 13, 0);
                   }
                   else
                   {
@@ -159,7 +159,7 @@ static DWORD SendMail(char *pszRcpt, char *pszSubject, char *pszText)
                   {
                      iState = STATE_FROM;
                      sprintf(szBuffer, "MAIL FROM: <%s>\r\n", m_szFromAddr);
-                     send(hSocket, szBuffer, strlen(szBuffer), 0);
+                     SendEx(hSocket, szBuffer, strlen(szBuffer), 0);
                   }
                   else
                   {
@@ -172,7 +172,7 @@ static DWORD SendMail(char *pszRcpt, char *pszSubject, char *pszText)
                   {
                      iState = STATE_RCPT;
                      sprintf(szBuffer, "RCPT TO: <%s>\r\n", pszRcpt);
-                     send(hSocket, szBuffer, strlen(szBuffer), 0);
+                     SendEx(hSocket, szBuffer, strlen(szBuffer), 0);
                   }
                   else
                   {
@@ -184,7 +184,7 @@ static DWORD SendMail(char *pszRcpt, char *pszSubject, char *pszText)
                   if (!memcmp(szBuffer,"250",3))
                   {
                      iState = STATE_DATA;
-                     send(hSocket, "DATA\r\n", 6, 0);
+                     SendEx(hSocket, "DATA\r\n", 6, 0);
                   }
                   else
                   {
@@ -199,15 +199,15 @@ static DWORD SendMail(char *pszRcpt, char *pszSubject, char *pszText)
 
                      // Mail header
                      sprintf(szBuffer, "From: NetXMS Server <%s>\r\n", m_szFromAddr);
-                     send(hSocket, szBuffer, strlen(szBuffer), 0);
+                     SendEx(hSocket, szBuffer, strlen(szBuffer), 0);
                      sprintf(szBuffer, "To: <%s>\r\n", pszRcpt);
-                     send(hSocket, szBuffer, strlen(szBuffer), 0);
+                     SendEx(hSocket, szBuffer, strlen(szBuffer), 0);
                      sprintf(szBuffer, "Subject: <%s>\r\n", pszSubject);
-                     send(hSocket, szBuffer, strlen(szBuffer), 0);
+                     SendEx(hSocket, szBuffer, strlen(szBuffer), 0);
 
                      // Mail body
-                     send(hSocket, pszText, strlen(pszText), 0);
-                     send(hSocket, "\r\n.\r\n", 5, 0);
+                     SendEx(hSocket, pszText, strlen(pszText), 0);
+                     SendEx(hSocket, "\r\n.\r\n", 5, 0);
                   }
                   else
                   {
@@ -219,7 +219,7 @@ static DWORD SendMail(char *pszRcpt, char *pszSubject, char *pszText)
                   if (!memcmp(szBuffer,"250",3))
                   {
                      iState = STATE_QUIT;
-                     send(hSocket, "QUIT\r\n", 6, 0);
+                     SendEx(hSocket, "QUIT\r\n", 6, 0);
                   }
                   else
                   {
index 2b01908..d11adca 100644 (file)
@@ -417,7 +417,7 @@ void ClientSession::WriteThread(void)
          break;
 
       DebugPrintf("Sending message %s\n", CSCPMessageCodeName(ntohs(pMsg->wCode), szBuffer));
-      if (send(m_hSocket, (const char *)pMsg, ntohl(pMsg->dwSize), 0) <= 0)
+      if (SendEx(m_hSocket, (const char *)pMsg, ntohl(pMsg->dwSize), 0) <= 0)
       {
          safe_free(pMsg);
          closesocket(m_hSocket);
index e26abf7..1f91db6 100644 (file)
@@ -555,7 +555,7 @@ BOOL AgentConnection::SendMessage(CSCPMessage *pMsg)
    BOOL bResult;
 
    pRawMsg = pMsg->CreateMessage();
-   bResult = (send(m_hSocket, (char *)pRawMsg, ntohl(pRawMsg->dwSize), 0) == (int)ntohl(pRawMsg->dwSize));
+   bResult = (SendEx(m_hSocket, (char *)pRawMsg, ntohl(pRawMsg->dwSize), 0) == (int)ntohl(pRawMsg->dwSize));
    free(pRawMsg);
    return bResult;
 }
index b225a28..bb9acf6 100644 (file)
@@ -87,7 +87,7 @@ void Disconnect(void)
 
 BOOL SendCommand(WORD wCmd)
 {
-   return send(g_hSocket, (char *)&wCmd, sizeof(WORD), 0) == sizeof(WORD);
+   return SendEx(g_hSocket, (char *)&wCmd, sizeof(WORD), 0) == sizeof(WORD);
 }
 
 
@@ -112,10 +112,10 @@ BOOL SendString(char *szString)
    WORD wLen;
 
    wLen = strlen(szString);
-   if (send(g_hSocket, (char *)&wLen, sizeof(WORD), 0) != 2)
+   if (SendEx(g_hSocket, (char *)&wLen, sizeof(WORD), 0) != 2)
       return FALSE;
 
-   return send(g_hSocket, szString, wLen, 0) == wLen;
+   return SendEx(g_hSocket, szString, wLen, 0) == wLen;
 }
 
 
@@ -161,5 +161,5 @@ BOOL RecvDWord(DWORD *pBuffer)
 
 BOOL SendDWord(DWORD dwValue)
 {
-   return send(g_hSocket, (char *)&dwValue, sizeof(DWORD), 0) == sizeof(DWORD);
+   return SendEx(g_hSocket, (char *)&dwValue, sizeof(DWORD), 0) == sizeof(DWORD);
 }
index 994169f..45d5aa5 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <stdio.h>
 #include <nms_common.h>
+#include <nms_util.h>
 #include <local_admin.h>
 
 
index 1c35a6b..690eb5a 100755 (executable)
@@ -29,7 +29,13 @@ if [ "X"`head -n$skip $0 | tail -n +5 | $md5 | cut -b1-32 | tr A-Z a-z` != "X"$h
        echo Script MD5 mismach
        exit
 fi
-let "skip=skip+1" >/dev/null
+
+let "skip=skip+1" 2>/dev/null
+if [ $? != 0 ]; then
+       # real sh?
+       skip=`let "$skip+1"`
+fi
+
 if [ "X"`tail -n +$skip $0 | $md5 | cut -b1-32 | tr A-Z a-z` != "X"$hash2 ]; then
        echo Payload MD5 mismach
        exit