- CFSocketInvalidate( socket->m_cfSocket ) ;
- CFRelease( socket->m_cfSocket ) ;
- socket->m_cfSocket = NULL ;
- socket->m_fd = INVALID_SOCKET ;
- }
+ if ( socket->m_writeStream )
+ {
+ CFWriteStreamClose(socket->m_writeStream);
+ CFRelease( socket->m_writeStream ) ;
+ socket->m_writeStream = NULL ;
+ }
+
+ CFSocketInvalidate( socket->m_cfSocket ) ;
+ CFRelease( socket->m_cfSocket ) ;
+ socket->m_cfSocket = NULL ;
+ socket->m_fd = INVALID_SOCKET ;
+ }