+void TCP_int_FreeTCB(tTCPConnection *Connection)
+{
+ ASSERTC(Connection->State, ==, TCP_ST_FINISHED);
+ ASSERTC(Connection->Node.ReferenceCount, ==, 0);
+
+ if( Connection->Server )
+ {
+ tTCPListener *srv = Connection->Server;
+ SHORTLOCK(&srv->lConnections);
+ if(Connection->Prev)
+ Connection->Prev->Next = Connection->Next;
+ else
+ srv->Connections = Connection->Next;
+ if(Connection->Next)
+ Connection->Next->Prev = Connection->Prev;
+ else {
+ ASSERT(srv->ConnectionsTail == Connection);
+ srv->ConnectionsTail = Connection->Prev;
+ }
+ SHORTREL(&srv->lConnections);
+ }
+ else
+ {
+ SHORTLOCK(&glTCP_OutbountCons);
+ if(Connection->Prev)
+ Connection->Prev->Next = Connection->Next;
+ else
+ gTCP_OutbountCons = Connection->Next;
+ if(Connection->Next)
+ Connection->Next->Prev = Connection->Prev;
+ else
+ ;
+ SHORTREL(&glTCP_OutbountCons);
+ }
+
+ RingBuffer_Free(Connection->RecievedBuffer);
+ Time_FreeTimer(Connection->DeferredACKTimer);
+ // TODO: Force VFS to close handles? (they should all be closed);
+ free(Connection);
+}
+