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
#define PROCESS_EVENTS()
#endif // wxUSE_GUI/!wxUSE_GUI
#define PROCESS_EVENTS()
#endif // wxUSE_GUI/!wxUSE_GUI
+#define wxTRACE_Socket _T("wxSocket")
+
// --------------------------------------------------------------------------
// wxWin macros
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
// wxWin macros
// --------------------------------------------------------------------------
return FALSE;
peer = GSocket_GetPeer(m_socket);
return FALSE;
peer = GSocket_GetPeer(m_socket);
+
+ // copying a null address would just trigger an assert anyway
+
+ if (!peer)
+ return FALSE;
+
addr_man.SetAddress(peer);
GAddress_destroy(peer);
addr_man.SetAddress(peer);
GAddress_destroy(peer);
wxSocketFlags flags)
: wxSocketBase(flags, wxSOCKET_SERVER)
{
wxSocketFlags flags)
: wxSocketBase(flags, wxSOCKET_SERVER)
{
- // Create the socket
- m_socket = GSocket_new();
+ wxLogTrace( wxTRACE_Socket, _T("Opening wxSocketServer") );
- if (!m_socket)
- return;
+ m_socket = GSocket_new();
- // Setup the socket as server
- GSocket_SetLocal(m_socket, addr_man.GetAddress());
- if (GSocket_SetServer(m_socket) != GSOCK_NOERROR)
- {
- GSocket_destroy(m_socket);
- m_socket = NULL;
- return;
- }
+ if (!m_socket)
+ {
+ wxLogTrace( wxTRACE_Socket, _T("*** GSocket_new failed") );
+ return;
+ }
- GSocket_SetTimeout(m_socket, m_timeout * 1000);
- GSocket_SetCallback(m_socket, GSOCK_INPUT_FLAG | GSOCK_OUTPUT_FLAG |
- GSOCK_LOST_FLAG | GSOCK_CONNECTION_FLAG,
- wx_socket_callback, (char *)this);
+ // Setup the socket as server
+ GSocket_SetLocal(m_socket, addr_man.GetAddress());
+ if (GSocket_SetServer(m_socket) != GSOCK_NOERROR)
+ {
+ GSocket_destroy(m_socket);
+ m_socket = NULL;
+
+ wxLogTrace( wxTRACE_Socket, _T("*** GSocket_SetServer failed") );
+ return;
+ }
+
+ GSocket_SetTimeout(m_socket, m_timeout * 1000);
+ GSocket_SetCallback(m_socket, GSOCK_INPUT_FLAG | GSOCK_OUTPUT_FLAG |
+ GSOCK_LOST_FLAG | GSOCK_CONNECTION_FLAG,
+ wx_socket_callback, (char *)this);
}
// --------------------------------------------------------------------------
}
// --------------------------------------------------------------------------
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
gint *m_id = (gint *)(socket->m_gui_dependent);
int c;
gint *m_id = (gint *)(socket->m_gui_dependent);
int c;
+ assert( m_id != NULL );
+
switch (event)
{
case GSOCK_LOST: /* fall-through */
switch (event)
{
case GSOCK_LOST: /* fall-through */
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
gint *m_id = (gint *)(socket->m_gui_dependent);
int c;
gint *m_id = (gint *)(socket->m_gui_dependent);
int c;
+ assert( m_id != NULL );
+
switch (event)
{
case GSOCK_LOST: /* fall-through */
switch (event)
{
case GSOCK_LOST: /* fall-through */
+void GSocket_close(GSocket *socket)
+{
+ _GSocket_Disable_Events(socket);
+ closesocket(socket->m_fd);
+ socket->m_fd = INVALID_SOCKET;
+}
+
void GSocket_destroy(GSocket *socket)
{
assert(socket != NULL);
void GSocket_destroy(GSocket *socket)
{
assert(socket != NULL);
if (socket->m_fd != INVALID_SOCKET)
{
shutdown(socket->m_fd, 2);
if (socket->m_fd != INVALID_SOCKET)
{
shutdown(socket->m_fd, 2);
- closesocket(socket->m_fd);
- socket->m_fd = INVALID_SOCKET;
}
/* Disable GUI callbacks */
}
/* Disable GUI callbacks */
socket->m_cbacks[evt] = NULL;
socket->m_detected = GSOCK_LOST_FLAG;
socket->m_cbacks[evt] = NULL;
socket->m_detected = GSOCK_LOST_FLAG;
- _GSocket_Disable_Events(socket);
(SOCKLEN_T *)&sck->m_local->m_len) != 0) ||
(listen(sck->m_fd, 5) != 0))
{
(SOCKLEN_T *)&sck->m_local->m_len) != 0) ||
(listen(sck->m_fd, 5) != 0))
{
- closesocket(sck->m_fd);
- sck->m_fd = INVALID_SOCKET;
sck->m_error = GSOCK_IOERR;
return GSOCK_IOERR;
}
sck->m_error = GSOCK_IOERR;
return GSOCK_IOERR;
}
if (err != GSOCK_NOERROR)
{
if (err != GSOCK_NOERROR)
{
- closesocket(sck->m_fd);
- sck->m_fd = INVALID_SOCKET;
/* sck->m_error is set in _GSocket_Connect_Timeout */
}
/* sck->m_error is set in _GSocket_Connect_Timeout */
}
/* If connect failed with an error other than EWOULDBLOCK,
* then the call to GSocket_Connect() has failed.
*/
/* If connect failed with an error other than EWOULDBLOCK,
* then the call to GSocket_Connect() has failed.
*/
- closesocket(sck->m_fd);
- sck->m_fd = INVALID_SOCKET;
sck->m_error = GSOCK_IOERR;
return GSOCK_IOERR;
}
sck->m_error = GSOCK_IOERR;
return GSOCK_IOERR;
}
sck->m_local->m_addr,
(SOCKLEN_T *)&sck->m_local->m_len) != 0))
{
sck->m_local->m_addr,
(SOCKLEN_T *)&sck->m_local->m_len) != 0))
{
- closesocket(sck->m_fd);
- sck->m_fd = INVALID_SOCKET;
sck->m_error = GSOCK_IOERR;
return GSOCK_IOERR;
}
sck->m_error = GSOCK_IOERR;
return GSOCK_IOERR;
}
typedef void (*wxDummy)();
#endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */
typedef void (*wxDummy)();
#endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */
+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);
void GSocket_destroy(GSocket *socket)
{
assert(socket != NULL);
if (socket->m_fd != INVALID_SOCKET)
{
shutdown(socket->m_fd, 2);
if (socket->m_fd != INVALID_SOCKET)
{
shutdown(socket->m_fd, 2);
- close(socket->m_fd);
- socket->m_fd = INVALID_SOCKET;
}
/* Disable GUI callbacks */
}
/* Disable GUI callbacks */
socket->m_cbacks[evt] = NULL;
socket->m_detected = GSOCK_LOST_FLAG;
socket->m_cbacks[evt] = NULL;
socket->m_detected = GSOCK_LOST_FLAG;
- _GSocket_Disable_Events(socket);
(SOCKLEN_T *) &sck->m_local->m_len) != 0) ||
(listen(sck->m_fd, 5) != 0))
{
(SOCKLEN_T *) &sck->m_local->m_len) != 0) ||
(listen(sck->m_fd, 5) != 0))
{
- close(sck->m_fd);
- sck->m_fd = INVALID_SOCKET;
sck->m_error = GSOCK_IOERR;
return GSOCK_IOERR;
}
sck->m_error = GSOCK_IOERR;
return GSOCK_IOERR;
}
{
if (_GSocket_Output_Timeout(sck) == GSOCK_TIMEDOUT)
{
{
if (_GSocket_Output_Timeout(sck) == GSOCK_TIMEDOUT)
{
- close(sck->m_fd);
- sck->m_fd = INVALID_SOCKET;
/* sck->m_error is set in _GSocket_Output_Timeout */
return GSOCK_TIMEDOUT;
}
/* sck->m_error is set in _GSocket_Output_Timeout */
return GSOCK_TIMEDOUT;
}
/* If connect failed with an error other than EINPROGRESS,
* then the call to GSocket_Connect has failed.
*/
/* 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;
sck->m_error = GSOCK_IOERR;
return GSOCK_IOERR;
}
sck->m_error = GSOCK_IOERR;
return GSOCK_IOERR;
}
sck->m_local->m_addr,
(SOCKLEN_T *) &sck->m_local->m_len) != 0))
{
sck->m_local->m_addr,
(SOCKLEN_T *) &sck->m_local->m_len) != 0))
{
- close(sck->m_fd);
- sck->m_fd = INVALID_SOCKET;
sck->m_error = GSOCK_IOERR;
return GSOCK_IOERR;
}
sck->m_error = GSOCK_IOERR;
return GSOCK_IOERR;
}
memcpy(addr2, address, sizeof(GAddress));
memcpy(addr2, address, sizeof(GAddress));
+ if (address->m_addr && address->m_len > 0)
{
addr2->m_addr = (struct sockaddr *)malloc(addr2->m_len);
if (addr2->m_addr == NULL)
{
addr2->m_addr = (struct sockaddr *)malloc(addr2->m_len);
if (addr2->m_addr == NULL)
#endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */
#endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */