X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/75d684d9f772126b02aaea7eedadc79cd24aaf32..37b8e6798782278fdfe4f3c1291aaff55cdbb8c9:/src/msw/gsocket.c diff --git a/src/msw/gsocket.c b/src/msw/gsocket.c index 11f17d00a9..10c1b2ab4f 100644 --- a/src/msw/gsocket.c +++ b/src/msw/gsocket.c @@ -262,7 +262,8 @@ GAddress *GSocket_GetLocal(GSocket *socket) { GAddress *address; struct sockaddr addr; - SOCKLEN_T size; + SOCKLEN_T size = sizeof(addr); + GSocketError err; assert(socket != NULL); @@ -289,10 +290,11 @@ GAddress *GSocket_GetLocal(GSocket *socket) socket->m_error = GSOCK_MEMERR; return NULL; } - if (_GAddress_translate_from(address, &addr, size) != GSOCK_NOERROR) + err = _GAddress_translate_from(address, &addr, size); + if (err != GSOCK_NOERROR) { - socket->m_error = GSOCK_MEMERR; GAddress_destroy(address); + socket->m_error = err; return NULL; } @@ -380,6 +382,9 @@ GSocketError GSocket_SetServer(GSocket *sck) GSocket *GSocket_WaitConnection(GSocket *sck) { GSocket *connection; + struct sockaddr from; + SOCKLEN_T fromlen = sizeof(from); + GSocketError err; u_long arg = 1; assert(sck != NULL); @@ -409,7 +414,7 @@ GSocket *GSocket_WaitConnection(GSocket *sck) return NULL; } - connection->m_fd = accept(sck->m_fd, NULL, NULL); + connection->m_fd = accept(sck->m_fd, &from, &fromlen); if (connection->m_fd == INVALID_SOCKET) { @@ -427,6 +432,23 @@ GSocket *GSocket_WaitConnection(GSocket *sck) connection->m_stream = TRUE; connection->m_oriented = TRUE; + /* Setup the peer address field */ + connection->m_peer = GAddress_new(); + if (!connection->m_peer) + { + GSocket_destroy(connection); + sck->m_error = GSOCK_MEMERR; + return NULL; + } + err = _GAddress_translate_from(connection->m_peer, &from, fromlen); + if (err != GSOCK_NOERROR) + { + GAddress_destroy(connection->m_peer); + GSocket_destroy(connection); + sck->m_error = err; + return NULL; + } + ioctlsocket(connection->m_fd, FIONBIO, (u_long FAR *) &arg); _GSocket_Enable_Events(connection); @@ -633,12 +655,16 @@ int GSocket_Read(GSocket *socket, char *buffer, int size) * if the socket is in non-blocking mode (which is always * the case here, no matter the setting of GSocket itself) * a call to send() can fail with EWOULDBLOCK even when - * select() says that the socket is readable. + * select() says that the socket is writable. * * This can break several things because, usually, if * select() says that the socket is writable, it is * assumed that send() won't fail. To avoid this, we * return 0 instead of -1 for this special case. + * + * XXX - this comment seems not to belong here, and also + * the code is not consistent with the unix version of + * gsocket... what to do? (GRG) */ if (WSAGetLastError() != WSAEWOULDBLOCK) { @@ -956,6 +982,7 @@ int _GSocket_Recv_Dgram(GSocket *socket, char *buffer, int size) struct sockaddr from; SOCKLEN_T fromlen = sizeof(from); int ret; + GSocketError err; ret = recvfrom(socket->m_fd, buffer, size, 0, &from, &fromlen); @@ -972,10 +999,12 @@ int _GSocket_Recv_Dgram(GSocket *socket, char *buffer, int size) return -1; } } - if (_GAddress_translate_from(socket->m_peer, &from, fromlen) != GSOCK_NOERROR) + err = _GAddress_translate_from(socket->m_peer, &from, fromlen); + if (err != GSOCK_NOERROR) { - socket->m_error = GSOCK_MEMERR; GAddress_destroy(socket->m_peer); + socket->m_peer = NULL; + socket->m_error = err; return -1; } @@ -991,6 +1020,7 @@ int _GSocket_Send_Dgram(GSocket *socket, const char *buffer, int size) { struct sockaddr *addr; int len, ret; + GSocketError err; if (!socket->m_peer) { @@ -998,9 +1028,10 @@ int _GSocket_Send_Dgram(GSocket *socket, const char *buffer, int size) return -1; } - if (!_GAddress_translate_to(socket->m_peer, &addr, &len)) + err = _GAddress_translate_to(socket->m_peer, &addr, &len); + if (err != GSOCK_NOERROR) { - socket->m_error = GSOCK_MEMERR; + socket->m_error = err; return -1; } @@ -1164,6 +1195,7 @@ GSocketError _GAddress_translate_to(GAddress *address, GSocketError _GAddress_Init_INET(GAddress *address) { + address->m_len = sizeof(struct sockaddr_in); address->m_addr = (struct sockaddr *) malloc(address->m_len); if (address->m_addr == NULL) { @@ -1171,11 +1203,10 @@ GSocketError _GAddress_Init_INET(GAddress *address) return GSOCK_MEMERR; } - address->m_len = sizeof(struct sockaddr_in); address->m_family = GSOCK_INET; address->m_realfamily = PF_INET; ((struct sockaddr_in *)address->m_addr)->sin_family = AF_INET; - ((struct sockaddr_in *)address->m_addr)->sin_addr.s_addr = INADDR_ANY; + ((struct sockaddr_in *)address->m_addr)->sin_addr.s_addr = INADDR_NONE; return GSOCK_NOERROR; } @@ -1350,11 +1381,15 @@ GSocketError GAddress_UNIX_GetPath(GAddress *address, char *path, size_t sbuf) return GSOCK_INVADDR; } +#else /* !wxUSE_SOCKETS */ -#endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */ - - +/* + * translation unit shouldn't be empty, so include this typedef to make the + * compiler (VC++ 6.0, for example) happy + */ +typedef (*wxDummy)(); +#endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */ /* Diferencias con la version Unix: * - El descriptor es SOCKET y no int