The world should not end if a server has no peer. Let's return FALSE instead.

GAddress_copy should copy truthfully, not mangle the result if things are
going badly.  An earlier incarnation of the above.
Disable events before closing the socket, though just disabling them at all
will do.  This was the cause of the nasty 'crash on fail to bind' behaviour
that people have been seeing.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16309 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Ron Lee
2002-07-29 04:13:25 +00:00
parent 7af68c666b
commit 007c77ab4d
5 changed files with 66 additions and 39 deletions

View File

@@ -172,6 +172,13 @@ GSocket *GSocket_new(void)
return socket;
}
void GSocket_close(GSocket *socket)
{
_GSocket_Disable_Events(socket);
close(socket->m_fd);
socket->m_fd = INVALID_SOCKET;
}
void GSocket_destroy(GSocket *socket)
{
assert(socket != NULL);
@@ -208,8 +215,7 @@ void GSocket_Shutdown(GSocket *socket)
if (socket->m_fd != INVALID_SOCKET)
{
shutdown(socket->m_fd, 2);
close(socket->m_fd);
socket->m_fd = INVALID_SOCKET;
GSocket_close(socket);
}
/* Disable GUI callbacks */
@@ -217,7 +223,6 @@ void GSocket_Shutdown(GSocket *socket)
socket->m_cbacks[evt] = NULL;
socket->m_detected = GSOCK_LOST_FLAG;
_GSocket_Disable_Events(socket);
}
/* Address handling */
@@ -396,8 +401,7 @@ GSocketError GSocket_SetServer(GSocket *sck)
(SOCKLEN_T *) &sck->m_local->m_len) != 0) ||
(listen(sck->m_fd, 5) != 0))
{
close(sck->m_fd);
sck->m_fd = INVALID_SOCKET;
GSocket_close(sck);
sck->m_error = GSOCK_IOERR;
return GSOCK_IOERR;
}
@@ -577,8 +581,7 @@ GSocketError GSocket_Connect(GSocket *sck, GSocketStream stream)
{
if (_GSocket_Output_Timeout(sck) == GSOCK_TIMEDOUT)
{
close(sck->m_fd);
sck->m_fd = INVALID_SOCKET;
GSocket_close(sck);
/* sck->m_error is set in _GSocket_Output_Timeout */
return GSOCK_TIMEDOUT;
}
@@ -610,8 +613,7 @@ GSocketError GSocket_Connect(GSocket *sck, GSocketStream stream)
/* If connect failed with an error other than EINPROGRESS,
* then the call to GSocket_Connect has failed.
*/
close(sck->m_fd);
sck->m_fd = INVALID_SOCKET;
GSocket_close(sck);
sck->m_error = GSOCK_IOERR;
return GSOCK_IOERR;
}
@@ -675,8 +677,7 @@ GSocketError GSocket_SetNonOriented(GSocket *sck)
sck->m_local->m_addr,
(SOCKLEN_T *) &sck->m_local->m_len) != 0))
{
close(sck->m_fd);
sck->m_fd = INVALID_SOCKET;
GSocket_close(sck);
sck->m_error = GSOCK_IOERR;
return GSOCK_IOERR;
}
@@ -1301,7 +1302,7 @@ GAddress *GAddress_copy(GAddress *address)
memcpy(addr2, address, sizeof(GAddress));
if (address->m_addr)
if (address->m_addr && address->m_len > 0)
{
addr2->m_addr = (struct sockaddr *)malloc(addr2->m_len);
if (addr2->m_addr == NULL)
@@ -1640,3 +1641,4 @@ GSocketError GAddress_UNIX_GetPath(GAddress *address, char *path, size_t sbuf)
#endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */
// vi:sts=4:sw=4:et