]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-10167: Fixed sockets in libks, testsock now runs correctly under windows
authorShane Bryldt <astaelan@gmail.com>
Fri, 24 Mar 2017 06:34:14 +0000 (00:34 -0600)
committerShane Bryldt <astaelan@gmail.com>
Fri, 24 Mar 2017 06:34:14 +0000 (00:34 -0600)
libs/libks/src/ks.c
libs/libks/test/testsock.c

index ee9db3dfbe6051e45f06b8e75580140ce4031a1c..499e2ff11833f2086260139240e29ca2a97f3493 100644 (file)
@@ -73,7 +73,14 @@ KS_DECLARE(ks_status_t) ks_init(void)
        ks_ssl_init_ssl_locks();
        ks_global_pool();
        ks_rng_init();
-       
+
+#ifdef __WINDOWS__
+       WSADATA wsaData;
+       WORD wVersionRequested = MAKEWORD(2, 2);
+
+       WSAStartup(wVersionRequested, &wsaData);
+#endif
+
        return KS_STATUS_SUCCESS;
 }
 
@@ -81,6 +88,10 @@ KS_DECLARE(ks_status_t) ks_shutdown(void)
 {
        ks_status_t status = KS_STATUS_SUCCESS;
 
+#ifdef __WINDOWS__
+       WSACleanup();
+#endif
+
        ks_ssl_destroy_ssl_locks();
        //ks_rng_shutdown();
 
index f825768b709619966d7e58c3a011bb0ab375d37b..e17b9b6c5091f2907ec08100f7f6298e68462335 100644 (file)
@@ -180,15 +180,21 @@ static int test_tcp(char *ip)
        ks_addr_set(&addr, ip, tcp_port, family);
        cl_sock = ks_socket_connect(SOCK_STREAM, IPPROTO_TCP, &addr);
        
-       int x;
+       //int x;
 
        printf("TCP CLIENT SOCKET %d %s %d\n", (int)cl_sock, addr.host, addr.port);
 
-       x = write((int)cl_sock, __MSG, (unsigned)strlen(__MSG));
-       printf("TCP CLIENT WRITE %d bytes\n", x);
-       
-       x = read((int)cl_sock, buf, sizeof(buf));
-       printf("TCP CLIENT READ %d bytes [%s]\n", x, buf);
+       ks_size_t msglen = strlen(__MSG);
+       ks_socket_send(cl_sock, __MSG, &msglen);
+       printf("TCP CLIENT WRITE %d bytes\n", (int)msglen);
+       //x = write((int)cl_sock, __MSG, (unsigned)strlen(__MSG));
+       //printf("TCP CLIENT WRITE %d bytes\n", x);
+
+       msglen = sizeof(buf);
+       ks_socket_recv(cl_sock, buf, &msglen);
+       printf("TCP CLIENT READ %d bytes [%s]\n", (int)msglen, buf);
+       //x = read((int)cl_sock, buf, sizeof(buf));
+       //printf("TCP CLIENT READ %d bytes [%s]\n", x, buf);
        
  end: