Changeset 13604 in vbox for trunk/src/VBox/Devices/Network/slirp/socket.c
- Timestamp:
- Oct 28, 2008 4:47:11 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/slirp/socket.c
r8009 r13604 12 12 #ifdef __sun__ 13 13 #include <sys/filio.h> 14 #endif 15 16 #ifdef VBOX_WITH_SYNC_SLIRP 17 #include <iprt/semaphore.h> 14 18 #endif 15 19 … … 60 64 so->so_state = SS_NOFDREF; 61 65 so->s = -1; 66 #ifdef VBOX_WITH_SYNC_SLIRP 67 RTSemMutexCreate(&so->so_mutex); 68 #endif 62 69 } 63 70 return(so); … … 70 77 sofree(PNATState pData, struct socket *so) 71 78 { 79 #ifndef VBOX_WITH_SYNC_SLIRP 72 80 if (so->so_emu==EMU_RSH && so->extra) { 73 81 sofree(pData, so->extra); … … 83 91 if(so->so_next && so->so_prev) 84 92 remque(pData, so); /* crashes if so is not in a queue */ 93 #else 94 /*Take global mutexes of udb and tcb, because we dont know which is mutex */ 95 /*XXX: don't forget to set correct so_type in corresponded attach operation */ 96 RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT); 97 if (so->so_emu==EMU_RSH && so->extra) { 98 sofree(pData, so->extra); 99 so->extra=NULL; 100 } 101 102 if (so->so_type == IPPROTO_UDP) { 103 RTSemMutexRequest(pData->udb_mutex, RT_INDEFINITE_WAIT); 104 } 105 else if (so->so_type == IPPROTO_TCP) { 106 RTSemMutexRequest(pData->tcb_mutex, RT_INDEFINITE_WAIT); 107 } 108 else { 109 Assert(!"unknown type"); 110 } 111 112 if (so == tcp_last_so) 113 tcp_last_so = &tcb; 114 else if (so == udp_last_so) 115 udp_last_so = &udb; 116 117 if(so->so_next && so->so_prev) 118 remque(pData, so); /* crashes if so is not in a queue */ 119 120 if (so->so_type == IPPROTO_UDP) { 121 RTSemMutexRelease(pData->udb_mutex); 122 } 123 else if (so->so_type == IPPROTO_TCP) { 124 RTSemMutexRelease(pData->tcb_mutex); 125 } 126 else { 127 Assert(!"unknown type"); 128 } 129 /* socket's mutex could be released because socket none accessible via queue anymore*/ 130 RTSemMutexRelease(so->so_mutex); 131 132 m_free(pData, so->so_m); 133 134 135 RTSemMutexDestroy(so->so_mutex); 136 #endif 85 137 86 138 free(so); 139 so = NULL; 87 140 } 88 141 … … 101 154 int mss = so->so_tcpcb->t_maxseg; 102 155 156 #ifdef VBOX_WITH_SYNC_SLIRP 157 RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT); 158 #endif 103 159 DEBUG_CALL("soread"); 104 160 DEBUG_ARG("so = %lx", (long )so); … … 159 215 #endif 160 216 if (nn <= 0) { 161 if (nn < 0 && (errno == EINTR || errno == EAGAIN)) 217 if (nn < 0 && (errno == EINTR || errno == EAGAIN)) { 218 #ifdef VBOX_WITH_SYNC_SLIRP 219 RTSemMutexRelease(so->so_mutex); 220 #endif 162 221 return 0; 222 } 163 223 else { 164 224 DEBUG_MISC((dfd, " --- soread() disconnected, nn = %d, errno = %d-%s\n", nn, errno,strerror(errno))); 165 225 sofcantrcvmore(so); 166 226 tcp_sockclosed(pData, sototcpcb(so)); 227 #ifdef VBOX_WITH_SYNC_SLIRP 228 RTSemMutexRelease(so->so_mutex); 229 #endif 167 230 return -1; 168 231 } … … 194 257 if (sb->sb_wptr >= (sb->sb_data + sb->sb_datalen)) 195 258 sb->sb_wptr -= sb->sb_datalen; 259 #ifdef VBOX_WITH_SYNC_SLIRP 260 RTSemMutexRelease(so->so_mutex); 261 #endif 196 262 return nn; 197 263 } … … 207 273 sorecvoob(PNATState pData, struct socket *so) 208 274 { 275 #ifdef VBOX_WITH_SYNC_SLIRP 276 RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT); 277 #endif 209 278 struct tcpcb *tp = sototcpcb(so); 210 279 … … 225 294 tcp_output(pData, tp); 226 295 tp->t_force = 0; 296 #ifdef VBOX_WITH_SYNC_SLIRP 297 RTSemMutexRelease(so->so_mutex); 298 #endif 227 299 } 228 300 … … 239 311 240 312 int n, len; 313 #ifdef VBOX_WITH_SYNC_SLIRP 314 RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT); 315 #endif 241 316 242 317 DEBUG_CALL("sosendoob"); … … 283 358 sb->sb_rptr -= sb->sb_datalen; 284 359 360 #ifdef VBOX_WITH_SYNC_SLIRP 361 RTSemMutexRelease(so->so_mutex); 362 #endif 285 363 return n; 286 364 } … … 297 375 int len = sb->sb_cc; 298 376 struct iovec iov[2]; 377 #ifdef VBOX_WITH_SYNC_SLIRP 378 RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT); 379 #endif 299 380 300 381 DEBUG_CALL("sowrite"); … … 344 425 #endif 345 426 /* This should never happen, but people tell me it does *shrug* */ 346 if (nn < 0 && (errno == EAGAIN || errno == EINTR)) 427 if (nn < 0 && (errno == EAGAIN || errno == EINTR)) { 428 #ifdef VBOX_WITH_SYNC_SLIRP 429 RTSemMutexRelease(so->so_mutex); 430 #endif 347 431 return 0; 432 } 348 433 349 434 if (nn <= 0) { … … 352 437 sofcantsendmore(so); 353 438 tcp_sockclosed(pData, sototcpcb(so)); 439 #ifdef VBOX_WITH_SYNC_SLIRP 440 RTSemMutexRelease(so->so_mutex); 441 #endif 354 442 return -1; 355 443 } … … 378 466 sofcantsendmore(so); 379 467 468 #ifdef VBOX_WITH_SYNC_SLIRP 469 RTSemMutexRelease(so->so_mutex); 470 #endif 380 471 return nn; 381 472 } … … 392 483 DEBUG_CALL("sorecvfrom"); 393 484 DEBUG_ARG("so = %lx", (long)so); 485 486 #ifdef VBOX_WITH_SYNC_SLIRP 487 RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT); 488 #endif 394 489 395 490 if (so->so_type == IPPROTO_ICMP) { /* This is a "ping" reply */ … … 478 573 } /* rx error */ 479 574 } /* if ping packet */ 575 #ifdef VBOX_WITH_SYNC_SLIRP 576 RTSemMutexRelease(so->so_mutex); 577 #endif 480 578 } 481 579 … … 490 588 #if 0 491 589 struct sockaddr_in host_addr; 590 #endif 591 #ifdef VBOX_WITH_SYNC_SLIRP 592 RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT); 492 593 #endif 493 594 … … 542 643 ret = sendto(so->s, m->m_data, m->m_len, 0, 543 644 (struct sockaddr *)&addr, sizeof (struct sockaddr)); 544 if (ret < 0) 645 if (ret < 0) { 646 #ifdef VBOX_WITH_SYNC_SLIRP 647 RTSemMutexRelease(so->so_mutex); 648 #endif 545 649 return -1; 650 } 546 651 547 652 /* … … 552 657 so->so_expire = curtime + SO_EXPIRE; 553 658 so->so_state = SS_ISFCONNECTED; /* So that it gets select()ed */ 659 #ifdef VBOX_WITH_SYNC_SLIRP 660 RTSemMutexRelease(so->so_mutex); 661 #endif 554 662 return 0; 555 663 } … … 582 690 return NULL; 583 691 } 692 #ifndef VBOX_WITH_SYNC_SLIRP 584 693 insque(pData, so,&tcb); 694 #else 695 RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT); 696 /*after adding to global queue probably we should keep lock*/ 697 RTSemMutexRequest(pData->tcb_mutex, RT_INDEFINITE_WAIT); 698 insque(pData, so,&tcb); 699 RTSemMutexRelease(pData->tcb_mutex); 700 #endif 585 701 586 702 /* … … 627 743 628 744 so->s = s; 745 #ifdef VBOX_WITH_SYNC_SLIRP 746 RTSemMutexRelease(so->so_mutex); 747 #endif 629 748 return so; 630 749 } … … 665 784 register struct socket *so; 666 785 { 786 #ifdef VBOX_WITH_SYNC_SLIRP 787 RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT); 788 #endif 667 789 so->so_state &= ~(SS_NOFDREF|SS_ISFCONNECTED|SS_FCANTRCVMORE| 668 790 SS_FCANTSENDMORE|SS_FWDRAIN); 669 791 so->so_state |= SS_ISFCONNECTING; /* Clobber other states */ 792 #ifdef VBOX_WITH_SYNC_SLIRP 793 RTSemMutexRelease(so->so_mutex); 794 #endif 670 795 } 671 796 … … 674 799 register struct socket *so; 675 800 { 801 #ifdef VBOX_WITH_SYNC_SLIRP 802 RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT); 803 #endif 676 804 so->so_state &= ~(SS_ISFCONNECTING|SS_FWDRAIN|SS_NOFDREF); 677 805 so->so_state |= SS_ISFCONNECTED; /* Clobber other states */ 806 #ifdef VBOX_WITH_SYNC_SLIRP 807 RTSemMutexRelease(so->so_mutex); 808 #endif 678 809 } 679 810 … … 682 813 struct socket *so; 683 814 { 815 #ifdef VBOX_WITH_SYNC_SLIRP 816 RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT); 817 #endif 684 818 if ((so->so_state & SS_NOFDREF) == 0) { 685 819 shutdown(so->s,0); … … 690 824 else 691 825 so->so_state |= SS_FCANTRCVMORE; 826 #ifdef VBOX_WITH_SYNC_SLIRP 827 RTSemMutexRelease(so->so_mutex); 828 #endif 692 829 } 693 830 … … 696 833 struct socket *so; 697 834 { 835 #ifdef VBOX_WITH_SYNC_SLIRP 836 RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT); 837 #endif 698 838 if ((so->so_state & SS_NOFDREF) == 0) { 699 839 shutdown(so->s,1); /* send FIN to fhost */ … … 704 844 else 705 845 so->so_state |= SS_FCANTSENDMORE; 846 #ifdef VBOX_WITH_SYNC_SLIRP 847 RTSemMutexRelease(so->so_mutex); 848 #endif 706 849 } 707 850 … … 726 869 struct socket *so; 727 870 { 871 #ifdef VBOX_WITH_SYNC_SLIRP 872 RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT); 873 #endif 728 874 if (so->so_rcv.sb_cc) 729 875 so->so_state |= SS_FWDRAIN; 730 876 else 731 877 sofcantsendmore(so); 732 } 733 878 #ifdef VBOX_WITH_SYNC_SLIRP 879 RTSemMutexRelease(so->so_mutex); 880 #endif 881 } 882
Note:
See TracChangeset
for help on using the changeset viewer.