Changeset 58295 in vbox
- Timestamp:
- Oct 18, 2015 1:28:34 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
-
include/iprt/localipc.h (modified) (3 diffs)
-
include/iprt/mangling.h (modified) (1 diff)
-
src/VBox/Runtime/r3/posix/localipc-posix.cpp (modified) (1 diff)
-
src/VBox/Runtime/r3/socket.cpp (modified) (2 diffs)
-
src/VBox/Runtime/testcase/tstRTLocalIpc.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/localipc.h
r58293 r58295 161 161 162 162 /** 163 * Receive pending data from the other end of an local IPC session. 164 * 165 * This will not block to wait for data. 166 * 167 * @returns IPRT status code. 168 * @retval VINF_TRY_AGAIN if no pending data (*pcbRead is set to 0). 169 * @retval VERR_CANCELLED if a previous operation was cancelled by 170 * RTLocalIpcSessionCancel (this operation isn't cancellable). 171 * 172 * @param hSession The session handle. 173 * @param pvBuf Where to store the data. 174 * @param cbToRead How much to read (upper limit). 175 * @param pcbRead Where to return exactly how much was read. 176 */ 177 RTDECL(int) RTLocalIpcSessionReadNB(RTLOCALIPCSESSION hSession, void *pvBuf, size_t cbToRead, size_t *pcbRead); 178 179 /** 163 180 * Send data to the other end of an local IPC session. 164 181 * … … 190 207 191 208 /** 192 * Wait for data to become ready for reading or for the 193 * session to bedisconnected.209 * Wait for data to become ready for reading or for the session to be 210 * disconnected. 194 211 * 195 212 * @returns IPRT status code. … … 212 229 * 213 230 * Not all methods are cancellable, only those which are specfied 214 * returning VERR_CANCELLED. The others are assumed to not be blocking 215 * for ever and ever. 231 * returning VERR_CANCELLED. The others are assumed to not be blocking 232 * for ever and ever. However, the cancel is sticky, so the session must 233 * basically be trashed (closed) after calling this method. 216 234 * 217 235 * @returns IPRT status code. -
trunk/include/iprt/mangling.h
r58285 r58295 742 742 # define RTLocalIpcSessionCancel RT_MANGLER(RTLocalIpcSessionCancel) 743 743 # define RTLocalIpcSessionRead RT_MANGLER(RTLocalIpcSessionRead) 744 # define RTLocalIpcSessionReadNB RT_MANGLER(RTLocalIpcSessionReadNB) 744 745 # define RTLocalIpcSessionWrite RT_MANGLER(RTLocalIpcSessionWrite) 745 746 # define RTLocalIpcSessionFlush RT_MANGLER(RTLocalIpcSessionFlush) -
trunk/src/VBox/Runtime/r3/posix/localipc-posix.cpp
r58294 r58295 727 727 728 728 729 RTDECL(int) RTLocalIpcSessionReadNB(RTLOCALIPCSESSION hSession, void *pvBuf, size_t cbToRead, size_t *pcbRead) 730 { 731 /* 732 * Validate input. 733 */ 734 PRTLOCALIPCSESSIONINT pThis = hSession; 735 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 736 AssertReturn(pThis->u32Magic == RTLOCALIPCSESSION_MAGIC, VERR_INVALID_HANDLE); 737 738 /* 739 * Do the job. 740 */ 741 rtLocalIpcSessionRetain(pThis); 742 743 int rc = RTCritSectEnter(&pThis->CritSect); 744 if (RT_SUCCESS(rc)) 745 { 746 if (pThis->hReadThread == NIL_RTTHREAD) 747 { 748 pThis->hReadThread = RTThreadSelf(); /* not really required, but whatever. */ 749 750 for (;;) 751 { 752 if (!pThis->fCancelled) 753 { 754 rc = RTSocketReadNB(pThis->hSocket, pvBuf, cbToRead, pcbRead); 755 756 /* Detect broken pipe. */ 757 if (rc == VINF_SUCCESS) 758 { 759 if (!pcbRead || *pcbRead) 760 { /* likely */ } 761 else if (rtLocalIpcPosixHasHup(pThis)) 762 rc = VERR_BROKEN_PIPE; 763 } 764 else if (rc == VERR_NET_CONNECTION_RESET_BY_PEER || rc == VERR_NET_SHUTDOWN) 765 rc = VERR_BROKEN_PIPE; 766 767 if (rc == VERR_INTERRUPTED) 768 continue; 769 } 770 else 771 rc = VERR_CANCELLED; 772 break; 773 } 774 775 pThis->hReadThread = NIL_RTTHREAD; 776 } 777 int rc2 = RTCritSectLeave(&pThis->CritSect); 778 AssertStmt(RT_SUCCESS(rc2), rc = RT_SUCCESS(rc) ? rc2 : rc); 779 } 780 781 rtLocalIpcSessionRelease(pThis); 782 return rc; 783 } 784 785 729 786 RTDECL(int) RTLocalIpcSessionWrite(RTLOCALIPCSESSION hSession, const void *pvBuf, size_t cbToWrite) 730 787 { -
trunk/src/VBox/Runtime/r3/socket.cpp
r58282 r58295 1220 1220 if (cbRead >= 0) 1221 1221 *pcbRead = cbRead; 1222 else if (errno == EAGAIN) 1222 else if ( errno == EAGAIN 1223 # ifdef EWOULDBLOCK 1224 || errno == EWOULDBLOCK 1225 # endif 1226 ) 1223 1227 { 1224 1228 *pcbRead = 0; … … 1272 1276 if (cbWritten >= 0) 1273 1277 *pcbWritten = cbWritten; 1274 else if (errno == EAGAIN) 1278 else if ( errno == EAGAIN 1279 # ifdef EWOULDBLOCK 1280 || errno == EWOULDBLOCK 1281 # endif 1282 ) 1275 1283 { 1276 1284 *pcbWritten = 0; -
trunk/src/VBox/Runtime/testcase/tstRTLocalIpc.cpp
r58291 r58295 92 92 RTTESTI_CHECK_RC_RETV(rc = RTLocalIpcSessionConnect(&hIpcSession, "BasicTest", 0), VERR_FILE_NOT_FOUND); 93 93 if (RT_SUCCESS(rc)) RTLocalIpcSessionClose(hIpcSession); 94 RTTESTI_CHECK_RC(RTLocalIpcServerCancel(hIpcServer), VERR_INVALID_HANDLE);95 RTTESTI_CHECK_RC(RTLocalIpcServerDestroy(hIpcServer), VERR_INVALID_HANDLE);94 //RTTESTI_CHECK_RC(RTLocalIpcServerCancel(hIpcServer), VERR_INVALID_HANDLE); - accessing freed memory, bad idea. 95 //RTTESTI_CHECK_RC(RTLocalIpcServerDestroy(hIpcServer), VERR_INVALID_HANDLE); - accessing freed memory, bad idea. 96 96 } 97 97 … … 273 273 RTTESTI_CHECK_RC(RTLocalIpcSessionWaitForData(hClientSession, 0 /*cMsTimeout*/), VERR_TIMEOUT); 274 274 RTTESTI_CHECK_RC(RTLocalIpcSessionWaitForData(hClientSession, 8 /*cMsTimeout*/), VERR_TIMEOUT); 275 uint8_t abBuf[4]; 276 size_t cbRead = _4M-1; 277 #ifndef RT_OS_WINDOWS 278 RTTESTI_CHECK_RC(RTLocalIpcSessionReadNB(hClientSession, abBuf, sizeof(abBuf), &cbRead), VINF_TRY_AGAIN); 279 RTTESTI_CHECK(cbRead == 0); 280 #endif 275 281 276 282 /* Trigger server disconnect. */ … … 291 297 292 298 RTTESTI_CHECK_RC(RTLocalIpcSessionWrite(hClientSession, RT_STR_TUPLE("broken")), VERR_BROKEN_PIPE); 293 uint8_t abBuf[4];294 299 RTTESTI_CHECK_RC(RTLocalIpcSessionRead(hClientSession, abBuf, sizeof(abBuf), NULL), VERR_BROKEN_PIPE); 295 size_tcbRead = _4M-1;300 cbRead = _4M-1; 296 301 RTTESTI_CHECK_RC(RTLocalIpcSessionRead(hClientSession, abBuf, sizeof(abBuf), &cbRead), VERR_BROKEN_PIPE); 302 #ifndef RT_OS_WINDOWS 303 cbRead = _1G/2; 304 RTTESTI_CHECK_RC(RTLocalIpcSessionReadNB(hClientSession, abBuf, sizeof(abBuf), &cbRead), VERR_BROKEN_PIPE); 305 #endif 297 306 298 307 RTAssertSetMayPanic(fMayPanic);
Note:
See TracChangeset
for help on using the changeset viewer.

