From efb6c6a06277cfdde27b746d64fc06ea50535f3f Mon Sep 17 00:00:00 2001 From: miker Date: Tue, 12 Jun 2007 01:08:25 +0000 Subject: [PATCH] Patch from Scott McKellar: 1. I declared several functions as static, and moved their prototypes from the header file to the implementation file. In each case I verified that nothing else in the code base calls it. 2. I removed the socket_send_nowait prototype from the header, and commented it out in the implementation file. I was tempted to eliminate it entirely, but stayed my hand. It is a trivial wrapper for _socket_send(), and nothing calls it. 3. Nothing calls several other functions either. However unlike socket_send_nowait() they are non-trivial functions, and they appear to be intended for external linkage, so I left them alone for potential future use. 4. The identifier _socket_print_list is reserved for local scope, and should not have external linkage, because it starts with an underscore followed by a lower case letter. I may submit a patch to rename it some day if I ever get around to it, but that will require a change in socket_test.c, which calls it. 5. I moved the definition of the RBUFSIZE macro from the header file into the implmentation file. It is an internal detail that no other translation unit should know or care about. git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@937 9efc2488-bf62-4759-914b-345cdb29e865 --- src/utils/socket_bundle.c | 55 +++++++++++++++++++++++++++++++++-------------- src/utils/socket_bundle.h | 40 ---------------------------------- 2 files changed, 39 insertions(+), 56 deletions(-) diff --git a/src/utils/socket_bundle.c b/src/utils/socket_bundle.c index 5247328..4356ef6 100644 --- a/src/utils/socket_bundle.c +++ b/src/utils/socket_bundle.c @@ -1,5 +1,19 @@ #include "socket_bundle.h" +/* buffer used to read from the sockets */ +#define RBUFSIZE 1024 + +static socket_node* _socket_add_node(socket_manager* mgr, + int endpoint, int addr_type, int sock_fd, int parent_id ); +static socket_node* socket_find_node(socket_manager* mgr, int sock_fd); +static void socket_remove_node(socket_manager*, int sock_fd); +static int _socket_send(int sock_fd, const char* data, int flags); +static int _socket_route_data(socket_manager* mgr, int num_active, fd_set* read_set); +static int _socket_route_data_id( socket_manager* mgr, int sock_id); +static int _socket_handle_new_client(socket_manager* mgr, socket_node* node); +static int _socket_handle_client_data(socket_manager* mgr, socket_node* node); + + /* -------------------------------------------------------------------- Test Code -------------------------------------------------------------------- */ @@ -38,8 +52,9 @@ int main(int argc, char* argv[]) { /* -------------------------------------------------------------------- */ - -socket_node* _socket_add_node(socket_manager* mgr, +/* allocates and inserts a new socket node into the nodeset. + if parent_id is positive and non-zero, it will be set */ +static socket_node* _socket_add_node(socket_manager* mgr, int endpoint, int addr_type, int sock_fd, int parent_id ) { if(mgr == NULL) return NULL; @@ -332,9 +347,8 @@ int socket_open_unix_client(socket_manager* mgr, char* sock_path) { } - /* returns the socket_node with the given sock_fd */ -socket_node* socket_find_node(socket_manager* mgr, int sock_fd) { +static socket_node* socket_find_node(socket_manager* mgr, int sock_fd) { if(mgr == NULL) return NULL; socket_node* node = mgr->socket; while(node) { @@ -346,7 +360,7 @@ socket_node* socket_find_node(socket_manager* mgr, int sock_fd) { } /* removes the node with the given sock_fd from the list and frees it */ -void socket_remove_node(socket_manager* mgr, int sock_fd) { +static void socket_remove_node(socket_manager* mgr, int sock_fd) { if(mgr == NULL) return; @@ -378,7 +392,6 @@ void socket_remove_node(socket_manager* mgr, int sock_fd) { } - void _socket_print_list(socket_manager* mgr) { if(mgr == NULL) return; socket_node* node = mgr->socket; @@ -396,8 +409,8 @@ int socket_send(int sock_fd, const char* data) { return _socket_send( sock_fd, data, 0); } - -int _socket_send(int sock_fd, const char* data, int flags) { +/* utility method */ +static int _socket_send(int sock_fd, const char* data, int flags) { signal(SIGPIPE, SIG_IGN); /* in case a unix socket was closed */ @@ -415,9 +428,13 @@ int _socket_send(int sock_fd, const char* data, int flags) { } -int socket_send_nowait( int sock_fd, const char* data) { - return _socket_send( sock_fd, data, MSG_DONTWAIT); -} +/* sends the given data to the given socket. + * sets the send flag MSG_DONTWAIT which will allow the + * process to continue even if the socket buffer is full + * returns 0 on success, -1 otherwise */ +//int socket_send_nowait( int sock_fd, const char* data) { +// return _socket_send( sock_fd, data, MSG_DONTWAIT); +//} /* @@ -552,9 +569,14 @@ int socket_wait_all(socket_manager* mgr, int timeout) { return _socket_route_data(mgr, retval, &read_set); } -/* determines if we'er receiving a new client or data +/* iterates over the sockets in the set and handles active sockets. + new sockets connecting to server sockets cause the creation + of a new socket node. + Any new data read is is passed off to the data_received callback + as it arrives */ +/* determines if we're receiving a new client or data on an existing client */ -int _socket_route_data( +static int _socket_route_data( socket_manager* mgr, int num_active, fd_set* read_set) { if(!(mgr && read_set)) return -1; @@ -617,7 +639,8 @@ int _socket_route_data( } -int _socket_route_data_id( socket_manager* mgr, int sock_id) { +/* routes data from a single known socket */ +static int _socket_route_data_id( socket_manager* mgr, int sock_id) { socket_node* node = socket_find_node(mgr, sock_id); int status = 0; @@ -639,7 +662,7 @@ int _socket_route_data_id( socket_manager* mgr, int sock_id) { } -int _socket_handle_new_client(socket_manager* mgr, socket_node* node) { +static int _socket_handle_new_client(socket_manager* mgr, socket_node* node) { if(mgr == NULL || node == NULL) return -1; errno = 0; @@ -664,7 +687,7 @@ int _socket_handle_new_client(socket_manager* mgr, socket_node* node) { } -int _socket_handle_client_data(socket_manager* mgr, socket_node* node) { +static int _socket_handle_client_data(socket_manager* mgr, socket_node* node) { if(mgr == NULL || node == NULL) return -1; char buf[RBUFSIZE]; diff --git a/src/utils/socket_bundle.h b/src/utils/socket_bundle.h index d1f5fd7..28a5405 100644 --- a/src/utils/socket_bundle.h +++ b/src/utils/socket_bundle.h @@ -34,9 +34,6 @@ #define INET 10 #define UNIX 11 -/* buffer used to read from the sockets */ -#define RBUFSIZE 1024 - /* models a single socket connection */ struct socket_node_struct { @@ -87,26 +84,9 @@ int socket_open_unix_client(socket_manager*, char* sock_path); int socket_open_udp_client( socket_manager* mgr, int port, char* dest_addr); -/* returns the socket_node with the given sock_fd */ -socket_node* socket_find_node(socket_manager*, int sock_fd); - -/* removes the node with the given sock_fd from the list and frees it */ -void socket_remove_node(socket_manager*, int sock_fd); - - /* sends the given data to the given socket. returns 0 on success, -1 otherwise */ int socket_send(int sock_fd, const char* data); -/* utility method */ -int _socket_send(int sock_fd, const char* data, int flags); - - -/* sends the given data to the given socket. - * sets the send flag MSG_DONTWAIT which will allow the - * process to continue even if the socket buffer is full - * returns 0 on success, -1 otherwise */ -int socket_send_nowait( int sock_fd, const char* data); - /* waits at most usecs microseconds for the socket buffer to * be available */ int socket_send_timeout( int sock_fd, const char* data, int usecs ); @@ -115,11 +95,6 @@ int socket_send_timeout( int sock_fd, const char* data, int usecs ); it from the socket set */ void socket_disconnect(socket_manager*, int sock_fd); -/* allocates and inserts a new socket node into the nodeset. - if parent_id is positive and non-zero, it will be set */ -socket_node* _socket_add_node(socket_manager* mgr, - int endpoint, int addr_type, int sock_fd, int parent_id ); - /* XXX This only works if 'sock_fd' is a client socket... */ int socket_wait(socket_manager* mgr, int timeout, int sock_fd); @@ -129,24 +104,9 @@ int socket_wait(socket_manager* mgr, int timeout, int sock_fd); timeout == x | block for at most x seconds */ int socket_wait_all(socket_manager* mgr, int timeout); -/* iterates over the sockets in the set and handles active sockets. - new sockets connecting to server sockets cause the creation - of a new socket node. - Any new data read is is passed off to the data_received callback - as it arrives */ -int _socket_route_data(socket_manager* mgr, int num_active, fd_set* read_set); - -/* routes data from a single known socket */ -int _socket_route_data_id( socket_manager* mgr, int sock_id); - /* utility function for displaying the currently attached sockets */ void _socket_print_list(socket_manager* mgr); int socket_connected(int sock_fd); - -int _socket_handle_new_client(socket_manager* mgr, socket_node* node); -int _socket_handle_client_data(socket_manager* mgr, socket_node* node); - - #endif -- 2.11.0