* Authors: Guilhem Lavaux,
* Guillermo Rodriguez Garcia <guille@iies.es> (maintainer)
* Purpose: GSocket main Unix and OS/2 file
- * Licence: The wxWindows licence
+ * Licence: The wxWidgets licence
* CVSID: $Id$
* -------------------------------------------------------------------------
*/
#endif
_GSocket_Enable_Events(sck);
- /* allow a socket to re-bind if the socket is in the TIME_WAIT
- state after being previously closed.
- */
- setsockopt(sck->m_fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&arg, sizeof(u_long));
-
/* Bind to the local address,
* retrieve the actual address bound,
* and listen up to 5 connections.
assert(socket != NULL);
- /* When using CFSocket we MUST NOT reenable events until we finish reading */
-#ifndef __DARWIN__
- /* Reenable INPUT events */
- _GSocket_Enable(socket, GSOCK_INPUT);
-#endif
-
if (socket->m_fd == INVALID_SOCKET || socket->m_server)
{
socket->m_error = GSOCK_INVSOCK;
return -1;
}
+ /* Disable events during query of socket status */
+ _GSocket_Disable(socket, GSOCK_INPUT);
+
/* If the socket is blocking, wait for data (with a timeout) */
if (_GSocket_Input_Timeout(socket) == GSOCK_TIMEDOUT)
- return -1;
-
- /* Read the data */
- if (socket->m_stream)
- ret = _GSocket_Recv_Stream(socket, buffer, size);
- else
- ret = _GSocket_Recv_Dgram(socket, buffer, size);
+ /* We no longer return here immediately, otherwise socket events would not be re-enabled! */
+ ret = -1;
+ else {
+ /* Read the data */
+ if (socket->m_stream)
+ ret = _GSocket_Recv_Stream(socket, buffer, size);
+ else
+ ret = _GSocket_Recv_Dgram(socket, buffer, size);
+ }
if (ret == -1)
{
socket->m_error = GSOCK_IOERR;
}
-#ifdef __DARWIN__
- /* Reenable INPUT events */
+ /* Enable events again now that we are done processing */
_GSocket_Enable(socket, GSOCK_INPUT);
-#endif
-
+
return ret;
}
fd_set exceptfds;
struct timeval tv;
+ assert(socket != NULL);
+
/* Do not use a static struct, Linux can garble it */
tv.tv_sec = socket->m_timeout / 1000;
tv.tv_usec = (socket->m_timeout % 1000) / 1000;
- assert(socket != NULL);
-
FD_ZERO(&readfds);
FD_ZERO(&writefds);
FD_ZERO(&exceptfds);
FD_SET(socket->m_fd, &readfds);
- if (flags & GSOCK_OUTPUT_FLAG)
+ if (flags & GSOCK_OUTPUT_FLAG || flags & GSOCK_CONNECTION_FLAG)
FD_SET(socket->m_fd, &writefds);
FD_SET(socket->m_fd, &exceptfds);
}
}
+GSocketError GSocket_GetSockOpt(GSocket *socket, int level, int optname,
+ void *optval, int *optlen)
+{
+ if (getsockopt(socket->m_fd, level, optname, optval, optlen) == 0)
+ {
+ return GSOCK_NOERROR;
+ }
+ return GSOCK_OPTERR;
+}
+
+GSocketError GSocket_SetSockOpt(GSocket *socket, int level, int optname,
+ const void *optval, int optlen)
+{
+ if (setsockopt(socket->m_fd, level, optname, optval, optlen) == 0)
+ {
+ return GSOCK_NOERROR;
+ }
+ return GSOCK_OPTERR;
+}
+
+GSocketError GSocket_SetReuseAddr(GSocket *socket)
+{
+ /* allow a socket to re-bind if the socket is in the TIME_WAIT
+ state after being previously closed.
+ */
+ u_long arg = 1;
+ setsockopt(socket->m_fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&arg, sizeof(u_long));
+}
+
+void GSocket_Streamed(GSocket *socket)
+{
+ socket->m_stream = TRUE;
+}
+
+void GSocket_Unstreamed(GSocket *socket)
+{
+ socket->m_stream = FALSE;
+}
#define CALL_CALLBACK(socket, event) { \
_GSocket_Disable(socket, event); \
{
#else
/* Use gethostbyname by default */
+#ifndef __WXMAC__
int val = 1; /* VA doesn't like constants in conditional expressions */
if (val)
+#endif
{
#endif
struct in_addr *array_addr;
CHECK_ADDRESS(address, INET);
addr = &(((struct sockaddr_in *)address->m_addr)->sin_addr);
- addr->s_addr = hostaddr;
+ addr->s_addr = htonl(hostaddr);
return GSOCK_NOERROR;
}
addr = (struct sockaddr_in *)address->m_addr;
- return addr->sin_addr.s_addr;
+ return ntohl(addr->sin_addr.s_addr);
}
unsigned short GAddress_INET_GetPort(GAddress *address)