#include "ipv4.h"
#include "tcp.h"
+#define USE_SELECT 1
+
#define TCP_MIN_DYNPORT 0xC000
#define TCP_MAX_HALFOPEN 1024 // Should be enough
if(Header->Flags & TCP_FLAG_ACK) {
// TODO: Process an ACKed Packet
Log_Log("TCP", "Conn %p, Packet 0x%x ACKed", Connection, Header->AcknowlegementNumber);
+
+ // HACK
+ // TODO: Make sure that the packet is actually ACKing the FIN
+ if( Connection->State == TCP_ST_FIN_SENT ) {
+ Connection->State = TCP_ST_FINISHED;
+ return ;
+ }
}
// TODO: Check what to do here
}
RingBuffer_Write( Connection->RecievedBuffer, Pkt->Data, Pkt->Length );
+
+ #if USE_SELECT
+ VFS_MarkAvaliable(&Connection->Node, 1);
+ #endif
Mutex_Release( &Connection->lRecievedPackets );
}
// Poll packets
for(;;)
{
- // Lock list and check if there is a packet
+ // Wait
+ VFS_SelectNode(Node, VFS_SELECT_READ, NULL);
+ // Lock list and read
Mutex_Acquire( &conn->lRecievedPackets );
- if( conn->RecievedBuffer->Length == 0 ) {
- // If not, release the lock, yield and try again
- Mutex_Release( &conn->lRecievedPackets );
- Threads_Yield(); // TODO: Less expensive wait
- continue;
- }
// Attempt to read all `Length` bytes
len = RingBuffer_Read( destbuf, conn->RecievedBuffer, Length );
+ if( len == 0 || conn->RecievedBuffer->Length == 0 ) {
+ LOG("Marking as none avaliable (len = %i)\n", len);
+ VFS_MarkAvaliable(Node, 0);
+ }
+
// Release the lock (we don't need it any more)
Mutex_Release( &conn->lRecievedPackets );