X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Finclude%2Fpalacios%2Fvmm_socket.h;h=f73830ebecf4ff61210aa2914b8684b4cfe85b2b;hb=3574c981404a1c812d369132db09ec2a27d59a5d;hp=df3beceaa4694e15a74cc459553ce0b87f4d8951;hpb=a3a2224fa5e7d5c9d0ef2fe29bae0ccfb373ba26;p=palacios.git diff --git a/palacios/include/palacios/vmm_socket.h b/palacios/include/palacios/vmm_socket.h index df3bece..f73830e 100644 --- a/palacios/include/palacios/vmm_socket.h +++ b/palacios/include/palacios/vmm_socket.h @@ -42,7 +42,7 @@ extern struct v3_socket_hooks * sock_hooks; \ V3_SOCK sock = 0; \ if ((sock_hooks) && (sock_hooks)->tcp_socket) { \ - sock = (sock_hooks)->tcp_socket(0,0); \ + sock = (sock_hooks)->tcp_socket(0,0,0); \ } \ sock; \ }) @@ -61,15 +61,41 @@ #define V3_Bind_Socket(sock, port) ({ \ extern struct v3_socket_hooks * sock_hooks; \ int ret = -1; \ - if ((sock_hooks) && (sock_hooks)->bind) { \ - ret = (sock_hooks)->bind(sock, port); \ + if ((sock_hooks) && (sock_hooks)->bind_socket) { \ + ret = (sock_hooks)->bind_socket(sock, port); \ } \ ret; \ }) -#define V3_Accept_Socket() (-1) -#define V3_Select_Socket() (-1) +#define V3_Listen_Socket(sock, backlog) ({ \ + extern struct v3_socket_hooks * sock_hooks; \ + int ret = -1; \ + if ((sock_hooks) && (sock_hooks)->listen) { \ + ret = (sock_hooks)->listen(sock, backlog); \ + } \ + ret; \ + }) + + +#define V3_Accept_Socket(sock, ip_ptr, port_ptr) ({ \ + extern struct v3_socket_hooks * sock_hooks; \ + V3_SOCK client_sock = 0; \ + if ((sock_hooks) && (sock_hooks)->accept) { \ + client_sock = (sock_hooks)->accept(sock, ip_ptr, port_ptr); \ + } \ + client_sock; \ + }) + + +#define V3_Select_Socket(rset,wset,eset,tv) ({ \ + extern struct v3_socket_hooks * sock_hooks; \ + int ret = -1; \ + if ((sock_hooks) && (sock_hooks)->select) { \ + ret = (sock_hooks)->select(rset, wset, eset, tv); \ + } \ + ret; \ + }) @@ -134,7 +160,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 +185,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_entry * next; +}; + +struct v3_sock_set { + unsigned int num_socks; + struct v3_sock_entry * socks; }; -#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) +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) + struct v3_socket_hooks { @@ -182,8 +221,10 @@ struct v3_socket_hooks { // Network Server Calls int (*bind_socket)(const V3_SOCK sock, const int port); + + int (*listen)(const V3_SOCK sock, int backlog); - int (*accept)(const V3_SOCK const sock); + V3_SOCK (*accept)(const V3_SOCK sock, unsigned int * remote_ip, unsigned int * port); // This going to suck int (*select)(struct v3_sock_set * rset, \ struct v3_sock_set * wset, \ @@ -211,7 +252,7 @@ struct v3_socket_hooks { }; -void V3_Init_Socket(struct v3_socket_hooks * hooks); +extern void V3_Init_Sockets(struct v3_socket_hooks * hooks); #endif