diff --git a/src/axl_socket.c b/src/axl_socket.c index e39a25e..c5d3035 100644 --- a/src/axl_socket.c +++ b/src/axl_socket.c @@ -127,7 +127,7 @@ static kvtree* service_request_AXL_Config_Set(int sd) } #endif -static ssize_t service_request_from_client(int sd) +static ssize_t axl_socket_request_from_client(int sd) { ssize_t bytecount; axl_socket_Request req; @@ -171,6 +171,7 @@ static ssize_t service_request_from_client(int sd) static void sigterm_handler(int sig, siginfo_t* info, void* ucontext) { + AXL_DBG(2, "SIGTERM Received"); time_to_leave++; } @@ -250,12 +251,15 @@ int axl_socket_server_run(int port) activity = select(max_sd + 1 , &readfds , NULL , NULL , NULL); + if (time_to_leave) + break; + if (activity < 0 && errno != EINTR) { AXL_ABORT(-1, "select() error: (%s)", strerror(errno)); } if (FD_ISSET(server_socket, &readfds)) { - AXL_DBG(0, "Accepting new incomming connection"); + AXL_DBG(1, "Accepting new incomming connection"); if ((new_socket = accept(server_socket, (struct sockaddr *)&address, (socklen_t*)&addrlen)) < 0) { AXL_ABORT(-1, "accept() error: (%s)", strerror(errno)); @@ -267,15 +271,15 @@ int axl_socket_server_run(int port) break; } } - AXL_DBG(0, "Connection established"); + AXL_DBG(1, "Connection established"); } for ( int i = 0; i < AXL_SOCKET_MAX_CLIENTS; i++) { if (FD_ISSET(axl_socket_conn_ctx_array[i].sd , &readfds)) { axl_xfer_list = &axl_socket_conn_ctx_array[i].xfr; - if (service_request_from_client(axl_socket_conn_ctx_array[i].sd) == 0) { - AXL_DBG(0, "Closing server side socket(%d) to client", axl_socket_conn_ctx_array[i].sd); + if (axl_socket_request_from_client(axl_socket_conn_ctx_array[i].sd) == 0) { + AXL_DBG(1, "Closing server side socket(%d) to client", axl_socket_conn_ctx_array[i].sd); close(axl_socket_conn_ctx_array[i].sd); axl_socket_conn_ctx_array[i].sd = 0; axl_free(&axl_xfer_list->axl_kvtrees); diff --git a/test/test_client_server.c b/test/test_client_server.c index 9df4b02..30eb498 100644 --- a/test/test_client_server.c +++ b/test/test_client_server.c @@ -25,10 +25,17 @@ int run_service() int run_client() { - fprintf(stdout, "Client Started!\n"); - sleep(2); - fprintf(stdout, "Client Ending!\n"); - return AXLCS_SUCCESS; + int rval; + + if ((rval = AXL_Init()) != AXL_SUCCESS) { + fprintf(stderr, "Call to AXL_Init failed with code: %d\n", rval); + } else { + if ((rval = AXL_Finalize()) != AXL_SUCCESS) { + fprintf(stderr, "Call to AXL_Init failed with code: %d\n", rval); + } + } + + return rval; } int main(int ac, char **av) diff --git a/test/test_driver_client_server.py b/test/test_driver_client_server.py index e5c9876..36f43db 100755 --- a/test/test_driver_client_server.py +++ b/test/test_driver_client_server.py @@ -3,6 +3,7 @@ import sys import subprocess import os +import time def wait_for_completion(procname, proc, wait_time): try: @@ -20,8 +21,11 @@ def wait_for_completion(procname, proc, wait_time): if __name__ == '__main__': errors = 0 # Launch the server then the client - server = subprocess.Popen(['./test_client_server', '--server'], env=dict(os.environ), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False) - client = subprocess.Popen(['./test_client_server', '--client'], env=dict(os.environ), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False) + test_env = {'AXL_DEBUG': '44', 'AXL_SERVICE_HOST': 'localhost', 'AXL_SERVICE_PORT': '2000'} + server = subprocess.Popen(['./test_client_server', '--server'], env=dict(os.environ, **test_env), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False) + time.sleep(2) # Give server a chance to start + + client = subprocess.Popen(['./test_client_server', '--client'], env=dict(os.environ, **test_env), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False) # Wait for the client then the server to finish client_ecode, client_out, client_err = wait_for_completion("axl_client", client, 30)