Changeset 101885 in vbox
- Timestamp:
- Nov 6, 2023 5:52:28 PM (15 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/xpcom18a4/ipc/ipcd/client/src/ipcConnectionUnix.cpp
r99775 r101885 38 38 #include "private/pprio.h" 39 39 #include "prerror.h" 40 #include "prthread.h"41 #include "prlock.h"42 #include "prlog.h" // for PR_ASSERT (we don't actually use NSPR logging)43 40 #include "prio.h" 44 41 … … 49 46 50 47 #ifdef VBOX 51 # include "prenv.h" 48 # include <iprt/assert.h> 49 # include <iprt/critsect.h> 50 # include <iprt/err.h> 51 # include <iprt/env.h> 52 # include <iprt/log.h> 53 # include <iprt/thread.h> 54 52 55 # include <stdio.h> 53 # include <VBox/log.h>54 56 #endif 55 57 … … 64 66 65 67 66 // single user systems, like OS/2, don't need these security checks.67 #ifndef XP_OS268 #define IPC_SKIP_SECURITY_CHECKS69 #endif70 71 #ifndef IPC_SKIP_SECURITY_CHECKS72 68 #include <unistd.h> 73 69 #include <sys/stat.h> 74 #endif75 70 76 71 static PRStatus 77 72 DoSecurityCheck(PRFileDesc *fd, const char *path) 78 73 { 79 #ifndef IPC_SKIP_SECURITY_CHECKS80 74 // 81 75 // now that we have a connected socket; do some security checks on the … … 116 110 } 117 111 } 118 #endif 112 119 113 return PR_SUCCESS; 120 114 } … … 134 128 struct ipcConnectionState 135 129 { 136 PRLock *lock;130 RTCRITSECT CritSect; 137 131 PRPollDesc fds[2]; 138 132 ipcCallbackQ callback_queue; … … 146 140 #define POLL 1 147 141 148 static void 149 ConnDestroy(ipcConnectionState *s) 150 { 151 if (s->lock) 152 PR_DestroyLock(s->lock); 142 static void ConnDestroy(ipcConnectionState *s) 143 { 144 if (RTCritSectIsInitialized(&s->CritSect)) 145 RTCritSectDelete(&s->CritSect); 153 146 154 147 if (s->fds[SOCK].fd) … … 165 158 } 166 159 167 static ipcConnectionState * 168 ConnCreate(PRFileDesc *fd) 160 static ipcConnectionState *ConnCreate(PRFileDesc *fd) 169 161 { 170 162 ipcConnectionState *s = new ipcConnectionState; … … 172 164 return NULL; 173 165 174 s->lock = PR_NewLock(); 166 int vrc = RTCritSectInit(&s->CritSect); 167 if (RT_FAILURE(vrc)) 168 { 169 ConnDestroy(s); 170 return NULL; 171 } 172 175 173 s->fds[SOCK].fd = NULL; 176 174 s->fds[POLL].fd = PR_NewPollableEvent(); … … 179 177 s->shutdown = PR_FALSE; 180 178 181 if (!s-> lock || !s->fds[1].fd)179 if (!s->fds[1].fd) 182 180 { 183 181 ConnDestroy(s); … … 251 249 } 252 250 253 PR_ASSERT(PRUint32(n) >= bytesRead);251 Assert(PRUint32(n) >= bytesRead); 254 252 n -= bytesRead; 255 253 pdata += bytesRead; … … 276 274 nsresult rv = NS_OK; 277 275 278 PR_Lock(s->lock);276 RTCritSectEnter(&s->CritSect); 279 277 280 278 // write one message and then return. … … 312 310 } 313 311 314 PR_Unlock(s->lock);312 RTCritSectLeave(&s->CritSect); 315 313 return rv; 316 314 } 317 315 318 PR_STATIC_CALLBACK(void) 319 ConnThread(void *arg) 320 { 316 static DECLCALLBACK(int) ipcConnThread(RTTHREAD hSelf, void *pvArg) 317 { 318 RT_NOREF(hSelf); 319 321 320 PRInt32 num; 322 321 nsresult rv = NS_OK; 323 322 324 ipcConnectionState *s = (ipcConnectionState *) arg;323 ipcConnectionState *s = (ipcConnectionState *)pvArg; 325 324 326 325 // we monitor two file descriptors in this thread. the first (at index 0) is … … 352 351 { 353 352 PR_WaitForPollableEvent(s->fds[POLL].fd); 354 PR_Lock(s->lock);353 RTCritSectEnter(&s->CritSect); 355 354 356 355 if (!s->send_queue.IsEmpty()) … … 360 359 s->callback_queue.MoveTo(cbs_to_run); 361 360 362 PR_Unlock(s->lock);361 RTCritSectLeave(&s->CritSect); 363 362 } 364 363 … … 382 381 // request until after all queued up messages have been sent and until 383 382 // after all queued up callbacks have been run. 384 PR_Lock(s->lock);383 RTCritSectEnter(&s->CritSect); 385 384 if (s->shutdown && s->send_queue.IsEmpty() && s->callback_queue.IsEmpty()) 386 385 rv = NS_ERROR_ABORT; 387 PR_Unlock(s->lock);386 RTCritSectLeave(&s->CritSect); 388 387 } 389 388 else … … 401 400 402 401 LOG(("IPC thread exiting\n")); 402 return VINF_SUCCESS; 403 403 } 404 404 … … 408 408 409 409 static ipcConnectionState *gConnState = NULL; 410 static PRThread *gConnThread = NULL;410 static RTTHREAD gConnThread = NULL; 411 411 412 412 #ifdef DEBUG 413 static PRThread *gMainThread = NULL;413 static RTTHREAD gMainThread = NULL; 414 414 #endif 415 415 … … 436 436 437 437 #ifdef VBOX 438 if ( PR_GetEnv("TESTBOX_UUID"))438 if (RTEnvExist("TESTBOX_UUID")) 439 439 fprintf(stderr, "IPC socket path: %s\n", addr.local.path); 440 440 LogRel(("IPC socket path: %s\n", addr.local.path)); … … 467 467 PRFileDesc *fd = NULL; 468 468 nsresult rv = NS_ERROR_FAILURE; 469 int vrc = VINF_SUCCESS; 469 470 470 471 if (gConnState) … … 505 506 fd = NULL; // connection state now owns the socket 506 507 507 gConnThread = PR_CreateThread(PR_USER_THREAD, 508 ConnThread, 509 gConnState, 510 PR_PRIORITY_NORMAL, 511 PR_GLOBAL_THREAD, 512 PR_JOINABLE_THREAD, 513 0); 514 if (!gConnThread) 508 vrc = RTThreadCreate(&gConnThread, ipcConnThread, gConnState, 0 /*cbStack*/, 509 RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "Ipc-Conn"); 510 if (RT_FAILURE(vrc)) 515 511 { 516 512 rv = NS_ERROR_OUT_OF_MEMORY; … … 519 515 520 516 #ifdef DEBUG 521 gMainThread = PR_GetCurrentThread();517 gMainThread = RTThreadSelf(); 522 518 #endif 523 519 return NS_OK; … … 538 534 { 539 535 // Must disconnect on same thread used to connect! 540 PR_ASSERT(gMainThread == PR_GetCurrentThread());536 Assert(gMainThread == RTThreadSelf()); 541 537 542 538 if (!gConnState || !gConnThread) 543 539 return NS_ERROR_NOT_INITIALIZED; 544 540 545 PR_Lock(gConnState->lock);541 RTCritSectEnter(&gConnState->CritSect); 546 542 gConnState->shutdown = PR_TRUE; 547 543 PR_SetPollableEvent(gConnState->fds[POLL].fd); 548 PR_Unlock(gConnState->lock); 549 550 PR_JoinThread(gConnThread); 544 RTCritSectLeave(&gConnState->CritSect); 545 546 int rcThread; 547 RTThreadWait(gConnThread, RT_INDEFINITE_WAIT, &rcThread); 548 AssertRC(rcThread); 551 549 552 550 ConnDestroy(gConnState); … … 563 561 return NS_ERROR_NOT_INITIALIZED; 564 562 565 PR_Lock(gConnState->lock);563 RTCritSectEnter(&gConnState->CritSect); 566 564 gConnState->send_queue.Append(msg); 567 565 PR_SetPollableEvent(gConnState->fds[POLL].fd); 568 PR_Unlock(gConnState->lock);566 RTCritSectLeave(&gConnState->CritSect); 569 567 570 568 return NS_OK; … … 583 581 callback->arg = arg; 584 582 585 PR_Lock(gConnState->lock);583 RTCritSectEnter(&gConnState->CritSect); 586 584 gConnState->callback_queue.Append(callback); 587 585 PR_SetPollableEvent(gConnState->fds[POLL].fd); 588 PR_Unlock(gConnState->lock);586 RTCritSectLeave(&gConnState->CritSect); 589 587 return NS_OK; 590 588 } 591 589 592 //-----------------------------------------------------------------------------593 594 #ifdef TEST_STANDALONE595 596 void IPC_OnConnectionFault(nsresult rv)597 {598 LOG(("IPC_OnConnectionFault [rv=%x]\n", rv));599 }600 601 void IPC_OnMessageAvailable(ipcMessage *msg)602 {603 LOG(("IPC_OnMessageAvailable\n"));604 delete msg;605 }606 607 int main()608 {609 IPC_InitLog(">>>");610 IPC_Connect("/builds/moz-trunk/seamonkey-debug-build/dist/bin/mozilla-ipcd");611 IPC_Disconnect();612 return 0;613 }614 615 #endif
Note:
See TracChangeset
for help on using the changeset viewer.