From: Jack Lange Date: Tue, 25 Nov 2008 00:36:15 +0000 (-0600) Subject: added sock_set functions for select() support X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=commitdiff_plain;h=36fb65749158643467beb8ebc82276b2b29412d1 added sock_set functions for select() support --- diff --git a/palacios/include/palacios/vmm_socket.h b/palacios/include/palacios/vmm_socket.h index df3bece..bfc7123 100644 --- a/palacios/include/palacios/vmm_socket.h +++ b/palacios/include/palacios/vmm_socket.h @@ -134,7 +134,7 @@ #define V3_RecvFrom_Host(sock, hostname, port, buf, len) ({ \ extern struct v3_socket_hooks * sock_hooks; \ int ret = -1; \ - if ((sock_hooks) && (sock_hooks)->recvfrom_host) { \ + if ((sock_hooks) && (sock_hooks)->recvfrom_host) { \ ret = (sock_hooks)->recvfrom_host(sock, hostname, port, buf, len); \ } \ ret; \ @@ -159,17 +159,30 @@ struct v3_timeval { long tv_usec; /* and microseconds */ }; -struct v3_sock_set { +struct v3_sock_entry { V3_SOCK sock; unsigned int is_set; struct v3_sock_set * next; }; +struct v3_sock_set { + unsigned int num_socks; + struct v3_sock_entry * socks; +}; + + +void v3_init_sock_set(struct v3_sock_set * sock_set); + +void v3_set_sock(struct v3_sock_set * sock_set, V3_SOCK sock); // adds socket to the sockset +void v3_clr_sock(struct v3_sock_set * sock_set, V3_SOCK sock); // deletes socket from sockset +int v3_isset_sock(struct v3_sock_set * sock_set, V3_SOCK sock); // checks is_set vairable +void v3_zero_sockset(struct v3_sock_set * sock_set); // clears all is_set variables. + + + +#define v3_foreach_sock(/* (struct v3_sock_set *) */ sock_set, /* (struct v3_sock_entry *) */ iter) \ + for (iter = sock_set->socks; iter != NULL; iter = iter->next) -#define v3_set_sock(n, p) ((p)->fd_bits[(n)/8] |= (1 << ((n) & 7))) -#define v3_clr_sock(n, p) ((p)->fd_bits[(n)/8] &= ~(1 << ((n) & 7))) -#define v3_isset_sock(n,p) ((p)->fd_bits[(n)/8] & (1 << ((n) & 7))) -#define v3_zero_sockset(p) struct v3_socket_hooks { @@ -183,7 +196,7 @@ struct v3_socket_hooks { // Network Server Calls int (*bind_socket)(const V3_SOCK sock, const int port); - int (*accept)(const V3_SOCK const sock); + int (*accept)(const V3_SOCK const sock, unsigned int * remote_ip); // This going to suck int (*select)(struct v3_sock_set * rset, \ struct v3_sock_set * wset, \ diff --git a/palacios/src/palacios/vmm_socket.c b/palacios/src/palacios/vmm_socket.c index 8546688..dbc19c0 100644 --- a/palacios/src/palacios/vmm_socket.c +++ b/palacios/src/palacios/vmm_socket.c @@ -19,6 +19,8 @@ #include +#include + struct v3_socket_hooks * sock_hooks = 0; @@ -29,3 +31,79 @@ void V3_Init_Sockets(struct v3_socket_hooks * hooks) { PrintInfo("Initializing Socket Interface\n"); sock_hooks = hooks; } + + + +void v3_init_sock_set(struct v3_sock_set * sock_set) { + sock_set->num_socks = 0; + sock_set->socks = NULL; + +} + + + + + +/* This should probably check if the socket is already added */ +// adds socket to the sockset +void v3_set_sock(struct v3_sock_set * sock_set, V3_SOCK sock) { + struct v3_sock_entry * new_entry = V3_Malloc(sizeof(struct v3_sock_entry)); + + new_entry->sock = sock; + new_entry->is_set = 0; + + if (sock_set->socks) { + new_entry->next = sock_set->socks; + } + + sock_set->socks = new_entry; + + sock_set->num_socks++; +} + + +// deletes socket from sockset +void v3_clr_sock(struct v3_sock_set * sock_set, V3_SOCK sock) { + struct v3_sock_entry * iter, * back_ptr; + + iter = sock_set->socks; + back_ptr = NULL; + + v3_foreach_sock(sock_set, iter) { + if (iter->sock == sock) { + if (back_ptr == NULL) { + sock_set->socks = iter->next; + } else { + back_ptr->next = iter->next; + } + + V3_Free(iter); + + sock_set->num_socks--; + break; + } + + back_ptr = iter; + } +} + +// checks is_set vairable +int v3_isset_sock(struct v3_sock_set * sock_set, V3_SOCK sock) { + struct v3_sock_entry * iter; + + v3_foreach_sock(sock_set, iter) { + if (iter->sock == sock) { + return iter->is_set; + } + } + return -1; +} + + +// clears all is_set variables. +void v3_zero_sockset(struct v3_sock_set * sock_set) { + struct v3_sock_entry * iter; + v3_foreach_sock(sock_set, iter) { + iter->is_set = 0; + } +}