#ifndef __GSOCKET_STANDALONE__
#include "wx/defs.h"
+#include "wx/private/gsocketiohandler.h"
#endif
#if defined(__VISAGECPP__)
int i;
m_fd = INVALID_SOCKET;
+ m_handler = NULL;
+
for (i=0;i<GSOCK_MAX_EVENT;i++)
{
m_cbacks[i] = NULL;
m_gui_dependent = NULL;
m_non_blocking = false;
m_reusable = false;
+ m_broadcast = false;
+ m_dobind = true;
m_timeout = 10*60*1000;
/* 10 minutes * 60 sec * 1000 millisec */
m_establishing = false;
+ m_initialRecvBufferSize = -1;
+ m_initialSendBufferSize = -1;
assert(gs_gui_functions);
/* Per-socket GUI-specific initialization */
void GSocket::Close()
{
gs_gui_functions->Disable_Events(this);
- /* gsockosx.c calls CFSocketInvalidate which closes the socket for us */
-#if !(defined(__DARWIN__) && (defined(__WXMAC__) || defined(__WXCOCOA__)))
- close(m_fd);
-#endif
+
+ /* When running on OS X, the gsockosx implementation of GSocketGUIFunctionsTable
+ will close the socket during Disable_Events. However, it will only do this
+ if it is being used. That is, it won't do it in a console program. To
+ ensure we get the right behavior, we have gsockosx set m_fd = INVALID_SOCKET
+ if it has closed the socket which indicates to us (at runtime, instead of
+ at compile time as this had been before) that the socket has already
+ been closed.
+ */
+ if(m_fd != INVALID_SOCKET)
+ close(m_fd);
m_fd = INVALID_SOCKET;
}
/* Per-socket GUI-specific cleanup */
gs_gui_functions->Destroy_Socket(this);
+ delete m_handler;
+
/* Destroy private addresses */
if (m_local)
GAddress_destroy(m_local);
return false;
}
+bool GSocket::SetBroadcast()
+{
+ /* socket must not be in use/already bound */
+ if (m_fd == INVALID_SOCKET) {
+ m_broadcast = true;
+ return true;
+ }
+ return false;
+}
+
+bool GSocket::DontDoBind()
+{
+ /* socket must not be in use/already bound */
+ if (m_fd == INVALID_SOCKET) {
+ m_dobind = false;
+ return true;
+ }
+ return false;
+}
+
/* Client specific parts */
/* GSocket_Connect:
#endif
}
+ if (m_initialRecvBufferSize >= 0)
+ setsockopt(m_fd, SOL_SOCKET, SO_RCVBUF, (const char*)&m_initialRecvBufferSize, sizeof(m_initialRecvBufferSize));
+ if (m_initialSendBufferSize >= 0)
+ setsockopt(m_fd, SOL_SOCKET, SO_SNDBUF, (const char*)&m_initialSendBufferSize, sizeof(m_initialSendBufferSize));
+
// If a local address has been set, then we need to bind to it before calling connect
if (m_local && m_local->m_addr)
{
#endif
}
- /* Bind to the local address,
- * and retrieve the actual address bound.
- */
- if ((bind(m_fd, m_local->m_addr, m_local->m_len) != 0) ||
- (getsockname(m_fd,
- m_local->m_addr,
- (WX_SOCKLEN_T *) &m_local->m_len) != 0))
+ if (m_broadcast)
{
- Close();
- m_error = GSOCK_IOERR;
- return GSOCK_IOERR;
+ setsockopt(m_fd, SOL_SOCKET, SO_BROADCAST, (const char*)&arg, sizeof(arg));
+ }
+ if (m_dobind)
+ {
+ /* Bind to the local address,
+ * and retrieve the actual address bound.
+ */
+ if ((bind(m_fd, m_local->m_addr, m_local->m_len) != 0) ||
+ (getsockname(m_fd,
+ m_local->m_addr,
+ (WX_SOCKLEN_T *) &m_local->m_len) != 0))
+ {
+ Close();
+ m_error = GSOCK_IOERR;
+ return GSOCK_IOERR;
+ }
}
-
return GSOCK_NOERROR;
}
return GSOCK_NOERROR;
}
+
+GSocketError GAddress_INET_SetBroadcastAddress(GAddress *address)
+{
+ return GAddress_INET_SetHostAddress(address, INADDR_BROADCAST);
+}
+
GSocketError GAddress_INET_SetAnyAddress(GAddress *address)
{
return GAddress_INET_SetHostAddress(address, INADDR_ANY);