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.


Merge branch 'devel' of /home/palacios/palacios into devel
Lei Xia [Wed, 4 Feb 2009 00:00:02 +0000 (18:00 -0600)]
palacios/include/palacios/vmm_socket.h
palacios/src/palacios/vmm_socket.c

index 6025869..f73830e 100644 (file)
 #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(sock, ip_ptr) ({                      \
+#define V3_Listen_Socket(sock, backlog) ({                             \
       extern struct v3_socket_hooks * sock_hooks;              \
       int ret = -1;                                            \
-      if ((sock_hooks) && (sock_hooks)->accept) {              \
-       ret = (sock_hooks)->accept(sock, ip_ptr);               \
+      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;                                            \
@@ -214,7 +224,7 @@ struct v3_socket_hooks {
 
   int (*listen)(const V3_SOCK sock, int backlog);
   
-  V3_SOCK (*accept)(const V3_SOCK const sock, unsigned int * remote_ip, unsigned int * port);
+  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, \
index 2832db7..ee5bc92 100644 (file)
@@ -27,7 +27,7 @@
 struct v3_socket_hooks * sock_hooks = 0;
 
 
-//static int v3_socket_api_test(void);
+static int v3_socket_api_test(void);
 
 
 void V3_Init_Sockets(struct v3_socket_hooks * hooks) {
@@ -36,7 +36,7 @@ void V3_Init_Sockets(struct v3_socket_hooks * hooks) {
 
   PrintDebug("V3 sockets inited\n");
 
-  //v3_socket_api_test();
+  v3_socket_api_test();
   
   return;
 }
@@ -118,7 +118,7 @@ void v3_zero_sockset(struct v3_sock_set * sock_set) {
   }
 }
 
-#if 0
+#if 1
 static int
 v3_socket_api_test(void)
 {
@@ -129,6 +129,66 @@ v3_socket_api_test(void)
        V3_SOCK client;
        unsigned int remote_ip;
        
+       PrintDebug("\nIn Palacios: Test V3_Socket Macros\n");
+       sock = V3_Create_TCP_Socket();
+       if( sock == NULL ){
+               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 ){