X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fgeekos%2Fsocket.c;h=64b5f00b2535e27c3e282a9c03694644fbc68bfe;hb=b2d5697513a87d61e63a4317c89a0927b62b7ea1;hp=3b6da22df956b739bc874d4159a98cc937f31aa1;hpb=fb8c4864a1d840edf0be5a84ca30bc1517af8796;p=palacios.git diff --git a/palacios/src/geekos/socket.c b/palacios/src/geekos/socket.c index 3b6da22..64b5f00 100644 --- a/palacios/src/geekos/socket.c +++ b/palacios/src/geekos/socket.c @@ -19,7 +19,7 @@ struct socket sockets[MAX_SOCKS]; extern void* memcpy(void *dst, const void* src, int n); -int Packet_Received(struct NE2K_Packet_Info* info, uchar_t *pkt) ; +int Packet_Received(struct NE2K_Packet_Info* info, uchar_t *pkt); void init_network() { int i = 0; @@ -30,6 +30,7 @@ void init_network() { sockets[i].recv_buf = NULL; } + //initiate uIP uip_init(); uip_arp_init(); @@ -38,6 +39,7 @@ void init_network() { Init_Ne2k(&Packet_Received); + } static int allocate_socket_fd() { @@ -92,9 +94,10 @@ int connect(const uchar_t ip_addr[4], ushort_t port) { sockets[sockfd].con = uip_connect((uip_ipaddr_t *)&ip_addr, htons(port)); + if (sockets[sockfd].con == NULL){ - release_socket_fd(sockfd); - return -1; + release_socket_fd(sockfd); + return -1; } return sockfd; @@ -105,6 +108,7 @@ int recv(int sockfd, void * buf, uint_t len){ struct socket *sock = get_socket_from_fd(sockfd); + // here we need some lock mechnism, just disable interrupt may not work properly because recv() will be run as a kernel thread buf_read: recvlen = rb_read(sock->recv_buf, buf, len); @@ -201,76 +205,91 @@ senddata(int sockfd){ static int get_socket_from_port(ushort_t lport) { int i; - for (i = 0; ilport == lport) - return i; + + for (i = 0; i < MAX_SOCKS; i++){ + if (sockets[i].con->lport == lport) { + return i; + } } return -1; } -void -socket_appcall(void) -{ - int sockfd; +void socket_appcall(void) { + + int sockfd; + sockfd = get_socket_from_port(uip_conn->lport); - if (sockfd == -1) return; - - if(uip_connected()) { - connected(sockfd); + + if (sockfd == -1) { + return; + } + + if (uip_connected()) { + connected(sockfd); + } - if(uip_closed() ||uip_aborted() ||uip_timedout()) { + if (uip_closed() ||uip_aborted() ||uip_timedout()) { closed(sockfd); return; } - if(uip_acked()) { + if (uip_acked()) { acked(sockfd); } - if(uip_newdata()) { + if (uip_newdata()) { newdata(sockfd); } - if(uip_rexmit() || - uip_newdata() || - uip_acked() || - uip_connected() || - uip_poll()) { - senddata(sockfd); + if (uip_rexmit() || + uip_newdata() || + uip_acked() || + uip_connected() || + uip_poll()) { + senddata(sockfd); } } -int Packet_Received(struct NE2K_Packet_Info* info, uchar_t *pkt) -{ - uip_len = info->size; - - // for (i = 0; i < info->size; i++) { - // uip_buf[i] = *(pkt + i); - //} - - memcpy(uip_buf, pkt, uip_len); - Free(pkt); - if(BUF->type == htons(UIP_ETHTYPE_ARP)) { - uip_arp_arpin(); - if (uip_len > 0){ - //ethernet_devicedriver_send(); - NE2K_Transmit(uip_len); - } - } else { - uip_arp_ipin(); - uip_input(); - if(uip_len > 0) { - uip_arp_out(); - //ethernet_devicedriver_send(); - NE2K_Transmit(uip_len); - } - } - return 0; + +int Packet_Received(struct NE2K_Packet_Info * info, uchar_t * pkt) { + //int i; + + uip_len = info->size; + + // for (i = 0; i < info->size; i++) { + // uip_buf[i] = *(pkt + i); + //} + + memcpy(uip_buf, pkt, uip_len); + + + Free(pkt); + + if (BUF->type == htons(UIP_ETHTYPE_ARP)) { + uip_arp_arpin(); + + if (uip_len > 0) { + NE2K_Transmit(uip_len); + } + + } else { + + uip_arp_ipin(); + uip_input(); + + if (uip_len > 0) { + uip_arp_out(); + NE2K_Transmit(uip_len); + } + } + + return 0; + }