tMutex lList;
tIPCPipe_Packet *OutHead;
tIPCPipe_Packet *OutTail;
+ size_t ByteCount;
tVFS_Node Node;
};
struct sIPCPipe_Channel
tIPCPipe_Server *Prev;
char *Name;
size_t MaxBlockSize; // Max size of a 'packet'
- size_t QueueByteLimit; // Maximum number of bytes held in kernel for this server
- size_t CurrentByteCount;
+ // NOTE: Not strictly enforced, can go MaxBlockSize-1 over
+ size_t QueueByteLimit; // Maximum number of bytes held in kernel for each endpoint
tVFS_Node ServerNode;
tRWLock lChannelList;
tIPCPipe_Channel *FirstClient;
// Wait for a packet to be ready
tTime timeout_z = 0, *timeout = ((Flags & VFS_IOFLAG_NOBLOCK) ? &timeout_z : NULL);
- int rv = VFS_SelectNode(Node, VFS_SELECT_READ, timeout, "IPCPipe Endpoint");
+ int rv = VFS_SelectNode(Node, VFS_SELECT_READ|VFS_SELECT_ERROR, timeout, "IPCPipe Endpoint");
if( !rv ) {
errno = (Flags & VFS_IOFLAG_NOBLOCK) ? EWOULDBLOCK : EINTR;
LEAVE('i', -1);
return -1;
}
- if( channel->Server == NULL ) {
+ if( (rv & VFS_SELECT_ERROR) || channel->Server == NULL ) {
//errno = EIO;
LEAVE('i', -1);
return -1;
if(!rep->OutHead)
rep->OutTail = NULL;
VFS_MarkAvaliable(Node, !!rep->OutHead);
+ VFS_MarkFull(&rep->Node, 0); // Just read a packet, remote shouldn't be full
Mutex_Release(&rep->lList);
// Return
}
else
{
- Log_Warning("IPCPipe", "No packet ready but semaphore returned");
+ Log_Warning("IPCPipe", "No packet ready but select returned");
}
LEAVE('i', ret);
LEAVE('i', 0);
return 0;
}
-
- // TODO: Ensure that no more than DEF_MAX_BYTE_LIMIT bytes are in flight at one time
+
+ // Wait for a packet to be ready
+ tTime timeout_z = 0, *timeout = ((Flags & VFS_IOFLAG_NOBLOCK) ? &timeout_z : NULL);
+ int rv = VFS_SelectNode(Node, VFS_SELECT_WRITE|VFS_SELECT_ERROR, timeout, "IPCPipe Endpoint");
+ ASSERTC(rv, >=, 0);
+ if( !rv ) {
+ errno = (Flags & VFS_IOFLAG_NOBLOCK) ? EWOULDBLOCK : EINTR;
+ LEAVE('i', -1);
+ return -1;
+ }
+ if( (rv & VFS_SELECT_ERROR) || channel->Server == NULL ) {
+ //errno = EIO;
+ LEAVE('i', -1);
+ return -1;
+ }
// Create packet structure
tIPCPipe_Packet *pkt = malloc(sizeof(tIPCPipe_Packet)+Length);
else
lep->OutHead = pkt;
lep->OutTail = pkt;
+
+ lep->ByteCount += Length;
+ if( lep->ByteCount >= channel->Server->QueueByteLimit ) {
+ VFS_MarkFull(Node, 1);
+ }
+
Mutex_Release(&lep->lList);
// Signal other end