void GSocket_close(GSocket *socket)
{
_GSocket_Disable_Events(socket);
+// gsockosx.c calls CFSocketInvalidate which closes the socket for us
+#if !(defined(__DARWIN__) && (defined(__WXMAC__) || defined(__WXCOCOA__)))
close(socket->m_fd);
+#endif
socket->m_fd = INVALID_SOCKET;
}
#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_IOERR;
}
+#ifdef __DARWIN__
+ /* Reenable INPUT events */
+ _GSocket_Enable(socket, GSOCK_INPUT);
+#endif
+
return ret;
}
struct timeval tv;
/* Do not use a static struct, Linux can garble it */
- tv.tv_sec = 0;
- tv.tv_usec = 0;
+ tv.tv_sec = socket->m_timeout / 1000;
+ tv.tv_usec = (socket->m_timeout % 1000) / 1000;
assert(socket != NULL);
FD_ZERO(&writefds);
FD_ZERO(&exceptfds);
FD_SET(socket->m_fd, &readfds);
- FD_SET(socket->m_fd, &writefds);
+ if (flags & GSOCK_OUTPUT_FLAG)
+ FD_SET(socket->m_fd, &writefds);
FD_SET(socket->m_fd, &exceptfds);
/* Check 'sticky' CONNECTION flag first */