diff libnnchat.c @ 91:acfc4b4bc180

Create network initialization functions in libnnchat and move Win32/WinSock code there.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 07 May 2009 00:04:37 +0300
parents 1e0bf7b4fd41
children 6e47426efb6a
line wrap: on
line diff
--- a/libnnchat.c	Wed May 06 23:55:21 2009 +0300
+++ b/libnnchat.c	Thu May 07 00:04:37 2009 +0300
@@ -92,6 +92,29 @@
 }
 
 
+BOOL initNetwork(void)
+{
+#ifdef __WIN32
+    /* Initialize WinSock, if needed */
+    WSADATA wsaData;
+    int err = WSAStartup(0x0101, &wsaData);
+    if (err != 0) {
+        THERR("Could not initialize WinSock library (err=%d).\n", err);
+        return FALSE;
+    }
+#endif
+    return TRUE;
+}
+
+
+void closeNetwork(void)
+{
+#ifdef __WIN32
+    WSACleanup();
+#endif
+}
+
+
 BOOL sendToSocket(const int sock, char *buf, const size_t bufLen)
 {
     size_t bufLeft = bufLen;