X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvmm_socket.c;h=c4736dd184bbf495a544c6acabce8b94ce6319ee;hb=3ad91649ab3f5b74f08ac049683ea1a75e63535c;hp=2832db77662b7b47b52ae19d5a7a94dd803a1cc3;hpb=362bcedc1da3725afc621c93d26d74f30c796354;p=palacios.git diff --git a/palacios/src/palacios/vmm_socket.c b/palacios/src/palacios/vmm_socket.c index 2832db7..c4736dd 100644 --- a/palacios/src/palacios/vmm_socket.c +++ b/palacios/src/palacios/vmm_socket.c @@ -27,7 +27,7 @@ struct v3_socket_hooks * sock_hooks = 0; -//static int v3_socket_api_test(void); +//int v3_socket_api_test(void); void V3_Init_Sockets(struct v3_socket_hooks * hooks) { @@ -119,7 +119,8 @@ void v3_zero_sockset(struct v3_sock_set * sock_set) { } #if 0 -static int + +int v3_socket_api_test(void) { unsigned int port; @@ -129,6 +130,67 @@ 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( ((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 ){