X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Modules%2FIPStack%2Ftcp.c;h=23d028c9de9f75f069acd85b5b373f0b922b406f;hb=fe2794b4f932c0755674493b6a6da4b60a5c2433;hp=f292ea866026a3dd7107fd945779355bc90df846;hpb=4dcdedff0ff1494189773c2d724f76a0291ca155;p=tpg%2Facess2.git diff --git a/Modules/IPStack/tcp.c b/Modules/IPStack/tcp.c index f292ea86..23d028c9 100644 --- a/Modules/IPStack/tcp.c +++ b/Modules/IPStack/tcp.c @@ -426,6 +426,10 @@ void TCP_INT_AppendRecieved(tTCPConnection *Connection, tTCPStoredPacket *Pkt) } RingBuffer_Write( Connection->RecievedBuffer, Pkt->Data, Pkt->Length ); + + #if USE_SELECT + VFS_MarkAvaliable(&Connection->Node, 1); + #endif Mutex_Release( &Connection->lRecievedPackets ); } @@ -763,6 +767,12 @@ Uint64 TCP_Client_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buff // Poll packets for(;;) { + #if USE_SELECT + // Wait + VFS_SelectNode(Node, VFS_SELECT_READ, NULL); + // Lock list and read + Mutex_Acquire( &conn->lRecievedPackets ); + #else // Lock list and check if there is a packet Mutex_Acquire( &conn->lRecievedPackets ); if( conn->RecievedBuffer->Length == 0 ) { @@ -771,10 +781,16 @@ Uint64 TCP_Client_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buff Threads_Yield(); // TODO: Less expensive wait continue; } + #endif // Attempt to read all `Length` bytes len = RingBuffer_Read( destbuf, conn->RecievedBuffer, Length ); + #if USE_SELECT + if( conn->RecievedBuffer->Length == 0 ) + VFS_MarkAvaliable(Node, 0); + #endif + // Release the lock (we don't need it any more) Mutex_Release( &conn->lRecievedPackets );