From 75e04cfc177c68e6e8374646ddaa3a0fc0e98352 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Fri, 20 Sep 2013 17:53:21 -0400 Subject: [PATCH] Quit handling useless network client structures It is useless to handle a client structure on recvfrom() or accept() when nothing is done with this information. Changed in Aggregator, Listener, Positioner and UDP-to-HTTP. --- owlps-aggregator/owlps-aggregatord.c | 6 +----- owlps-listener/owlps-listenerd.c | 4 +--- owlps-positioner/inputudpsocket.cc | 7 ++----- owlps-udp-to-http/owlps-udp-to-http.c | 8 ++------ 4 files changed, 6 insertions(+), 19 deletions(-) diff --git a/owlps-aggregator/owlps-aggregatord.c b/owlps-aggregator/owlps-aggregatord.c index ea94bde..f395e62 100644 --- a/owlps-aggregator/owlps-aggregatord.c +++ b/owlps-aggregator/owlps-aggregatord.c @@ -540,15 +540,11 @@ int read_loop(int sockfd) { int ret = 0 ; // Return value ssize_t nread ; // recvfrom return value - struct sockaddr_in client; // UDP client structure - socklen_t client_len = sizeof(client) ; // Size of clients owl_captured_request request ; // Message read on the socket while (owl_run) { - nread = recvfrom(sockfd, &request, sizeof(request), 0, - (struct sockaddr *) &client, &client_len) ; - + nread = recvfrom(sockfd, &request, sizeof(request), 0, NULL, NULL) ; if (nread <= 0) { if (owl_run) diff --git a/owlps-listener/owlps-listenerd.c b/owlps-listener/owlps-listenerd.c index d6b354e..a1ae1ba 100644 --- a/owlps-listener/owlps-listenerd.c +++ b/owlps-listener/owlps-listenerd.c @@ -1570,8 +1570,6 @@ void* autocalibrate_hello(void *NULL_value) void* autocalibrate(void *NULL_value) { int nread ; // recvfrom return value - struct sockaddr_in client; // UDP client structure - socklen_t client_len = sizeof(client) ; // Size of clients int listen_sockfd ; owl_autocalibration_order message ; @@ -1599,7 +1597,7 @@ void* autocalibrate(void *NULL_value) while (owl_run) { nread = recvfrom(listen_sockfd, &message, sizeof(message), 0, - (struct sockaddr *) &client, &client_len) ; + NULL, NULL) ; if (nread <= 0 && owl_run) { diff --git a/owlps-positioner/inputudpsocket.cc b/owlps-positioner/inputudpsocket.cc index ab5361a..2621122 100644 --- a/owlps-positioner/inputudpsocket.cc +++ b/owlps-positioner/inputudpsocket.cc @@ -98,13 +98,10 @@ bool InputUDPSocket::fill_current_request() if (eof()) return false ; - struct sockaddr_in client; // UDP client structure - socklen_t client_len = sizeof(client) ; // Size of clients - // Read the main request data owl_request request ; ssize_t nread = recvfrom(sockfd, &request, sizeof(request), 0, - (struct sockaddr *) &client, &client_len) ; + NULL, NULL) ; if (nread <= 0) { cerr << "InputUDPSocket: No request received!" << endl ; @@ -184,7 +181,7 @@ bool InputUDPSocket::fill_current_request() for (int i = 0 ; i < request.nb_info ; ++i) { nread = recvfrom(sockfd, &request_info, sizeof(request_info), 0, - (struct sockaddr *) &client, &client_len) ; + NULL, NULL) ; if (nread <= 0) { cerr << "No request info received!" << endl ; diff --git a/owlps-udp-to-http/owlps-udp-to-http.c b/owlps-udp-to-http/owlps-udp-to-http.c index b238e7b..974ceab 100644 --- a/owlps-udp-to-http/owlps-udp-to-http.c +++ b/owlps-udp-to-http/owlps-udp-to-http.c @@ -306,7 +306,7 @@ int init_tcp_socket() return OWL_ERR_SOCKET_CREATE ; } - bzero((char *) &server_addr, sizeof(server_addr)) ; + memset(&server_addr, 0, sizeof(server_addr)) ; server_addr.sin_family = AF_INET ; server_addr.sin_addr.s_addr = INADDR_ANY ; server_addr.sin_port = htons(options.http_port) ; @@ -329,15 +329,12 @@ int init_tcp_socket() void* tcp_server(void *NULL_value) { int newsockfd ; - socklen_t client_len ; - struct sockaddr_in client_addr ; ssize_t nbytes ; // recv/send return value char client_message[CLIENT_MESSAGE_STRLEN] ; char client_request[CLIENT_REQUEST_STRLEN] ; int request_id ; listen(tcp_sockfd, options.nb_connections) ; - client_len = sizeof(client_addr) ; // Prepare the answer, assuming there is only 1 full result (an error // message will also fit) @@ -353,8 +350,7 @@ void* tcp_server(void *NULL_value) while (owl_run) { - newsockfd = accept(tcp_sockfd, - (struct sockaddr*) &client_addr, &client_len) ; + newsockfd = accept(tcp_sockfd, NULL, NULL) ; if (newsockfd < 0) { perror("Error accepting a connection on the TCP socket") ;