]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/gsocket.cpp
rename g_openDialogs to wxOpenModalDialogsCount and define it in toplevel.cpp to...
[wxWidgets.git] / src / msw / gsocket.cpp
index c107146e2c615ede248523219ddb330278552e40..393d15c29c4dd579d03917dc96d75ce6afa48e63 100644 (file)
@@ -177,7 +177,11 @@ GSocket::GSocket()
   m_timeout.tv_usec = 0;
   m_establishing    = false;
   m_reusable        = false;
-
+  m_broadcast          = false;
+  m_dobind          = true;
+  m_initialRecvBufferSize = -1;
+  m_initialSendBufferSize = -1;
+   
   assert(gs_gui_functions);
   /* Per-socket GUI-specific initialization */
   m_ok = gs_gui_functions->Init_Socket(this);
@@ -222,7 +226,7 @@ void GSocket::Shutdown()
   /* If socket has been created, shutdown it */
   if (m_fd != INVALID_SOCKET)
   {
-    shutdown(m_fd, 2);
+    shutdown(m_fd, 1 /* SD_SEND */);
     Close();
   }
 
@@ -529,6 +533,34 @@ bool GSocket::SetReusable()
     return false;
 }
 
+/* GSocket_SetBroadcast:
+*  Simply sets the m_broadcast flag on the socket. GSocket_SetServer will
+*  make the appropriate setsockopt() call.
+*  Implemented as a GSocket function because clients (ie, wxSocketServer)
+*  don't have access to the GSocket struct information.
+*  Returns true if the flag was set correctly, false if an error occurred
+*  (ie, if the parameter was NULL)
+*/
+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:
@@ -600,6 +632,11 @@ GSocketError GSocket::Connect(GSocketStream stream)
      setsockopt(m_fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&arg, sizeof(arg));
   }
 
+  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)
   {
@@ -706,18 +743,24 @@ GSocketError GSocket::SetNonOriented()
   {
     setsockopt(m_fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&arg, sizeof(arg));
   }
-
-  /* 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;
@@ -1413,6 +1456,11 @@ GSocketError GAddress_INET_SetHostName(GAddress *address, const char *hostname)
   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);