// ACK Packet
Header->DestPort = Header->SourcePort;
Header->SourcePort = htons(Connection->LocalPort);
- Header->AcknowlegementNumber = htonl(Connection->NextSequenceRcv);
+ Header->AcknowlegementNumber = Header->SequenceNumber;
Header->SequenceNumber = htonl(Connection->NextSequenceSend);
Header->WindowSize = htons(TCP_WINDOW_SIZE);
Header->Flags = TCP_FLAG_ACK;
// Send ACK
Header->DestPort = Header->SourcePort;
Header->SourcePort = htons(Connection->LocalPort);
- Header->AcknowlegementNumber = htonl(Connection->NextSequenceRcv);
+ Header->AcknowlegementNumber = Header->SequenceNumber;
Header->SequenceNumber = htonl(Connection->NextSequenceSend);
Header->WindowSize = htons(TCP_WINDOW_SIZE);
Header->Flags = TCP_FLAG_ACK;
while( conn->State == TCP_ST_SYN_RCVD || conn->State == TCP_ST_SYN_SENT )
Threads_Yield();
- // If the conneciton is not nope, then clean out the recieved buffer
+ // If the conneciton is not open, then clean out the recieved buffer
if( conn->State != TCP_ST_OPEN )
{
Mutex_Acquire( &conn->lRecievedPackets );
}
// Wait
- VFS_SelectNode(Node, VFS_SELECT_READ, NULL, "TCP_Client_Read");
+ VFS_SelectNode(Node, VFS_SELECT_READ|VFS_SELECT_ERROR, NULL, "TCP_Client_Read");
// Lock list and read as much as possible (up to `Length`)
Mutex_Acquire( &conn->lRecievedPackets );
Conn->NextSequenceSend ++;
Conn->State = TCP_ST_SYN_SENT;
+
return ;
}
if(conn->RemotePort == -1)
LEAVE_RET('i', 0);
- TCP_StartConnection(conn);
+ {
+ tTime timeout_end = now() + conn->Interface->TimeoutDelay;
+
+ TCP_StartConnection(conn);
+ // TODO: Wait for connection to open
+ while( conn->State == TCP_ST_SYN_SENT && timeout_end > now() ) {
+ Threads_Yield();
+ }
+ if( conn->State == TCP_ST_SYN_SENT )
+ LEAVE_RET('i', 0);
+ }
+
LEAVE_RET('i', 1);
// Get recieve buffer length
packet.AcknowlegementNumber = 0;
packet.SequenceNumber = htonl(conn->NextSequenceSend);
- packet.Flags = TCP_FLAG_FIN|TCP_FLAG_ACK;
+ packet.Flags = TCP_FLAG_FIN;
TCP_SendPacket( conn, sizeof(tTCPHeader), &packet );
}
switch( conn->State )
{
case TCP_ST_CLOSE_WAIT:
- conn->State = TCP_ST_CLOSED;
+ conn->State = TCP_ST_LAST_ACK;
break;
case TCP_ST_OPEN:
conn->State = TCP_ST_FIN_WAIT1;