diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/server/sws.c | 32 | ||||
-rw-r--r-- | tests/server/tftpd.c | 35 |
2 files changed, 43 insertions, 24 deletions
diff --git a/tests/server/sws.c b/tests/server/sws.c index 87a697957..0e17d6ebd 100644 --- a/tests/server/sws.c +++ b/tests/server/sws.c @@ -676,7 +676,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req) case RCMD_STREAM: #define STREAMTHIS "a string to stream 01234567890\n" count = strlen(STREAMTHIS); - while(1) { + for (;;) { written = swrite(sock, STREAMTHIS, count); if(written != (ssize_t)count) { logmsg("Stopped streaming"); @@ -875,12 +875,14 @@ int main(int argc, char *argv[]) #ifdef ENABLE_IPV6 struct sockaddr_in6 me6; #endif /* ENABLE_IPV6 */ - curl_socket_t sock, msgsock; + curl_socket_t sock = CURL_SOCKET_BAD; + curl_socket_t msgsock = CURL_SOCKET_BAD; int flag; unsigned short port = DEFAULT_PORT; char *pidname= (char *)".http.pid"; struct httprequest req; int rc; + int error; int arg=1; #ifdef CURL_SWS_FORK_ENABLED bool use_fork = FALSE; @@ -954,15 +956,19 @@ int main(int argc, char *argv[]) sock = socket(AF_INET6, SOCK_STREAM, 0); #endif - if (CURL_SOCKET_BAD == sock) { - logmsg("Error opening socket: %d", SOCKERRNO); + if(CURL_SOCKET_BAD == sock) { + error = SOCKERRNO; + logmsg("Error creating socket: (%d) %s", + error, strerror(error)); return 1; } flag = 1; if (0 != setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, - (void *) &flag, sizeof(flag))) { - logmsg("setsockopt(SO_REUSEADDR) failed: %d", SOCKERRNO); + (void *)&flag, sizeof(flag))) { + error = SOCKERRNO; + logmsg("setsockopt(SO_REUSEADDR) failed with error: (%d) %s", + error, strerror(error)); sclose(sock); return 1; } @@ -986,7 +992,9 @@ int main(int argc, char *argv[]) } #endif /* ENABLE_IPV6 */ if(0 != rc) { - logmsg("Error binding socket: %d", SOCKERRNO); + error = SOCKERRNO; + logmsg("Error binding socket on port %hu: (%d) %s", + port, error, strerror(error)); sclose(sock); return 1; } @@ -1001,16 +1009,20 @@ int main(int argc, char *argv[]) /* start accepting connections */ rc = listen(sock, 5); if(0 != rc) { - logmsg("listen() failed with error: %d", SOCKERRNO); + error = SOCKERRNO; + logmsg("listen() failed with error: (%d) %s", + error, strerror(error)); sclose(sock); return 1; } - while (1) { + for (;;) { msgsock = accept(sock, NULL, NULL); if (CURL_SOCKET_BAD == msgsock) { - printf("MAJOR ERROR: accept() failed with error: %d\n", SOCKERRNO); + error = SOCKERRNO; + logmsg("MAJOR ERROR: accept() failed with error: (%d) %s", + error, strerror(error)); break; } diff --git a/tests/server/tftpd.c b/tests/server/tftpd.c index f3e521b75..e0c2d19e2 100644 --- a/tests/server/tftpd.c +++ b/tests/server/tftpd.c @@ -378,7 +378,7 @@ static int synchnet(curl_socket_t f /* socket to flush */) struct sockaddr_in fromaddr; curl_socklen_t fromaddrlen; - while (1) { + for (;;) { #if defined(HAVE_IOCTLSOCKET) (void) ioctlsocket(f, FIONREAD, &i); #else @@ -431,9 +431,10 @@ int main(int argc, char **argv) int arg = 1; char *pidname= (char *)".tftpd.pid"; unsigned short port = DEFAULT_PORT; - curl_socket_t sock; + curl_socket_t sock = CURL_SOCKET_BAD; int flag; int rc; + int error; struct testcase test; int result = 0; @@ -485,21 +486,26 @@ int main(int argc, char **argv) #endif if(CURL_SOCKET_BAD == sock) { - perror("opening stream socket"); - logmsg("Error opening socket"); + error = SOCKERRNO; + logmsg("Error creating socket: (%d) %s", + error, strerror(error)); return 1; } flag = 1; - if (setsockopt - (sock, SOL_SOCKET, SO_REUSEADDR, (const void *) &flag, - sizeof(int)) < 0) { - perror("setsockopt(SO_REUSEADDR)"); + if (0 != setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, + (void *)&flag, sizeof(flag))) { + error = SOCKERRNO; + logmsg("setsockopt(SO_REUSEADDR) failed with error: (%d) %s", + error, strerror(error)); + sclose(sock); + return 1; } #ifdef ENABLE_IPV6 if(!use_ipv6) { #endif + memset(&me, 0, sizeof(me)); me.sin_family = AF_INET; me.sin_addr.s_addr = INADDR_ANY; me.sin_port = htons(port); @@ -507,16 +513,17 @@ int main(int argc, char **argv) #ifdef ENABLE_IPV6 } else { - memset(&me6, 0, sizeof(struct sockaddr_in6)); + memset(&me6, 0, sizeof(me6)); me6.sin6_family = AF_INET6; me6.sin6_addr = in6addr_any; me6.sin6_port = htons(port); rc = bind(sock, (struct sockaddr *) &me6, sizeof(me6)); } #endif /* ENABLE_IPV6 */ - if(rc < 0) { - perror("binding stream socket"); - logmsg("Error binding socket"); + if(0 != rc) { + error = SOCKERRNO; + logmsg("Error binding socket on port %hu: (%d) %s", + port, error, strerror(error)); sclose(sock); return 1; } @@ -528,7 +535,7 @@ int main(int argc, char **argv) logmsg("Running %s version on port UDP/%d", ipv_inuse, (int)port); - do { + for (;;) { fromlen = sizeof(from); n = (ssize_t)recvfrom(sock, buf, sizeof(buf), 0, (struct sockaddr *)&from, &fromlen); @@ -571,7 +578,7 @@ int main(int argc, char **argv) logmsg("end of one transfer"); - } while(1); + } clear_advisor_read_lock(SERVERLOGS_LOCK); |