]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/socket.cpp
Added wxVector::swap().
[wxWidgets.git] / src / common / socket.cpp
index c7af4a26000869f338a46ee28e610d126c6dc429..000d89b4648c4371bbacb81f1523136f917d2f3b 100644 (file)
@@ -213,7 +213,11 @@ public:
     {
         m_socket->m_reading = false;
 
-        m_socket->m_impl->ReenableEvents(wxSOCKET_INPUT_FLAG);
+        // connection could have been lost while reading, in this case calling
+        // ReenableEvents() would assert and is not necessary anyhow
+        wxSocketImpl * const impl = m_socket->m_impl;
+        if ( impl && impl->m_fd != INVALID_SOCKET )
+            impl->ReenableEvents(wxSOCKET_INPUT_FLAG);
     }
 
 private:
@@ -231,13 +235,15 @@ public:
         wxASSERT_MSG( !m_socket->m_writing, "write reentrancy?" );
 
         m_socket->m_writing = true;
-
-        m_socket->m_impl->ReenableEvents(wxSOCKET_OUTPUT_FLAG);
     }
 
     ~wxSocketWriteGuard()
     {
         m_socket->m_writing = false;
+
+        wxSocketImpl * const impl = m_socket->m_impl;
+        if ( impl && impl->m_fd != INVALID_SOCKET )
+            impl->ReenableEvents(wxSOCKET_OUTPUT_FLAG);
     }
 
 private:
@@ -813,7 +819,9 @@ void wxSocketBase::Init()
         // this Initialize() will be undone by wxSocketModule::OnExit(), all
         // the other calls to it should be matched by a call to Shutdown()
         if (!Initialize())
+        {
             wxLogError("Cannot initialize wxSocketBase");
+        }
     }
 }
 
@@ -950,7 +958,9 @@ wxUint32 wxSocketBase::DoRead(void* buffer_, wxUint32 nbytes)
         // events and, even more importantly, we must do this under Windows
         // where we're not going to get notifications about socket being ready
         // for reading before we read all the existing data from it
-        const int ret = m_connected ? m_impl->Read(buffer, nbytes) : 0;
+        const int ret = !m_impl->m_stream || m_connected
+                            ? m_impl->Read(buffer, nbytes)
+                            : 0;
         if ( ret == -1 )
         {
             if ( m_impl->GetLastError() == wxSOCKET_WOULDBLOCK )
@@ -1115,7 +1125,7 @@ wxUint32 wxSocketBase::DoWrite(const void *buffer_, wxUint32 nbytes)
     wxUint32 total = 0;
     while ( nbytes )
     {
-        if ( !m_connected )
+        if ( m_impl->m_stream && !m_connected )
         {
             if ( (m_flags & wxSOCKET_WAITALL) || !total )
                 SetError(wxSOCKET_IOERR);
@@ -1605,20 +1615,29 @@ void wxSocketBase::OnRequest(wxSocketNotify notification)
 
         case wxSOCKET_CONNECTION:
             flag = wxSOCKET_CONNECTION_FLAG;
+
+            // we're now successfully connected
+            m_connected = true;
+            m_establishing = false;
+
+            // error was previously set to wxSOCKET_WOULDBLOCK, but this is not
+            // the case any longer
+            SetError(wxSOCKET_NOERROR);
             break;
 
         case wxSOCKET_LOST:
             flag = wxSOCKET_LOST_FLAG;
+
+            // if we lost the connection the socket is now closed and not
+            // connected any more
+            m_connected = false;
+            m_closed = true;
             break;
 
         default:
             wxFAIL_MSG( "unknown wxSocket notification" );
     }
 
-    // if we lost the connection the socket is now closed
-    if ( notification == wxSOCKET_LOST )
-        m_closed = true;
-
     // remember the events which were generated for this socket, we're going to
     // use this in DoWait()
     m_eventsgot |= flag;