int32 FileDescriptorDataIO :: Write(const void * buffer, uint32 size) { int fd = _fd.GetFileDescriptor(); if (fd >= 0) { int w = write_ignore_eintr(fd, buffer, size); return _blocking ? w : ConvertReturnValueToMuscleSemantics(w, size, _blocking); } else return -1; }
int32 Thread :: WaitForNextMessageAux(ThreadSpecificData & tsd, MessageRef & ref, uint64 wakeupTime) { int32 ret = -1; // pessimistic default if (tsd._queueLock.Lock() == B_NO_ERROR) { if (tsd._messages.RemoveHead(ref) == B_NO_ERROR) ret = tsd._messages.GetNumItems(); (void) tsd._queueLock.Unlock(); int msgfd; if ((ret < 0)&&((msgfd = tsd._messageSocket.GetFileDescriptor()) >= 0)) // no Message available? then we'll have to wait until there is one! { // block until either // (a) a new-message-signal-byte wakes us, or // (b) we reach our wakeup/timeout time, or // (c) a user-specified socket in the socket set selects as ready-for-something for (uint32 i=0; i<ARRAYITEMS(tsd._socketSets); i++) { const Hashtable<ConstSocketRef, bool> & t = tsd._socketSets[i]; if (t.HasItems()) { for (HashtableIterator<ConstSocketRef, bool> iter(t, HTIT_FLAG_NOREGISTER); iter.HasData(); iter++) { int nextFD = iter.GetKey().GetFileDescriptor(); if (nextFD >= 0) tsd._multiplexer.RegisterSocketForEventsByTypeIndex(nextFD, i); } } } tsd._multiplexer.RegisterSocketForReadReady(msgfd); if (tsd._multiplexer.WaitForEvents(wakeupTime) >= 0) { for (uint32 j=0; j<ARRAYITEMS(tsd._socketSets); j++) { Hashtable<ConstSocketRef, bool> & t = tsd._socketSets[j]; if (t.HasItems()) for (HashtableIterator<ConstSocketRef, bool> iter(t, HTIT_FLAG_NOREGISTER); iter.HasData(); iter++) iter.GetValue() = tsd._multiplexer.IsSocketEventOfTypeFlagged(iter.GetKey().GetFileDescriptor(), j); } if (tsd._multiplexer.IsSocketReadyForRead(msgfd)) // any signals from the other thread? { uint8 bytes[256]; if (ConvertReturnValueToMuscleSemantics(recv_ignore_eintr(msgfd, (char *)bytes, sizeof(bytes), 0), sizeof(bytes), false) > 0) ret = WaitForNextMessageAux(tsd, ref, wakeupTime); } } } } return ret; }