Changeset 13727 in vbox for trunk/src/VBox/Devices/Network/slirp/slirp.c
- Timestamp:
- Nov 1, 2008 9:00:32 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/slirp/slirp.c
r13704 r13727 203 203 { 204 204 int fNATfailed = 0; 205 #ifdef VBOX_WITH_SYNC_SLIRP206 int rc = 0;207 #endif208 205 PNATState pData = malloc(sizeof(NATState)); 209 206 *ppData = pData; … … 230 227 #endif 231 228 232 #ifdef VBOX_WITH_SYNC_SLIRP 233 rc = RTSemMutexCreate(&pData->tcb_mutex); 234 AssertReleaseRC(rc); 235 rc = RTSemMutexCreate(&pData->tcp_last_so_mutex); 236 AssertReleaseRC(rc); 237 rc = RTSemMutexCreate(&pData->udb_mutex); 238 AssertReleaseRC(rc); 239 rc = RTSemMutexCreate(&pData->udp_last_so_mutex); 240 AssertReleaseRC(rc); 241 rc = RTSemMutexCreate(&pData->if_queued_mutex); 242 AssertReleaseRC(rc); 243 rc = RTSemMutexCreate(&pData->next_m_mutex); 244 AssertReleaseRC(rc); 245 #endif 229 VBOX_SLIRP_LOCK_CREATE(&pData->tcb_mutex); 230 VBOX_SLIRP_LOCK_CREATE(&pData->tcp_last_so_mutex); 231 VBOX_SLIRP_LOCK_CREATE(&pData->udb_mutex); 232 VBOX_SLIRP_LOCK_CREATE(&pData->udp_last_so_mutex); 233 VBOX_SLIRP_LOCK_CREATE(&pData->if_queued_mutex); 234 VBOX_SLIRP_LOCK_CREATE(&pData->next_m_mutex); 246 235 247 236 Assert(sizeof(struct ip) == 20); … … 379 368 * in the fragment queue, or there are TCP connections active 380 369 */ 381 #ifndef VBOX_WITH_SYNC_SLIRP 370 VBOX_SLIRP_LOCK(pData->tcb_mutex); 382 371 do_slowtimo = ((tcb.so_next != &tcb) || 383 372 ((struct ipasfrag *)&ipq != u32_to_ptr(pData, ipq.next, struct ipasfrag *))); 384 373 374 so = tcb.so_next; 375 #ifndef VBOX_WITH_SYNC_SLIRP 385 376 for (so = tcb.so_next; so != &tcb; so = so_next) { 386 so_next = so->so_next;387 377 #else 388 RTSemMutexRequest(pData->tcb_mutex, RT_INDEFINITE_WAIT);389 so = tcb.so_next;390 do_slowtimo = ((so != &tcb) ||391 ((struct ipasfrag *)&ipq != u32_to_ptr(pData, ipq.next, struct ipasfrag *)));392 378 while (1) { 393 379 if (so == &tcb) { 394 RTSemMutexRelease(pData->tcb_mutex);380 VBOX_SLIRP_UNLOCK(pData->tcb_mutex); 395 381 break; 396 382 } 383 #endif 397 384 so_next = so->so_next; 398 RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT); 399 RTSemMutexRelease(pData->tcb_mutex); 400 #endif 385 VBOX_SLIRP_LOCK(so->so_mutex); 386 VBOX_SLIRP_UNLOCK(pData->tcb_mutex); 401 387 402 388 /* … … 411 397 */ 412 398 if (so->so_state & SS_NOFDREF || so->s == -1) 413 #ifndef VBOX_WITH_SYNC_SLIRP414 continue;415 #else416 399 goto before_loop_ends; 417 #endif418 400 419 401 /* … … 423 405 FD_SET(so->s, readfds); 424 406 UPD_NFDS(so->s); 425 #ifndef VBOX_WITH_SYNC_SLIRP426 continue;427 #else428 407 goto before_loop_ends; 429 #endif430 408 } 431 409 … … 436 414 FD_SET(so->s, writefds); 437 415 UPD_NFDS(so->s); 438 #ifndef VBOX_WITH_SYNC_SLIRP439 continue;440 #else441 416 goto before_loop_ends; 442 #endif443 417 } 444 418 … … 461 435 UPD_NFDS(so->s); 462 436 } 463 #ifdef VBOX_WITH_SYNC_SLIRP464 437 before_loop_ends: 465 438 /*Release of global tcb mutex happens in the head of loop*/ 466 RTSemMutexRelease(so->so_mutex); 467 RTSemMutexRequest(pData->tcb_mutex, RT_INDEFINITE_WAIT); 439 VBOX_SLIRP_UNLOCK(so->so_mutex); 440 VBOX_SLIRP_LOCK(pData->tcb_mutex); 441 #ifdef VBOX_WITH_SYNC_SLIRP 468 442 so = so_next; 469 443 #endif … … 473 447 * UDP sockets 474 448 */ 449 VBOX_SLIRP_LOCK(pData->udb_mutex); 450 so = udb.so_next; 475 451 #ifndef VBOX_WITH_SYNC_SLIRP 476 452 for (so = udb.so_next; so != &udb; so = so_next) { 477 so_next = so->so_next;478 453 #else 479 RTSemMutexRequest(pData->udb_mutex, RT_INDEFINITE_WAIT);480 so = udb.so_next;481 454 while(1) { 482 455 if (so == &udb) { 483 RTSemMutexRelease(pData->udb_mutex);456 VBOX_SLIRP_UNLOCK(pData->udb_mutex); 484 457 break; 485 458 } 486 so_next = so->so_next; 487 RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT);488 RTSemMutexRelease(pData->udb_mutex);489 #endif 459 #endif 460 so_next = so->so_next; 461 VBOX_SLIRP_LOCK(so->so_mutex); 462 VBOX_SLIRP_UNLOCK(pData->udb_mutex); 490 463 491 464 /* … … 495 468 if (so->so_expire <= curtime) { 496 469 udp_detach(pData, so); 497 #ifndef VBOX_WITH_SYNC_SLIRP498 continue;499 #else500 470 goto before_udp_loop_end; 501 #endif502 471 } else 503 472 do_slowtimo = 1; /* Let socket expire */ … … 518 487 UPD_NFDS(so->s); 519 488 } 489 before_udp_loop_end: 490 VBOX_SLIRP_UNLOCK(so->so_mutex); 491 VBOX_SLIRP_LOCK(pData->udb_mutex); 520 492 #ifdef VBOX_WITH_SYNC_SLIRP 521 before_udp_loop_end:522 RTSemMutexRelease(so->so_mutex);523 RTSemMutexRequest(pData->udb_mutex, RT_INDEFINITE_WAIT);524 493 so = so_next; 525 494 #endif … … 593 562 * Check TCP sockets 594 563 */ 564 VBOX_SLIRP_LOCK(pData->tcb_mutex); 565 so = tcb.so_next; 595 566 #ifndef VBOX_WITH_SYNC_SLIRP 596 567 for (so = tcb.so_next; so != &tcb; so = so_next) { 597 so_next = so->so_next;598 568 #else 599 RTSemMutexRequest(pData->tcb_mutex, RT_INDEFINITE_WAIT);600 so = tcb.so_next;601 569 while (1) { 602 570 if (so == &tcb) { 603 RTSemMutexRelease(pData->tcb_mutex);571 VBOX_SLIRP_UNLOCK(pData->tcb_mutex); 604 572 break; 605 573 } 606 so_next = so->so_next; 607 RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT);608 RTSemMutexRelease(pData->tcb_mutex);609 #endif 574 #endif 575 so_next = so->so_next; 576 VBOX_SLIRP_LOCK(so->so_mutex); 577 VBOX_SLIRP_UNLOCK(pData->tcb_mutex); 610 578 611 579 /* … … 614 582 */ 615 583 if (so->so_state & SS_NOFDREF || so->s == -1) 616 #ifndef VBOX_WITH_SYNC_SLIRP617 continue;618 #else619 584 goto before_loop_ends; 620 #endif621 585 622 586 /* … … 636 600 if (so->so_state & SS_FACCEPTCONN) { 637 601 tcp_connect(pData, so); 638 #ifndef VBOX_WITH_SYNC_SLIRP639 continue;640 #else641 602 goto before_loop_ends; 642 #endif643 603 } /* else */ 644 604 ret = soread(pData, so); … … 672 632 if (errno == EAGAIN || errno == EWOULDBLOCK || 673 633 errno == EINPROGRESS || errno == ENOTCONN) 674 #ifndef VBOX_WITH_SYNC_SLIRP675 continue;676 #else677 634 goto before_loop_ends; 678 #endif679 635 680 636 /* else failed */ … … 711 667 if (errno == EAGAIN || errno == EWOULDBLOCK || 712 668 errno == EINPROGRESS || errno == ENOTCONN) 713 #ifndef VBOX_WITH_SYNC_SLIRP 714 continue;/* Still connecting, continue */ 715 #else 716 goto before_loop_ends; 717 #endif 669 goto before_loop_ends;/* Still connecting, continue */ 718 670 719 671 /* else failed */ … … 727 679 if (errno == EAGAIN || errno == EWOULDBLOCK || 728 680 errno == EINPROGRESS || errno == ENOTCONN) 729 #ifndef VBOX_WITH_SYNC_SLIRP730 continue;731 #else732 681 goto before_loop_ends; 733 #endif734 682 /* else failed */ 735 683 so->so_state = SS_NOFDREF; … … 741 689 } /* SS_ISFCONNECTING */ 742 690 #endif 691 before_loop_ends: 692 VBOX_SLIRP_UNLOCK(so->so_mutex); 693 VBOX_SLIRP_LOCK(pData->tcb_mutex); 743 694 #ifdef VBOX_WITH_SYNC_SLIRP 744 before_loop_ends:745 RTSemMutexRelease(so->so_mutex);746 RTSemMutexRequest(pData->tcb_mutex, RT_INDEFINITE_WAIT);747 695 so = so_next; 748 696 #endif … … 754 702 * Incoming UDP data isn't buffered either. 755 703 */ 704 VBOX_SLIRP_LOCK(pData->udb_mutex); 705 so = udb.so_next; 756 706 #ifndef VBOX_WITH_SYNC_SLIRP 757 707 for (so = udb.so_next; so != &udb; so = so_next) { 758 so_next = so->so_next;759 708 #else 760 RTSemMutexRequest(pData->udb_mutex, RT_INDEFINITE_WAIT);761 so = udb.so_next;762 709 while(1) { 763 710 if (so == &udb) { 764 RTSemMutexRelease(pData->udb_mutex);711 VBOX_SLIRP_UNLOCK(pData->udb_mutex); 765 712 break; 766 713 } 714 #endif 767 715 so_next = so->so_next; 768 RTSemMutexRequest(so->so_mutex, RT_INDEFINITE_WAIT); 769 RTSemMutexRelease(pData->udb_mutex); 770 #endif 716 VBOX_SLIRP_LOCK(so->so_mutex); 717 VBOX_SLIRP_UNLOCK(pData->udb_mutex); 771 718 772 719 if (so->s != -1 && FD_ISSET(so->s, readfds)) { 773 720 sorecvfrom(pData, so); 774 721 } 722 VBOX_SLIRP_UNLOCK(so->so_mutex); 723 VBOX_SLIRP_LOCK(pData->udb_mutex); 775 724 #ifdef VBOX_WITH_SYNC_SLIRP 776 RTSemMutexRelease(so->so_mutex);777 RTSemMutexRequest(pData->udb_mutex, RT_INDEFINITE_WAIT);778 725 so = so_next; 779 726 #endif … … 790 737 #if 0 791 738 if (link_up) { 792 RTSemMutexRequest(pData->if_queued_mutex, RT_INDEFINITE_WAIT);739 VBOX_SLIRP_LOCK(pData->if_queued_mutex); 793 740 if (if_queued > 0){ 794 RTSemMutexRelease(pData->if_queued_mutex);741 VBOX_SLIRP_UNLOCK(pData->if_queued_mutex); 795 742 if_start(pData); 796 743 } 797 744 else { 798 RTSemMutexRelease(pData->if_queued_mutex);745 VBOX_SLIRP_UNLOCK(pData->if_queued_mutex); 799 746 } 800 747 } … … 891 838 struct mbuf *m; 892 839 int proto; 893 #ifdef VBOX_WITH_SYNC_SLIRP894 int rc;895 #endif896 840 897 841 if (pkt_len < ETH_HLEN) … … 909 853 910 854 m = m_get(pData); 911 #ifdef VBOX_WITH_SYNC_SLIRP912 if (m != NULL) {913 rc = RTSemMutexRequest(m->m_mutex, RT_INDEFINITE_WAIT);914 AssertReleaseRC(rc);915 }916 #endif917 855 if (!m) 918 856 return; 857 VBOX_SLIRP_LOCK(m->m_mutex); 919 858 /* Note: we add to align the IP header */ 920 859 if (M_FREEROOM(m) < pkt_len + 2) { … … 928 867 929 868 ip_input(pData, m); 930 #ifdef VBOX_WITH_SYNC_SLIRP 931 rc = RTSemMutexRelease(m->m_mutex); 932 AssertReleaseRC(rc); 933 #endif 869 VBOX_SLIRP_UNLOCK(m->m_mutex); 934 870 break; 935 871 default:
Note:
See TracChangeset
for help on using the changeset viewer.