#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
-------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
-
-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;
}
-
/* 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) {
}
/* 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;
}
-
void _socket_print_list(socket_manager* mgr) {
if(mgr == NULL) return;
socket_node* node = mgr->socket;
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 */
}
-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);
+//}
/*
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;
}
-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;
}
-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;
}
-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];
#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 {
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 );
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);
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