Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


added sock_set functions for select() support
Jack Lange [Tue, 25 Nov 2008 00:36:15 +0000 (18:36 -0600)]
palacios/include/palacios/vmm_socket.h
palacios/src/palacios/vmm_socket.c

index df3bece..bfc7123 100644 (file)
 #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, \
index 8546688..dbc19c0 100644 (file)
@@ -19,6 +19,8 @@
 
 
 #include <palacios/vmm_socket.h>
+#include <palacios/vmm.h>
+
 
 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;
+  }
+}