IPStack - Cleaning IPv4 code, implemented routing
[tpg/acess2.git] / Modules / IPStack / tcp.h
index 10a65ef..223805e 100644 (file)
@@ -67,7 +67,7 @@ struct sTCPListener
        tInterface      *Interface;     //!< Listening Interface
        tVFS_Node       Node;   //!< Server Directory node
         int    NextID;         //!< Name of the next connection
-       tSpinlock       lConnections;   //!< Spinlock for connections
+       tShortSpinlock  lConnections;   //!< Spinlock for connections
        tTCPConnection  *Connections;   //!< Connections (linked list)
        tTCPConnection  *volatile NewConnections;
        tTCPConnection  *ConnectionsTail;
@@ -81,10 +81,30 @@ struct sTCPStoredPacket
        Uint8   Data[];
 };
 
+enum eTCPConnectionState
+{
+       TCP_ST_CLOSED,          // 0 - Connection invalid
+       
+       TCP_ST_SYN_SENT,        // 1 - SYN sent by local, waiting for SYN-ACK
+       TCP_ST_SYN_RCVD,        // 2 - SYN recieved, SYN-ACK sent
+       
+       TCP_ST_OPEN,            // 3 - Connection open
+       
+       // Local Close
+       TCP_ST_FIN_WAIT1,       // 4 - FIN sent, waiting for reply (ACK or FIN)
+       TCP_ST_FIN_WAIT2,       // 5 - sent FIN acked, waiting for FIN from peer
+       TCP_ST_CLOSING,         // 6 - Waiting for ACK of FIN (FIN sent and recieved)
+       TCP_ST_TIME_WAIT,       // 7 - Waiting for timeout after local close
+       // Remote close
+       TCP_ST_CLOSE_WAIT,      // 8 - FIN recieved, waiting for user to close (error set, wait for node close)
+       TCP_ST_LAST_ACK,        // 9 - FIN sent and recieved, waiting for ACK
+       TCP_ST_FINISHED         // 10 - Essentially closed, all packets are invalid
+};
+
 struct sTCPConnection
 {
        struct sTCPConnection   *Next;
-        int    State;  //!< Connection state (see ::eTCPConnectionState)
+       enum eTCPConnectionState        State;  //!< Connection state (see ::eTCPConnectionState)
        Uint16  LocalPort;      //!< Local port
        Uint16  RemotePort;     //!< Remote port
        tInterface      *Interface;     //!< Listening Interface
@@ -98,7 +118,7 @@ struct sTCPConnection
         * \note FIFO list
         * \{
         */
-       tSpinlock       lQueuedPackets;
+       tMutex  lQueuedPackets;
        tTCPStoredPacket        *QueuedPackets; //!< Non-ACKed packets
        /**
         * \}
@@ -106,12 +126,11 @@ struct sTCPConnection
        
        /**
         * \brief Unread Packets
-        * \note Double ended list (fifo)
+        * \note Ring buffer
         * \{
         */
-       tSpinlock       lRecievedPackets;
-       tTCPStoredPacket        *RecievedPackets;       //!< Unread Packets
-       tTCPStoredPacket        *RecievedPacketsTail;   //!< Unread Packets (End of list)
+       tMutex  lRecievedPackets;
+       tRingBuffer     *RecievedBuffer;
        /**
         * \}
         */
@@ -121,7 +140,7 @@ struct sTCPConnection
         * \note Sorted list to improve times
         * \{
         */
-       tSpinlock       lFuturePackets; //!< Future packets spinlock
+       tShortSpinlock  lFuturePackets; //!< Future packets spinlock
        tTCPStoredPacket        *FuturePackets; //!< Out of sequence packets
        /**
         * \}
@@ -134,11 +153,4 @@ struct sTCPConnection
        // Type is determined by LocalInterface->Type
 };
 
-enum eTCPConnectionState
-{
-       TCP_ST_CLOSED,
-       TCP_ST_HALFOPEN,
-       TCP_ST_OPEN
-};
-
 #endif

UCC git Repository :: git.ucc.asn.au