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;
}
{
assert(socket != NULL);
- /* When using CFSocket we MUST invalidate before closing the fd */
-#ifdef __DARWIN__
- /* Per-socket GUI-specific cleanup */
- _GSocket_GUI_Destroy_Socket(socket);
-#endif
-
/* Check that the socket is really shutdowned */
if (socket->m_fd != INVALID_SOCKET)
GSocket_Shutdown(socket);
-#ifndef __DARWIN__
/* Per-socket GUI-specific cleanup */
_GSocket_GUI_Destroy_Socket(socket);
-#endif
/* Destroy private addresses */
if (socket->m_local)
#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.
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 */
{
#else
/* Use gethostbyname by default */
- int val = 1; //VA doesn't like constants in conditional expressions at all
+#ifndef __WXMAC__
+ int val = 1; /* VA doesn't like constants in conditional expressions */
if (val)
+#endif
{
#endif
struct in_addr *array_addr;