tunnel socket set to non-blocking mode on server side; correct read or write select...
authorVictor Kirhenshtein <victor@netxms.org>
Tue, 21 Nov 2017 21:11:50 +0000 (23:11 +0200)
committerVictor Kirhenshtein <victor@netxms.org>
Tue, 21 Nov 2017 21:11:50 +0000 (23:11 +0200)
src/agent/core/tunnel.cpp
src/libnetxms/msgrecv.cpp
src/server/core/tunnel.cpp

index ce83419..96baf84 100644 (file)
@@ -308,7 +308,7 @@ int Tunnel::sslWrite(const void *data, size_t size)
          int err = SSL_get_error(m_ssl, bytes);
          if ((err == SSL_ERROR_WANT_READ) || (err == SSL_ERROR_WANT_WRITE))
          {
-            SocketPoller sp(true);
+            SocketPoller sp(err == SSL_ERROR_WANT_WRITE);
             sp.add(m_socket);
             if (sp.poll(5000) > 0)
                canRetry = true;
index 98f6d8e..22b7172 100644 (file)
@@ -251,6 +251,7 @@ TlsMessageReceiver::~TlsMessageReceiver()
 int TlsMessageReceiver::readBytes(BYTE *buffer, size_t size, UINT32 timeout)
 {
    bool doRead = true;
+   bool needWrite = false;
    int bytes = 0;
    MutexLock(m_mutex);
    while(doRead)
@@ -258,11 +259,12 @@ int TlsMessageReceiver::readBytes(BYTE *buffer, size_t size, UINT32 timeout)
       if (SSL_pending(m_ssl) == 0)
       {
          MutexUnlock(m_mutex);
-         SocketPoller sp;
+         SocketPoller sp(needWrite);
          sp.add(m_socket);
          int rc = sp.poll(timeout);
          if (rc <= 0)
             return (rc == 0) ? -2 : -1;   // -2 for timeout
+         needWrite = false;
          MutexLock(m_mutex);
       }
       doRead = false;
@@ -273,6 +275,7 @@ int TlsMessageReceiver::readBytes(BYTE *buffer, size_t size, UINT32 timeout)
          if ((err == SSL_ERROR_WANT_READ) || (err == SSL_ERROR_WANT_WRITE))
          {
             doRead = true;
+            needWrite = (err == SSL_ERROR_WANT_WRITE);
          }
          else
          {
index 094f5d1..208b67e 100644 (file)
@@ -369,7 +369,7 @@ int AgentTunnel::sslWrite(const void *data, size_t size)
          int err = SSL_get_error(m_ssl, bytes);
          if ((err == SSL_ERROR_WANT_READ) || (err == SSL_ERROR_WANT_WRITE))
          {
-            SocketPoller sp(true);
+            SocketPoller sp(err == SSL_ERROR_WANT_WRITE);
             sp.add(m_socket);
             if (sp.poll(5000) > 0)
                canRetry = true;
@@ -413,6 +413,7 @@ void AgentTunnel::start()
 {
    debugPrintf(4, _T("Tunnel started"));
    incRefCount();
+   SetSocketNonBlocking(m_socket);
    ThreadCreate(AgentTunnel::recvThreadStarter, 0, this);
 }