diff options
Diffstat (limited to 'programs/ekr_loop.c')
-rw-r--r-- | programs/ekr_loop.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/programs/ekr_loop.c b/programs/ekr_loop.c index 35154f67..3a9920db 100644 --- a/programs/ekr_loop.c +++ b/programs/ekr_loop.c @@ -267,7 +267,7 @@ main(int argc, char *argv[]) #ifdef _WIN32 SOCKET fd_c, fd_s; #else - int fd_c, fd_s; + int fd_c, fd_s, rc; #endif struct socket *s_c, *s_s, *s_l; #ifdef _WIN32 @@ -294,7 +294,7 @@ main(int argc, char *argv[]) #ifdef _WIN32 if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) { - printf("WSAStartup failed\n"); + debug_printf("WSAStartup failed\n"); exit (EXIT_FAILURE); } #endif @@ -302,11 +302,11 @@ main(int argc, char *argv[]) /* set up a connected UDP socket */ #ifdef _WIN32 if ((fd_c = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == INVALID_SOCKET) { - printf("socket() failed with error: %d\n", WSAGetLastError()); + debug_printf("socket() failed with error: %d\n", WSAGetLastError()); exit(EXIT_FAILURE); } if ((fd_s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == INVALID_SOCKET) { - printf("socket() failed with error: %d\n", WSAGetLastError()); + debug_printf("socket() failed with error: %d\n", WSAGetLastError()); exit(EXIT_FAILURE); } #else @@ -335,11 +335,11 @@ main(int argc, char *argv[]) sin_s.sin_addr.s_addr = htonl(INADDR_LOOPBACK); #ifdef _WIN32 if (bind(fd_c, (struct sockaddr *)&sin_c, sizeof(struct sockaddr_in)) == SOCKET_ERROR) { - printf("bind() failed with error: %d\n", WSAGetLastError()); + debug_printf("bind() failed with error: %d\n", WSAGetLastError()); exit(EXIT_FAILURE); } if (bind(fd_s, (struct sockaddr *)&sin_s, sizeof(struct sockaddr_in)) == SOCKET_ERROR) { - printf("bind() failed with error: %d\n", WSAGetLastError()); + debug_printf("bind() failed with error: %d\n", WSAGetLastError()); exit(EXIT_FAILURE); } #else @@ -372,16 +372,22 @@ main(int argc, char *argv[]) } #endif #ifdef _WIN32 - tid_c = CreateThread(NULL, 0, &handle_packets, (void *)&fd_c, 0, NULL); - tid_s = CreateThread(NULL, 0, &handle_packets, (void *)&fd_s, 0, NULL); + if ((tid_c = CreateThread(NULL, 0, &handle_packets, (void *)&fd_c, 0, NULL)) == NULL) { + debug_printf("CreateThread() failed with error: %d\n", GetLastError()); + exit(EXIT_FAILURE); + } + if ((tid_s = CreateThread(NULL, 0, &handle_packets, (void *)&fd_s, 0, NULL)) == NULL) { + debug_printf("CreateThread() failed with error: %d\n", GetLastError()); + exit(EXIT_FAILURE); + } #else - if (pthread_create(&tid_c, NULL, &handle_packets, (void *)&fd_c)) { - perror("pthread_create tid_c"); + if ((rc = pthread_create(&tid_c, NULL, &handle_packets, (void *)&fd_c)) != 0) { + fprintf(stderr, "pthread_create tid_c: %s\n", strerror(rc)); exit(EXIT_FAILURE); } - if (pthread_create(&tid_s, NULL, &handle_packets, (void *)&fd_s)) { - perror("pthread_create tid_s"); + if ((rc = pthread_create(&tid_s, NULL, &handle_packets, (void *)&fd_s)) != 0) { + fprintf(stderr, "pthread_create tid_s: %s\n", strerror(rc)); exit(EXIT_FAILURE); }; #endif |