FS-10167: Fixed sockets in libks, testsock now runs correctly under windows

This commit is contained in:
Shane Bryldt 2017-03-24 00:34:14 -06:00
parent ad968eda6f
commit be451e4305
2 changed files with 24 additions and 7 deletions

View 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();

View 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: