From: Jack Lange Date: Tue, 3 Mar 2009 19:09:32 +0000 (-0600) Subject: changed V3_SOCK to int, and updated the sock_set types and macros X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=commitdiff_plain;h=2166b2c5f57341f9674821c4b2af0de607f63c2f changed V3_SOCK to int, and updated the sock_set types and macros --- diff --git a/palacios/include/palacios/vmm_socket.h b/palacios/include/palacios/vmm_socket.h index eb87f71..5776043 100644 --- a/palacios/include/palacios/vmm_socket.h +++ b/palacios/include/palacios/vmm_socket.h @@ -23,13 +23,12 @@ #include -#define V3_SOCK long #ifdef __V3VEE__ #define V3_Create_UDP_Socket() ({ \ extern struct v3_socket_hooks * sock_hooks; \ - V3_SOCK sock = 0; \ + int sock = 0; \ if ((sock_hooks) && (sock_hooks)->udp_socket) { \ sock = (sock_hooks)->udp_socket(0,0); \ } \ @@ -40,7 +39,7 @@ #define V3_Create_TCP_Socket() ({ \ extern struct v3_socket_hooks * sock_hooks; \ - V3_SOCK sock = 0; \ + int sock = 0; \ if ((sock_hooks) && (sock_hooks)->tcp_socket) { \ sock = (sock_hooks)->tcp_socket(0,0,0); \ } \ @@ -80,7 +79,7 @@ #define V3_Accept_Socket(sock, ip_ptr, port_ptr) ({ \ extern struct v3_socket_hooks * sock_hooks; \ - V3_SOCK client_sock = 0; \ + int client_sock = 0; \ if ((sock_hooks) && (sock_hooks)->accept) { \ client_sock = (sock_hooks)->accept(sock, ip_ptr, port_ptr); \ } \ @@ -177,6 +176,13 @@ }) + +#define V3_SOCK_SET(n, p) ((p)->fd_bits[(n)/8] |= (1 << ((n) & 7))) +#define V3_SOCK_CLR(n, p) ((p)->fd_bits[(n)/8] &= ~(1 << ((n) & 7))) +#define V3_SOCK_ISSET(n,p) ((p)->fd_bits[(n)/8] & (1 << ((n) & 7))) +#define V3_SOCK_ZERO(p) memset((void*)(p), 0, sizeof(*(p))) + + #endif @@ -185,46 +191,30 @@ struct v3_timeval { long tv_usec; /* and microseconds */ }; -struct v3_sock_entry { - V3_SOCK sock; - unsigned int is_set; - struct v3_sock_entry * 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_SOCK_SETSIZE 1000 -#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) +typedef struct v3_sock_set { + // This format needs to match the standard posix FD_SET format, so it can be cast + unsigned char fd_bits [(V3_SOCK_SETSIZE + 7) / 8]; +} v3_sock_set; struct v3_socket_hooks { // Socket creation routines - V3_SOCK (*tcp_socket)(const int bufsize, const int nodelay, const int nonblocking); - V3_SOCK (*udp_socket)(const int bufsize, const int nonblocking); + int (*tcp_socket)(const int bufsize, const int nodelay, const int nonblocking); + int (*udp_socket)(const int bufsize, const int nonblocking); // Socket Destruction - void (*close)(V3_SOCK sock); + void (*close)(int sock); // Network Server Calls - int (*bind_socket)(const V3_SOCK sock, const int port); + int (*bind_socket)(const int sock, const int port); - int (*listen)(const V3_SOCK sock, int backlog); + int (*listen)(const int sock, int backlog); - V3_SOCK (*accept)(const V3_SOCK sock, unsigned int * remote_ip, unsigned int * port); + int (*accept)(const int sock, unsigned int * remote_ip, unsigned int * port); // This going to suck int (*select)(struct v3_sock_set * rset, \ struct v3_sock_set * wset, \ @@ -232,22 +222,22 @@ struct v3_socket_hooks { struct v3_timeval tv); // Connect calls - int (*connect_to_ip)(const V3_SOCK sock, const int hostip, const int port); - int (*connect_to_host)(const V3_SOCK sock, const char * hostname, const int port); + int (*connect_to_ip)(const int sock, const int hostip, const int port); + int (*connect_to_host)(const int sock, const char * hostname, const int port); // TCP Data Transfer - int (*send)(const V3_SOCK sock, const char * buf, const int len); - int (*recv)(const V3_SOCK sock, char * buf, const int len); + int (*send)(const int sock, const char * buf, const int len); + int (*recv)(const int sock, char * buf, const int len); // UDP Data Transfer - int (*sendto_host)(const V3_SOCK sock, const char * hostname, const int port, + int (*sendto_host)(const int sock, const char * hostname, const int port, const char * buf, const int len); - int (*sendto_ip)(const V3_SOCK sock, const int ip_addr, const int port, + int (*sendto_ip)(const int sock, const int ip_addr, const int port, const char * buf, const int len); - int (*recvfrom_host)(const V3_SOCK sock, const char * hostname, const int port, + int (*recvfrom_host)(const int sock, const char * hostname, const int port, char * buf, const int len); - int (*recvfrom_ip)(const V3_SOCK sock, const int ip_addr, const int port, + int (*recvfrom_ip)(const int sock, const int ip_addr, const int port, char * buf, const int len); }; diff --git a/palacios/src/palacios/vmm_socket.c b/palacios/src/palacios/vmm_socket.c index c4736dd..acad8f3 100644 --- a/palacios/src/palacios/vmm_socket.c +++ b/palacios/src/palacios/vmm_socket.c @@ -26,215 +26,14 @@ struct v3_socket_hooks * sock_hooks = 0; - -//int v3_socket_api_test(void); - - void V3_Init_Sockets(struct v3_socket_hooks * hooks) { PrintInfo("Initializing Socket Interface\n"); sock_hooks = hooks; PrintDebug("V3 sockets inited\n"); - //v3_socket_api_test(); - return; } -void v3_init_sock_set(struct v3_sock_set * sock_set) { - sock_set->num_socks = 0; - sock_set->socks = NULL; - - return; -} - - - - - -/* 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; - } -} - -#if 0 - -int -v3_socket_api_test(void) -{ - unsigned int port; - char buf[1024]; - int rc = 0; - V3_SOCK sock; - V3_SOCK client; - unsigned int remote_ip; - - PrintDebug("\nIn Palacios: Test V3_Socket Macros\n"); - sock = V3_Create_TCP_Socket(); - if( ((int)sock) < 0 ){ - PrintDebug( "ERROR: tcp_socket() failed!\n"); - return -1; - } - - port = 80; - - if( V3_Bind_Socket(sock, port) < 0){ - PrintDebug("bind error\n"); - return -1; - } - - if( V3_Listen_Socket(sock, 1) < 0) { - PrintDebug("listen error\n" ); - return -1; - } - - PrintDebug( "Going into mainloop: server listening on port %d\n", port); - - client = V3_Accept_Socket(sock, &remote_ip, &port); - - PrintDebug(" New connection from %d port: %d\n", remote_ip, port); - - V3_Send(client, "Welcome!\n", 9); - - while(1) - { - V3_Send(client, buf, rc); - rc = V3_Recv(client, buf, sizeof(buf)-1); - if( rc <= 0 ){ - PrintDebug( "Closed connection\n"); - V3_Close_Socket(client); - break; - } - - buf[rc] = '\0'; - - PrintDebug( "Read %d bytes: '%s'\n", rc, buf); - } - - PrintDebug("TEST END: Sockets API\n"); - return 0; -} - -#endif - - -#if 0 - -static int -socket_api_test(void) -{ - unsigned int port; - char buf[1024]; - int rc = 0; - V3_SOCK sock; - V3_SOCK client; - unsigned int remote_ip; - - PrintDebug("\nIn Palacios: TEST BEGIN: Sockets API\n"); - sock = sock_hooks->tcp_socket(0, 0, 0); - if( sock == NULL ){ - PrintDebug( "ERROR: tcp_socket() failed!\n"); - return -1; - } - - port = 80; - - if( sock_hooks->bind_socket(sock, port) < 0){ - PrintDebug("bind error\n"); - return -1; - } - - if( sock_hooks->listen(sock, 1) < 0) { - PrintDebug("listen error\n" ); - return -1; - } - - PrintDebug( "Going into mainloop: server listening on port %d\n", port); - - client = sock_hooks->accept(sock, &remote_ip , &port); - - PrintDebug(" New connection from %d port: %d\n", remote_ip, port); - - sock_hooks->send(client, "Welcome!\n", 9); - - while(1) - { - sock_hooks->send(client, buf, rc); - rc = sock_hooks->recv(client, buf, sizeof(buf)-1); - if( rc <= 0 ){ - PrintDebug( "Closed connection\n"); - sock_hooks->close(client); - break; - } - - buf[rc] = '\0'; - - PrintDebug( "Read %d bytes: '%s'\n", rc, buf); - } - - PrintDebug("TEST END: Sockets API\n"); - return 0; -} - -#endif