Changeset 58318 in vbox for trunk/src/VBox/Runtime/r3/posix/localipc-posix.cpp
- Timestamp:
- Oct 19, 2015 6:58:35 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/posix/localipc-posix.cpp
r58305 r58318 52 52 #endif 53 53 #include <fcntl.h> 54 #include <signal.h> 54 55 #include <unistd.h> 55 56 … … 232 233 { 233 234 RTSocketSetInheritance(pThis->hSocket, false /*fInheritable*/); 235 signal(SIGPIPE, SIG_IGN); /* Required on solaris, at least. */ 234 236 235 237 uint8_t cbAddr; … … 511 513 { 512 514 RTSocketSetInheritance(pThis->hSocket, false /*fInheritable*/); 515 signal(SIGPIPE, SIG_IGN); /* Required on solaris, at least. */ 513 516 514 517 struct sockaddr_un Addr; … … 690 693 RT_ZERO(PollFd); 691 694 PollFd.fd = RTSocketToNative(pThis->hSocket); 692 PollFd.events = POLLHUP; 693 return poll(&PollFd, 1, 0) >= 1 694 && (PollFd.revents & POLLHUP); 695 696 #else /* RT_OS_OS2: */ 697 return true; 698 #endif 695 PollFd.events = POLLHUP | POLLIN; 696 if (poll(&PollFd, 1, 0) > 0) 697 { 698 if (PollFd.revents & POLLIN) 699 { 700 # ifdef RT_OS_SOLARIS 701 /* Solaris doesn't seem to set POLLHUP for disconnected unix domain 702 sockets. So, we have to do extra stupid work here to detect it. */ 703 uint8_t bDummy; 704 ssize_t rcSend = send(PollFd.fd, &bDummy, 0, MSG_DONTWAIT); 705 if (rcSend < 0 && (errno == EPIPE || errno == ECONNRESET)) 706 return true; 707 AssertMsg(rcSend == 0, ("rcSend=%zd errno=%d\n", rcSend, errno)); 708 # endif 709 return false; 710 } 711 Assert(PollFd.revents != 0); 712 return true; 713 } 714 #else /* RT_OS_OS2 */ 715 /* No native poll, do zero byte send to check for EPIPE. */ 716 uint8_t bDummy; 717 ssize_t rcSend = send(PollFd.fd, &bDummy, 0, 0); 718 if (rcSend < 0 && (errno == EPIPE || errno == ECONNRESET)) 719 return true; 720 #endif /* RT_OS_OS2 */ 721 return false; 699 722 } 700 723 … … 942 965 uint32_t fEvents = 0; 943 966 #ifdef RT_OS_OS2 944 /* This doesn't give us any error condition on hangup . */967 /* This doesn't give us any error condition on hangup, so use HUP check. */ 945 968 Log(("RTLocalIpcSessionWaitForData: Calling RTSocketSelectOneEx...\n")); 946 969 rc = RTSocketSelectOneEx(pThis->hSocket, RTPOLL_EVT_READ | RTPOLL_EVT_ERROR, &fEvents, cMillies); 947 970 Log(("RTLocalIpcSessionWaitForData: RTSocketSelectOneEx returns %Rrc, fEvents=%#x\n", rc, fEvents)); 971 if (RT_SUCCESS(rc) && fEvents == RTPOLL_EVT_READ && rtLocalIpcPosixHasHup(pThis)) 972 rc = VERR_BROKEN_PIPE; 948 973 #else 949 /** @todo RTSocketPoll */974 /** @todo RTSocketPoll? */ 950 975 /* POLLHUP will be set on hangup. */ 951 976 struct pollfd PollFd; … … 957 982 if (cFds >= 1) 958 983 { 959 fEvents = PollFd.revents & (POLLHUP | POLLERR) ? RTPOLL_EVT_ERROR : RTPOLL_EVT_READ; 984 /* Solaris may flag both POLLIN and POLLHUP for pipes when there is more 985 input to read. Also, solaris may give us POLLIN without POLLHUP even 986 if a unix domain socket is already disconnected. So, extra solaris 987 hacks are necessary here in addition to prioritizing POLLIN. */ 988 if (PollFd.revents & POLLIN) 989 { 990 fEvents = RTPOLL_EVT_READ; 991 # ifdef RT_OS_SOLARIS /* Same hack as in rtLocalIpcPosixHasHup. */ 992 uint8_t bDummy; 993 ssize_t rcSend = send(PollFd.fd, &bDummy, 0, MSG_DONTWAIT); 994 if (rcSend < 0 && (errno == EPIPE || errno == ECONNRESET)) 995 fEvents = RTPOLL_EVT_ERROR; 996 else 997 AssertMsg(rcSend == 0, ("rcSend=%zd errno=%d\n", rcSend, errno)); 998 # endif 999 } 1000 else 1001 fEvents = RTPOLL_EVT_ERROR; 960 1002 rc = VINF_SUCCESS; 961 1003 }
Note:
See TracChangeset
for help on using the changeset viewer.