儲存庫 vbox 的更動 16443
- 時間撮記:
- 2009-1-31 上午07:16:03 (16 年 以前)
- 位置:
- trunk/src/VBox/Devices/Network
- 檔案:
-
- 修改 10 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/Devices/Network/DrvNAT.cpp
r16291 r16443 53 53 * activity. This needs to be fixed properly. 54 54 */ 55 #define VBOX_NAT_DELAY_HACK 55 /*#define VBOX_NAT_DELAY_HACK*/ 56 56 57 57 … … 148 148 Log2(("drvNATSend: pvBuf=%p cb=%#x\n%.*Rhxd\n", pvBuf, cb, cb, pvBuf)); 149 149 150 #ifdef VBOX_WITH_SIMPLIFIED_SLIRP_SYNC 150 #ifdef VBOX_WITH_SIMPLIFIED_SLIRP_SYNC 151 151 152 152 PRTREQ pReq = NULL; … … 155 155 if (pThis->pThread->enmState != PDMTHREADSTATE_RUNNING) 156 156 return VINF_SUCCESS; 157 #ifndef VBOX_WITH_SLIRP_MT 157 158 rc = RTReqAlloc(pThis->pReqQueue, &pReq, RTREQTYPE_INTERNAL); 159 #else 160 rc = RTReqAlloc((PRTREQQUEUE)slirp_get_queue(pThis->pNATState), &pReq, RTREQTYPE_INTERNAL); 161 #endif 158 162 AssertReleaseRC(rc); 159 163 pReq->u.Internal.pfn = (PFNRT)drvNATSendWorker; … … 163 167 pReq->u.Internal.aArgs[2] = (uintptr_t)cb; 164 168 pReq->fFlags = RTREQFLAGS_VOID; 169 165 170 rc = RTReqQueue(pReq, 0); /* don't wait, we have to wakeup the NAT thread fist */ 166 171 if (RT_LIKELY(rc == VERR_TIMEOUT)) … … 181 186 AssertReleaseRC(rc); 182 187 RTReqFree(pReq); 188 189 rc = WSASetEvent(pThis->hWakeupEvent); 190 AssertRelease(rc == TRUE); 183 191 184 192 #else /* !VBOX_WITH_SIMPLIFIED_SLIRP_SYNC */ … … 397 405 /* only check for slow/fast timers */ 398 406 slirp_select_poll(pThis->pNATState, /* fTimeout=*/true, /*fIcmp=*/false); 407 Log2(("%s: timeout\n", __FUNCTION__)); 399 408 continue; 400 409 } 401 410 402 411 /* poll the sockets in any case */ 412 Log2(("%s: poll\n", __FUNCTION__)); 403 413 slirp_select_poll(pThis->pNATState, /* fTimeout=*/false, /* fIcmp=*/(event == WSA_WAIT_EVENT_0)); 404 414 /* process _all_ outstanding requests but don't wait */ … … 444 454 { 445 455 PDRVNAT pThis = PDMINS_2_DATA(pDrvIns, PDRVNAT); 446 while (1) 456 if (pThread->enmState == PDMTHREADSTATE_INITIALIZING) 457 return VINF_SUCCESS; 458 while (pThread->enmState == PDMTHREADSTATE_RUNNING) 447 459 { 460 slirp_process_queue(pThis->pNATState); 448 461 } 462 return VINF_SUCCESS; 449 463 } 450 464 -
trunk/src/VBox/Devices/Network/slirp/debug.c
r15683 r16443 185 185 char buff[256]; 186 186 int n; 187 struct socket *so ;187 struct socket *so, *so_next; 188 188 189 189 lprint(" \n"); … … 192 192 "Proto[state] Sock Local Address, Port Remote Address, Port RecvQ SendQ\n"); 193 193 194 for (so = tcb.so_next; so != &tcb; so = so->so_next)195 {194 QSOCKET_FOREACH(so, so_next, tcp) 195 /* { */ 196 196 n = sprintf(buff, "tcp[%s]", so->so_tcpcb?tcpstates[so->so_tcpcb->t_state]:"NONE"); 197 197 while (n < 17) … … 203 203 inet_ntoa(so->so_faddr), ntohs(so->so_fport), 204 204 so->so_rcv.sb_cc, so->so_snd.sb_cc); 205 LOOP_LABEL(tcp, so, so_next); 205 206 } 206 207 207 for (so = udb.so_next; so != &udb; so = so->so_next)208 {208 QSOCKET_FOREACH(so, so_next, udp) 209 /* { */ 209 210 n = sprintf(buff, "udp[%d sec]", (so->so_expire - curtime) / 1000); 210 211 while (n < 17) … … 216 217 inet_ntoa(so->so_faddr), ntohs(so->so_fport), 217 218 so->so_rcv.sb_cc, so->so_snd.sb_cc); 219 LOOP_LABEL(udp, so, so_next); 218 220 } 219 221 } … … 248 250 249 251 AssertReturn(strcmp(pszType, "natsock") == 0, 0); 250 252 if (so->so_state == SS_NOFDREF || so->s == -1) 253 return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "socket SS_NODREF"); 251 254 status = getsockname(so->s, &addr, &socklen); 252 255 … … 257 260 "state=%04x ip=" IP4_ADDR_PRINTF_FORMAT ":%d name=" IP4_ADDR_PRINTF_FORMAT ":%d", 258 261 so->s, so->so_type, so->so_state, IP4_ADDR_PRINTF_DECOMP(ip), ntohs(so->so_fport), 259 IP4_ADDR_PRINTF_DECOMP( ((struct sockaddr_in *)&addr)->sin_addr.s_addr),262 IP4_ADDR_PRINTF_DECOMP(ntohl(((struct sockaddr_in *)&addr)->sin_addr.s_addr)), 260 263 ntohs(((struct sockaddr_in *)&addr)->sin_port)); 261 264 } -
trunk/src/VBox/Devices/Network/slirp/libslirp.h
r15890 r16443 89 89 void slirp_register_external_event(PNATState pData, HANDLE hEvent, int index); 90 90 #endif 91 #ifdef VBOX_WITH_SLIRP_MT 92 void slirp_process_queue(PNATState pData); 93 void *slirp_get_queue(PNATState pData); 94 #endif 91 95 92 96 /* -
trunk/src/VBox/Devices/Network/slirp/slirp.c
r16303 r16443 8 8 #include <iprt/assert.h> 9 9 10 #ifdef VBOX_WITH_SLIRP_MT11 # define CONTINUE(label) goto loop_end_ ## label ## _mt12 /* @todo replace queue parameter with macrodinition */13 # define LOOP_LABEL(label, so, sonext) loop_end_ ## label ## _mt: \14 SOCKET_UNLOCK(so); \15 QSOCKET_LOCK(_X(queue_ ## label ## _label)); \16 (so) = (sonext)17 #else18 #define CONTINUE(label) continue;19 # define LOOP_LABEL(label, so, sonext) /* empty*/20 #endif21 10 #if !defined(VBOX_WITH_SIMPLIFIED_SLIRP_SYNC) || !defined(RT_OS_WINDOWS) 22 11 … … 387 376 { 388 377 int fNATfailed = 0; 378 int rc; 389 379 PNATState pData = RTMemAlloc(sizeof(NATState)); 390 380 *ppData = pData; … … 409 399 pData->phEvents[VBOX_SOCKET_EVENT_INDEX] = CreateEvent(NULL, FALSE, FALSE, NULL); 410 400 # endif 401 #endif 402 #ifdef VBOX_WITH_SLIRP_MT 403 QSOCKET_LOCK_CREATE(tcb); 404 QSOCKET_LOCK_CREATE(udb); 405 rc = RTReqCreateQueue(&pData->pReqQueue); 406 AssertReleaseRC(rc); 411 407 #endif 412 408 … … 686 682 QSOCKET_FOREACH(so, so_next, udp) 687 683 /* { */ 688 so_next = so->so_next;689 684 690 685 STAM_COUNTER_INC(&pData->StatUDP); … … 698 693 { 699 694 udp_detach(pData, so); 700 CONTINUE (udp);695 CONTINUE_NO_UNLOCK(udp); 701 696 } 702 697 else … … 796 791 * Check TCP sockets 797 792 */ 798 for (so = tcb.so_next; so != &tcb; so = so_next) 799 { 800 so_next = so->so_next; 793 QSOCKET_FOREACH(so, so_next, tcp) 794 /* { */ 801 795 802 796 /* … … 834 828 if (so->so_state & SS_FACCEPTCONN) 835 829 { 836 tcp_connect(pData, so);830 TCP_CONNECT(pData, so); 837 831 #if defined(VBOX_WITH_SIMPLIFIED_SLIRP_SYNC) && defined(RT_OS_WINDOWS) 838 832 if (!(NetworkEvents.lNetworkEvents & FD_CLOSE)) … … 841 835 } 842 836 843 ret = soread(pData, so, /*fCloseIfNothingRead=*/false);837 SOREAD(ret, pData, so, /*fCloseIfNothingRead=*/false); 844 838 /* Output it if we read something */ 845 839 if (ret > 0) 846 tcp_output(pData, sototcpcb(so));840 TCP_OUTPUT(pData, sototcpcb(so)); 847 841 } 848 842 … … 858 852 for (;;) 859 853 { 860 ret = soread(pData, so, /*fCloseIfNothingRead=*/true);854 SOREAD(ret, pData, so, /*fCloseIfNothingRead=*/true); 861 855 if (ret > 0) 862 tcp_output(pData, sototcpcb(so));856 TCP_OUTPUT(pData, sototcpcb(so)); 863 857 else 864 858 break; … … 907 901 * Continue tcp_input 908 902 */ 909 tcp_input(pData, (struct mbuf *)NULL, sizeof(struct ip), so);903 TCP_INPUT(pData, (struct mbuf *)NULL, sizeof(struct ip), so); 910 904 /* continue; */ 911 905 } 912 906 else 913 ret = sowrite(pData, so);907 SOWRITE(ret, pData, so); 914 908 /* 915 909 * XXX If we wrote something (a lot), there could be the need … … 964 958 965 959 } 966 tcp_input((struct mbuf *)NULL, sizeof(struct ip),so);960 TCP_INPUT((struct mbuf *)NULL, sizeof(struct ip),so); 967 961 } /* SS_ISFCONNECTING */ 968 962 #endif … … 975 969 * Incoming UDP data isn't buffered either. 976 970 */ 977 for (so = udb.so_next; so != &udb; so = so_next) 978 { 979 so_next = so->so_next; 980 971 QSOCKET_FOREACH(so, so_next, udp) 972 /* { */ 981 973 POLL_UDP_EVENTS(rc, error, so, &NetworkEvents); 982 974 … … 985 977 if (so->s != -1 && CHECK_FD_SET(so, NetworkEvents, readfds)) 986 978 { 987 sorecvfrom(pData, so);979 SORECVFROM(pData, so); 988 980 } 989 981 LOOP_LABEL(udp, so, so_next); … … 1290 1282 m_free(pData, m); 1291 1283 } 1284 #ifdef VBOX_WITH_SLIRP_MT 1285 void slirp_process_queue(PNATState pData) 1286 { 1287 RTReqProcess(pData->pReqQueue, RT_INDEFINITE_WAIT); 1288 } 1289 void *slirp_get_queue(PNATState pData) 1290 { 1291 return pData->pReqQueue; 1292 } 1293 #endif -
trunk/src/VBox/Devices/Network/slirp/slirp_state.h
r16292 r16443 21 21 #ifndef _slirp_state_h_ 22 22 #define _slirp_state_h_ 23 #include <iprt/req.h> 23 24 #include "ip_icmp.h" 24 25 … … 100 101 struct in_addr alias_addr; 101 102 struct in_addr special_addr; 103 #ifdef VBOX_WITH_SLIRP_MT 104 PRTREQQUEUE pReqQueue; 105 #endif 102 106 #ifndef VBOX_WITH_MULTI_DNS 103 107 struct in_addr dns_addr; … … 116 120 struct socket tcb; 117 121 #ifdef VBOX_WITH_SLIRP_MT 118 RT SEMMUTEXtcb_mutex;122 RTCRITSECT tcb_mutex; 119 123 #endif 120 124 struct socket *tcp_last_so; … … 134 138 struct socket udb; 135 139 #ifdef VBOX_WITH_SLIRP_MT 136 RT SEMMUTEXudb_mutex;140 RTCRITSECT udb_mutex; 137 141 #endif 138 142 struct socket *udp_last_so; … … 277 281 #define __X(x) x 278 282 #define _X(x) __X(x) 279 283 #define _str(x) #x 284 #define str(x) _str(x) 280 285 #ifdef VBOX_WITH_SLIRP_MT 281 286 #define QSOCKET_LOCK(queue) \ 282 287 do { \ 283 int rc = RTSemMutexRequest(_X(queue) ## _mutex, RT_INDEFINITE_WAIT); \ 288 int rc; \ 289 rc = RTCritSectEnter(&_X(queue) ## _mutex); \ 284 290 AssertReleaseRC(rc); \ 285 291 } while (0) 286 292 #define QSOCKET_UNLOCK(queue) \ 287 293 do { \ 288 int rc = RTSemMutexRelease(_X(queue) ## _mutex); \ 294 int rc; \ 295 rc = RTCritSectLeave(&_X(queue) ## _mutex); \ 289 296 AssertReleaseRC(rc); \ 290 297 } while (0) 291 298 #define QSOCKET_LOCK_CREATE(queue) \ 292 299 do { \ 293 int rc = RTSemMutexCreate(&pData->queue ## _mutex); \ 300 int rc; \ 301 rc = RTCritSectInit(&pData->queue ## _mutex); \ 294 302 AssertReleaseRC(rc); \ 295 303 } while (0) 296 304 #define QSOCKET_LOCK_DESTROY(queue) \ 297 305 do { \ 298 int rc = RT SemMutexDestroy(pData->queue ## _mutex); \306 int rc = RTCritSectDelete(&pData->queue ## _mutex); \ 299 307 AssertReleaseRC(rc); \ 300 308 } while (0) … … 303 311 QSOCKET_LOCK(__X(queue_## label ## _label)); \ 304 312 (so) = (_X(queue_ ## label ## _label)).so_next; \ 305 SOCKET_LOCK((so));\313 if ((so) != &(_X(queue_## label ## _label))) SOCKET_LOCK((so)); \ 306 314 for(;;) \ 307 315 { \ … … 311 319 break; \ 312 320 } \ 321 Log2(("%s:%d Processing so:%R[natsock]\n", __FUNCTION__, __LINE__, (so))); \ 313 322 if ((so)->so_next != &(_X(queue_## label ## _label))) \ 314 323 { \ … … 317 326 (sonext) = (so)->so_next; \ 318 327 QSOCKET_UNLOCK(__X(queue_## label ##_label)); 328 329 # define CONTINUE_NO_UNLOCK(label) goto loop_end_ ## label ## _mt_nounlock 330 # define CONTINUE(label) goto loop_end_ ## label ## _mt 331 /* @todo replace queue parameter with macrodinition */ 332 # define LOOP_LABEL(label, so, sonext) loop_end_ ## label ## _mt: \ 333 SOCKET_UNLOCK(so); \ 334 loop_end_ ## label ## _mt_nounlock: \ 335 QSOCKET_LOCK(_X(queue_ ## label ## _label)); \ 336 (so) = (sonext) 337 338 #define DO_TCP_OUTPUT(data, sotcb) \ 339 do { \ 340 PRTREQ pReq = NULL; \ 341 int rc; \ 342 rc = RTReqAlloc((data)->pReqQueue, &pReq, RTREQTYPE_INTERNAL); \ 343 AssertReleaseRC(rc); \ 344 pReq->u.Internal.pfn = (PFNRT)tcp_output; \ 345 pReq->u.Internal.cArgs = 2; \ 346 pReq->u.Internal.aArgs[0] = (uintptr_t)(data); \ 347 pReq->u.Internal.aArgs[1] = (uintptr_t)(sotcb); \ 348 pReq->fFlags = RTREQFLAGS_VOID; \ 349 rc = RTReqQueue(pReq, 0); \ 350 if (RT_LIKELY(rc) == VERR_TIMEOUT) \ 351 { \ 352 SOCKET_UNLOCK(so); \ 353 rc = RTReqWait(pReq, RT_INDEFINITE_WAIT); \ 354 AssertReleaseRC(rc); \ 355 SOCKET_LOCK(so); \ 356 RTReqFree(pReq); \ 357 } \ 358 else \ 359 AssertReleaseRC(rc); \ 360 } while(0) 361 362 #define DO_TCP_INPUT(data, mbuf, size, so) \ 363 do { \ 364 PRTREQ pReq = NULL; \ 365 int rc; \ 366 rc = RTReqAlloc((data)->pReqQueue, &pReq, RTREQTYPE_INTERNAL); \ 367 AssertReleaseRC(rc); \ 368 pReq->u.Internal.pfn = (PFNRT)tcp_input; \ 369 pReq->u.Internal.cArgs = 4; \ 370 pReq->u.Internal.aArgs[0] = (uintptr_t)(data); \ 371 pReq->u.Internal.aArgs[1] = (uintptr_t)(mbuf); \ 372 pReq->u.Internal.aArgs[2] = (uintptr_t)(size); \ 373 pReq->u.Internal.aArgs[3] = (uintptr_t)(so); \ 374 pReq->fFlags = RTREQFLAGS_VOID; \ 375 rc = RTReqQueue(pReq, 0); \ 376 if (RT_LIKELY(rc) == VERR_TIMEOUT) \ 377 { \ 378 SOCKET_UNLOCK(so); \ 379 rc = RTReqWait(pReq, RT_INDEFINITE_WAIT); \ 380 AssertReleaseRC(rc); \ 381 SOCKET_LOCK(so); \ 382 RTReqFree(pReq); \ 383 } \ 384 else \ 385 AssertReleaseRC(rc); \ 386 } while(0) 387 388 #define DO_TCP_CONNECT(data, so) \ 389 do { \ 390 PRTREQ pReq = NULL; \ 391 int rc; \ 392 rc = RTReqAlloc((data)->pReqQueue, &pReq, RTREQTYPE_INTERNAL); \ 393 AssertReleaseRC(rc); \ 394 pReq->u.Internal.pfn = (PFNRT)tcp_connect; \ 395 pReq->u.Internal.cArgs = 2; \ 396 pReq->u.Internal.aArgs[0] = (uintptr_t)(data); \ 397 pReq->u.Internal.aArgs[1] = (uintptr_t)(so); \ 398 pReq->fFlags = RTREQFLAGS_VOID; \ 399 rc = RTReqQueue(pReq, 0); /* don't wait, we have to release lock before*/ \ 400 if (RT_LIKELY(rc) == VERR_TIMEOUT) \ 401 { \ 402 SOCKET_UNLOCK(so); \ 403 rc = RTReqWait(pReq, RT_INDEFINITE_WAIT); \ 404 AssertReleaseRC(rc); \ 405 SOCKET_LOCK(so); \ 406 RTReqFree(pReq); \ 407 } \ 408 else \ 409 AssertReleaseRC(rc); \ 410 } while(0) 411 412 #define DO_SOREAD(ret, data, so, ifclose) \ 413 do { \ 414 PRTREQ pReq = NULL; \ 415 int rc; \ 416 rc = RTReqAlloc((data)->pReqQueue, &pReq, RTREQTYPE_INTERNAL); \ 417 AssertReleaseRC(rc); \ 418 pReq->u.Internal.pfn = (PFNRT)soread_queue; \ 419 pReq->u.Internal.cArgs = 4; \ 420 pReq->u.Internal.aArgs[0] = (uintptr_t)(data); \ 421 pReq->u.Internal.aArgs[1] = (uintptr_t)(so); \ 422 pReq->u.Internal.aArgs[2] = (uintptr_t)(ifclose); \ 423 pReq->u.Internal.aArgs[3] = (uintptr_t)&(ret); \ 424 pReq->fFlags = RTREQFLAGS_VOID; \ 425 rc = RTReqQueue(pReq, 0); /* don't wait, we have to release lock before*/ \ 426 if (RT_LIKELY(rc) == VERR_TIMEOUT) \ 427 { \ 428 SOCKET_UNLOCK(so); \ 429 rc = RTReqWait(pReq, RT_INDEFINITE_WAIT); \ 430 AssertReleaseRC(rc); \ 431 SOCKET_LOCK(so); \ 432 RTReqFree(pReq); \ 433 } \ 434 else \ 435 AssertReleaseRC(rc); \ 436 } while(0) 437 438 #define DO_SOWRITE(ret, data, so) \ 439 do { \ 440 PRTREQ pReq = NULL; \ 441 int rc; \ 442 rc = RTReqAlloc((data)->pReqQueue, &pReq, RTREQTYPE_INTERNAL); \ 443 AssertReleaseRC(rc); \ 444 pReq->u.Internal.pfn = (PFNRT)sowrite; \ 445 pReq->u.Internal.cArgs = 2; \ 446 pReq->u.Internal.aArgs[0] = (uintptr_t)(data); \ 447 pReq->u.Internal.aArgs[1] = (uintptr_t)(so); \ 448 pReq->fFlags = RTREQFLAGS_RETURN_MASK; \ 449 rc = RTReqQueue(pReq, 0); /* don't wait, we have to release lock before*/ \ 450 if (RT_LIKELY(rc) == VERR_TIMEOUT) \ 451 { \ 452 SOCKET_UNLOCK(so); \ 453 rc = RTReqWait(pReq, RT_INDEFINITE_WAIT); \ 454 SOCKET_LOCK(so); \ 455 ret = pReq->iStatus; \ 456 RTReqFree(pReq); \ 457 } \ 458 else \ 459 AssertReleaseRC(rc); \ 460 } while(0) 461 462 #define DO_SORECFROM(data, so) \ 463 do { \ 464 PRTREQ pReq = NULL; \ 465 int rc; \ 466 rc = RTReqAlloc((data)->pReqQueue, &pReq, RTREQTYPE_INTERNAL); \ 467 AssertReleaseRC(rc); \ 468 pReq->u.Internal.pfn = (PFNRT)sorecvfrom; \ 469 pReq->u.Internal.cArgs = 2; \ 470 pReq->u.Internal.aArgs[0] = (uintptr_t)(data); \ 471 pReq->u.Internal.aArgs[1] = (uintptr_t)(so); \ 472 pReq->fFlags = RTREQFLAGS_VOID; \ 473 rc = RTReqQueue(pReq, 0); \ 474 if (RT_LIKELY(rc) == VERR_TIMEOUT) \ 475 { \ 476 SOCKET_UNLOCK(so); \ 477 rc = RTReqWait(pReq, RT_INDEFINITE_WAIT); \ 478 AssertReleaseRC(rc); \ 479 SOCKET_LOCK(so); \ 480 RTReqFree(pReq); \ 481 } \ 482 else \ 483 AssertReleaseRC(rc); \ 484 } while(0) 485 486 #define SOLOOKUP(so, label, src, sport, dst, dport) \ 487 do { \ 488 struct socket *sonxt; \ 489 (so) = NULL; \ 490 QSOCKET_FOREACH(so, sonxt, label) \ 491 /* { */ \ 492 if ( so->so_lport == (sport) \ 493 && so->so_laddr.s_addr == (src).s_addr \ 494 && so->so_faddr.s_addr == (dst).s_addr \ 495 && so->so_fport == (dport)) \ 496 { \ 497 if (sonxt != &__X(queue_ ## label ## _label)) \ 498 SOCKET_UNLOCK(sonxt); \ 499 break; /*so is locked*/ \ 500 } \ 501 LOOP_LABEL(so, sonxt, label); \ 502 } \ 503 } \ 504 }while (0) 505 319 506 #else 320 507 #define QSOCKET_LOCK(queue) do {} while (0) … … 326 513 { \ 327 514 (sonext) = (so)->so_next; 328 #endif 329 515 # define CONTINUE(label) continue 516 # define CONTINUE_NO_UNLOCK(label) continue 517 # define LOOP_LABEL(label, so, sonext) /* empty*/ 518 #define DO_TCP_OUTPUT(data, sotcb) tcp_output((data), (sotcb)) 519 #define DO_TCP_INPUT(data, mbuf, size, so) tcp_input((data), (mbuf), (size), (so)) 520 #define DO_TCP_CONNECT(data, so) tcp_connect((data), (so)) 521 #define DO_SOREAD(ret, data, so, ifclose) do{(ret) = soread((data), (so), (ifclose));}while(0) 522 #define DO_SOWRITE(ret, data, so) do{(ret) = sowrite((data), (so));}while(0) 523 #define DO_SORECFROM(data, so) sorecvfrom((data), (so)) 524 #define SOLOOKUP(so, label, src, sport, dst, dport) \ 525 do { \ 526 (so) = solookup(&__X(queue_ ## label ## _label), (src), (sport), (dst), (dport)); \ 527 } while (0) 528 #endif 529 530 #define TCP_OUTPUT(data, sotcb) DO_TCP_OUTPUT((data), (sotcb)) 531 #define TCP_INPUT(data, mbuf, size, so) DO_TCP_INPUT((data), (mbuf), (size), (so)) 532 #define TCP_CONNECT(data, so) DO_TCP_CONNECT((data), (so)) 533 #define SOREAD(ret, data, so, ifclose) DO_SOREAD((ret), (data), (so), (ifclose)) 534 #define SOWRITE(ret, data, so) DO_SOWRITE((ret), (data), (so)) 535 #define SORECVFROM(data, so) DO_SORECFROM((data), (so)) 330 536 #endif /* !_slirp_state_h_ */ -
trunk/src/VBox/Devices/Network/slirp/socket.c
r16293 r16443 60 60 struct socket *so; 61 61 62 so = (struct socket *)RTMemAlloc (sizeof(struct socket));62 so = (struct socket *)RTMemAllocZ(sizeof(struct socket)); 63 63 if(so) 64 64 { … … 89 89 if(so->so_next && so->so_prev) 90 90 remque(pData, so); /* crashes if so is not in a queue */ 91 91 so->so_state = SS_NOFDREF; /* for debugging purposes */ 92 92 SOCKET_UNLOCK(so); 93 93 SOCKET_LOCK_DESTROY(so); 94 94 95 95 RTMemFree(so); 96 } 96 so = NULL; 97 } 98 99 #ifdef VBOX_WITH_SLIRP_MT 100 void 101 soread_queue(PNATState pData, struct socket *so, int fCloseIfNothingRead, int *ret) 102 { 103 *ret = soread(pData, so, fCloseIfNothingRead); 104 } 105 #endif 97 106 98 107 /* … … 109 118 struct iovec iov[2]; 110 119 int mss = so->so_tcpcb->t_maxseg; 120 Log2(("%s:%d soread before lock\n", __FUNCTION__, __LINE__)); 121 QSOCKET_LOCK(tcb); 122 SOCKET_LOCK(so); 123 QSOCKET_UNLOCK(tcb); 124 Log2(("%s:%d soread before lock\n",__FUNCTION__, __LINE__)); 111 125 112 126 DEBUG_CALL("soread"); … … 190 204 */ 191 205 if (nn == 0 && !fCloseIfNothingRead) 206 { 207 SOCKET_UNLOCK(so); 192 208 return 0; 209 } 193 210 #endif 194 211 if (nn < 0 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)) 212 { 213 SOCKET_UNLOCK(so); 195 214 return 0; 215 } 196 216 else 197 217 { … … 201 221 sofcantrcvmore(so); 202 222 tcp_sockclosed(pData, sototcpcb(so)); 223 SOCKET_UNLOCK(so); 203 224 return -1; 204 225 } … … 231 252 if (sb->sb_wptr >= (sb->sb_data + sb->sb_datalen)) 232 253 sb->sb_wptr -= sb->sb_datalen; 254 SOCKET_UNLOCK(so); 233 255 return nn; 234 256 } … … 344 366 DEBUG_CALL("sowrite"); 345 367 DEBUG_ARG("so = %lx", (long)so); 346 368 QSOCKET_LOCK(tcb); 369 SOCKET_LOCK(so); 370 QSOCKET_UNLOCK(tcb); 347 371 if (so->so_urgc) 348 372 { 349 373 sosendoob(so); 350 374 if (sb->sb_cc == 0) 375 { 376 SOCKET_UNLOCK(so); 351 377 return 0; 378 } 352 379 } 353 380 … … 396 423 /* This should never happen, but people tell me it does *shrug* */ 397 424 if (nn < 0 && (errno == EAGAIN || errno == EINTR || errno == EWOULDBLOCK)) 425 { 426 SOCKET_UNLOCK(so); 398 427 return 0; 428 } 399 429 400 430 if (nn < 0 || (nn == 0 && iov[0].iov_len > 0)) … … 404 434 sofcantsendmore(so); 405 435 tcp_sockclosed(pData, sototcpcb(so)); 436 SOCKET_UNLOCK(so); 406 437 return -1; 407 438 } … … 431 462 sofcantsendmore(so); 432 463 464 SOCKET_UNLOCK(so); 433 465 return nn; 434 466 } … … 463 495 u_long n; 464 496 465 if (!(m = m_get(pData))) 497 QSOCKET_LOCK(udb); 498 SOCKET_LOCK(so); 499 QSOCKET_UNLOCK(udb); 500 501 if (!(m = m_get(pData))) 502 { 503 SOCKET_UNLOCK(so); 466 504 return; 505 } 467 506 m->m_data += if_maxlinkhdr; 468 507 #ifdef VBOX_WITH_SIMPLIFIED_SLIRP_SYNC … … 490 529 m->m_len = recvfrom(so->s, m->m_data, len, 0, 491 530 (struct sockaddr *)&addr, &addrlen); 492 DEBUG_MISC((dfd," did recvfrom %d, errno = %d-%s\n",531 Log2((" did recvfrom %d, errno = %d-%s\n", 493 532 m->m_len, errno,strerror(errno))); 494 533 if(m->m_len < 0) … … 501 540 code = ICMP_UNREACH_NET; 502 541 503 DEBUG_MISC((dfd," rx error, tx icmp ICMP_UNREACH:%i\n", code));542 Log2((dfd," rx error, tx icmp ICMP_UNREACH:%i\n", code)); 504 543 icmp_error(pData, so->so_m, ICMP_UNREACH,code, 0,strerror(errno)); 505 544 m_free(pData, m); … … 534 573 */ 535 574 udp_output(pData, so, m, &addr); 575 SOCKET_UNLOCK(so); 536 576 } /* rx error */ 537 577 } /* if ping packet */ … … 678 718 int tmperrno = WSAGetLastError(); /* Don't clobber the real reason we failed */ 679 719 closesocket(s); 720 QSOCKET_LOCK(tcb); 680 721 sofree(pData, so); 722 QSOCKET_UNLOCK(tcb); 681 723 /* Restore the real errno */ 682 724 WSASetLastError(tmperrno); -
trunk/src/VBox/Devices/Network/slirp/socket.h
r16291 r16443 11 11 #define _SLIRP_SOCKET_H_ 12 12 #ifdef VBOX_WITH_SLIRP_MT 13 #include <iprt/ semaphore.h>13 #include <iprt/critsect.h> 14 14 #endif 15 15 … … 68 68 struct sbuf so_snd; /* Send buffer */ 69 69 #ifdef VBOX_WITH_SLIRP_MT 70 RT SEMMUTEXso_mutex;70 RTCRITSECT so_mutex; 71 71 #endif 72 72 }; … … 75 75 # define SOCKET_LOCK(so) \ 76 76 do { \ 77 int rc = RTSemMutexRequest((so)->so_mutex, RT_INDEFINITE_WAIT); \ 77 int rc; \ 78 Log2(("lock:%s:%d L on %R[natsock]\n", __FUNCTION__, __LINE__, (so))); \ 79 rc = RTCritSectEnter(&(so)->so_mutex); \ 78 80 AssertReleaseRC(rc); \ 79 81 } while (0) 80 82 # define SOCKET_UNLOCK(so) \ 81 83 do { \ 82 int rc = RTSemMutexRelease((so)->so_mutex); \ 84 int rc; \ 85 if ((so) != NULL) Log2(("lock:%s:%d U on %R[natsock]\n", __FUNCTION__, __LINE__, (so))); \ 86 rc = RTCritSectLeave(&(so)->so_mutex); \ 83 87 AssertReleaseRC(rc); \ 84 88 } while (0) 85 89 # define SOCKET_LOCK_CREATE(so) \ 86 90 do { \ 87 int rc = RTSemMutexCreate(&(so)->so_mutex); \ 91 int rc; \ 92 rc = RTCritSectInit(&(so)->so_mutex); \ 88 93 AssertReleaseRC(rc); \ 89 94 } while (0) 90 95 # define SOCKET_LOCK_DESTROY(so) \ 91 96 do { \ 92 int rc = RT SemMutexDestroy((so)->so_mutex);\97 int rc = RTCritSectDelete(&(so)->so_mutex); \ 93 98 AssertReleaseRC(rc); \ 94 99 } while (0) … … 130 135 struct socket * socreate _P((void)); 131 136 void sofree _P((PNATState, struct socket *)); 137 #ifdef VBOX_WITH_SLIRP_MT 138 void soread_queue (PNATState, struct socket *, int, int *); 139 #endif 132 140 int soread _P((PNATState, struct socket *, int)); 133 141 void sorecvoob _P((PNATState, struct socket *)); -
trunk/src/VBox/Devices/Network/slirp/tcp_input.c
r16291 r16443 277 277 DEBUG_ARGS((dfd," m = %8lx iphlen = %2d inso = %lx\n", 278 278 (long )m, iphlen, (long )inso )); 279 279 280 if (inso != NULL) 281 { 282 QSOCKET_LOCK(tcb); 283 SOCKET_LOCK(inso); 284 QSOCKET_UNLOCK(tcb); 285 } 280 286 /* 281 287 * If called with m == 0, then we're continuing the connect … … 395 401 */ 396 402 findso: 403 if (so != NULL && so != &tcb) 404 SOCKET_UNLOCK(so); 405 QSOCKET_LOCK(tcb); 397 406 so = tcp_last_so; 398 407 if ( so->so_fport != ti->ti_dport … … 401 410 || so->so_faddr.s_addr != ti->ti_dst.s_addr) 402 411 { 412 struct socket *sonxt; 413 QSOCKET_UNLOCK(tcb); 414 /* @todo fix SOLOOKUP macrodefinition to be usable here */ 415 #ifndef VBOX_WITH_SLIRP_MT 403 416 so = solookup(&tcb, ti->ti_src, ti->ti_sport, 404 417 ti->ti_dst, ti->ti_dport); 418 #else 419 so = NULL; 420 QSOCKET_FOREACH(so, sonxt, tcp) 421 /* { */ 422 if ( so->so_lport == ti->ti_sport 423 && so->so_laddr.s_addr == ti->ti_src.s_addr 424 && so->so_faddr.s_addr == ti->ti_dst.s_addr 425 && so->so_fport == ti->ti_dport) 426 { 427 if (sonxt != &tcb) 428 SOCKET_UNLOCK(sonxt); 429 Log2(("lock: %s:%d We found socket %R[natsock]\n", __FUNCTION__, __LINE__, so)); 430 break; /* so is locked here */ 431 } 432 LOOP_LABEL(tcp, so, sonxt); 433 } 434 if (so == &tcb) { 435 Log2(("lock: %s:%d Haven't find anything \n", __FUNCTION__, __LINE__)); 436 so = NULL; 437 } 438 #endif 405 439 if (so) 440 { 406 441 tcp_last_so = so; 442 } 407 443 ++tcpstat.tcps_socachemiss; 444 } 445 else 446 { 447 SOCKET_LOCK(so); 448 QSOCKET_UNLOCK(tcb); 408 449 } 409 450 … … 421 462 * as if it was LISTENING, and continue... 422 463 */ 464 Log2(("so = %p\n", so)); 423 465 if (so == 0) 424 466 { … … 594 636 (void) tcp_output(pData, tp); 595 637 638 SOCKET_UNLOCK(so); 596 639 return; 597 640 } … … 637 680 tp->t_flags |= TF_ACKNOW; 638 681 tcp_output(pData, tp); 682 SOCKET_UNLOCK(so); 639 683 return; 640 684 } … … 736 780 tp->t_state = TCPS_SYN_RECEIVED; 737 781 } 782 SOCKET_UNLOCK(so); 738 783 return; 739 784 … … 765 810 tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT; 766 811 tcpstat.tcps_accepts++; 812 Log2(("hit trimthenstep6\n")); 767 813 goto trimthenstep6; 768 814 } /* case TCPS_LISTEN */ … … 854 900 tp->snd_wl1 = ti->ti_seq - 1; 855 901 tp->rcv_up = ti->ti_seq; 902 Log2(("hit6")); 856 903 goto step6; 857 904 } /* switch tp->t_state */ … … 985 1032 iss = tp->rcv_nxt + TCP_ISSINCR; 986 1033 tp = tcp_close(pData, tp); 1034 SOCKET_UNLOCK(tp->t_socket); 987 1035 goto findso; 988 1036 } … … 1117 1165 tp->snd_wl1 = ti->ti_seq - 1; 1118 1166 /* Avoid ack processing; snd_una==ti_ack => dup ack */ 1167 Log2(("hit synrx_to_est\n")); 1119 1168 goto synrx_to_est; 1120 1169 /* fall into ... */ … … 1201 1250 } 1202 1251 synrx_to_est: 1252 Log2(("enter synrx_to_est\n")); 1203 1253 /* 1204 1254 * If the congestion window was inflated to account … … 1429 1479 tp->rcv_up = tp->rcv_nxt; 1430 1480 dodata: 1481 Log2(("do data hit!\n")); 1431 1482 1432 1483 /* … … 1567 1618 tcp_output(pData, tp); 1568 1619 1620 SOCKET_UNLOCK(so); 1569 1621 return; 1570 1622 … … 1580 1632 tp->t_flags |= TF_ACKNOW; 1581 1633 (void) tcp_output(pData, tp); 1634 SOCKET_UNLOCK(so); 1582 1635 return; 1583 1636 1584 1637 dropwithreset: 1585 1638 /* reuses m if m!=NULL, m_free() unnecessary */ 1586 Log2(("drop with reset\n"));1587 1639 if (tiflags & TH_ACK) 1588 1640 tcp_respond(pData, tp, ti, m, (tcp_seq)0, ti->ti_ack, TH_RST); … … 1594 1646 } 1595 1647 1648 if (so != &tcb) 1649 SOCKET_UNLOCK(so); 1596 1650 return; 1597 1651 … … 1600 1654 * Drop space held by incoming segment and return. 1601 1655 */ 1602 Log2(("drop\n"));1603 1656 m_free(pData, m); 1604 1657 1658 SOCKET_UNLOCK(so); 1605 1659 return; 1606 1660 } -
trunk/src/VBox/Devices/Network/slirp/tcp_timer.c
r15845 r16443 44 44 tcp_fasttimo(PNATState pData) 45 45 { 46 register struct socket *so ;46 register struct socket *so, *so_next; 47 47 register struct tcpcb *tp; 48 48 … … 51 51 so = tcb.so_next; 52 52 if (so) 53 for (; so != &tcb; so = so->so_next) 53 QSOCKET_FOREACH (so, so_next,tcp) 54 /* { */ 54 55 if ( (tp = (struct tcpcb *)so->so_tcpcb) 55 56 && (tp->t_flags & TF_DELACK)) … … 58 59 tp->t_flags |= TF_ACKNOW; 59 60 tcpstat.tcps_delack++; 60 (void) tcp_output(pData, tp); 61 } 61 TCP_OUTPUT(pData, tp); 62 } 63 LOOP_LABEL(tcp, so, so_next); 64 } 62 65 } 63 66 … … 82 85 if (ip == 0) 83 86 return; 84 for (; ip != &tcb; ip = ipnxt)85 {87 QSOCKET_FOREACH(ip, ipnxt, tcp) 88 /* { */ 86 89 ipnxt = ip->so_next; 87 90 tp = sototcpcb(ip); 88 91 if (tp == 0) 89 continue;92 CONTINUE(tcp); 90 93 for (i = 0; i < TCPT_NTIMERS; i++) 91 94 { … … 102 105 tpgone: 103 106 ; 107 LOOP_LABEL(tcp, ip, ipnxt); 104 108 } 105 109 tcp_iss += TCP_ISSINCR / PR_SLOWHZ; /* increment iss */ -
trunk/src/VBox/Devices/Network/slirp/udp.c
r16291 r16443 384 384 /* enable broadcast for later use */ 385 385 setsockopt(so->s, SOL_SOCKET, SO_BROADCAST, (const char *)&opt, sizeof(opt)); 386 status = getsockname(so->s, &sa_addr, &socklen); 387 Assert(status == 0 && sa_addr.sa_family == AF_INET); 388 so->so_hlport = ((struct sockaddr_in *)&sa_addr)->sin_port; 389 so->so_hladdr.s_addr = ((struct sockaddr_in *)&sa_addr)->sin_addr.s_addr; 386 390 SOCKET_LOCK_CREATE(so); 387 391 QSOCKET_LOCK(udb); 388 392 insque(pData, so,&udb); 389 393 QSOCKET_UNLOCK(udb); 390 status = getsockname(so->s, &sa_addr, &socklen);391 Assert(status == 0 && sa_addr.sa_family == AF_INET);392 so->so_hlport = ((struct sockaddr_in *)&sa_addr)->sin_port;393 so->so_hladdr.s_addr = ((struct sockaddr_in *)&sa_addr)->sin_addr.s_addr;394 394 } 395 395 } … … 403 403 { 404 404 closesocket(so->s); 405 QSOCKET_LOCK(udb); 405 406 sofree(pData, so); 407 QSOCKET_UNLOCK(udb); 406 408 } 407 409 } … … 699 701 so->s = socket(AF_INET,SOCK_DGRAM,0); 700 702 so->so_expire = curtime + SO_EXPIRE; 703 SOCKET_LOCK_CREATE(so); 704 QSOCKET_LOCK(udb); 701 705 insque(pData, so,&udb); 706 QSOCKET_UNLOCK(udb); 702 707 703 708 addr.sin_family = AF_INET;
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器