+tTCPConnection *TCP_int_CreateConnection(tInterface *Interface, enum eTCPConnectionState State)
+{
+ tTCPConnection *conn = calloc( sizeof(tTCPConnection) + TCP_WINDOW_SIZE + TCP_WINDOW_SIZE/8, 1 );
+
+ conn->State = State;
+ conn->Interface = Interface;
+ conn->LocalPort = -1;
+ conn->RemotePort = -1;
+
+ conn->Node.ReferenceCount = 1;
+ conn->Node.ImplPtr = conn;
+ conn->Node.NumACLs = 1;
+ conn->Node.ACLs = &gVFS_ACL_EveryoneRW;
+ conn->Node.Type = &gTCP_ClientNodeType;
+ conn->Node.BufferFull = 1; // Cleared when connection opens
+
+ conn->RecievedBuffer = RingBuffer_Create( TCP_RECIEVE_BUFFER_SIZE );
+ #if 0
+ conn->SentBuffer = RingBuffer_Create( TCP_SEND_BUFFER_SIZE );
+ Semaphore_Init(conn->SentBufferSpace, 0, TCP_SEND_BUFFER_SIZE, "TCP SentBuffer", conn->Name);
+ #endif
+
+ #if CACHE_FUTURE_PACKETS_IN_BYTES
+ // Future recieved data (ahead of the expected sequence number)
+ conn->FuturePacketData = (Uint8*)conn + sizeof(tTCPConnection);
+ conn->FuturePacketValidBytes = conn->FuturePacketData + TCP_WINDOW_SIZE;
+ #endif
+
+ conn->DeferredACKTimer = Time_AllocateTimer( TCP_int_SendDelayedACK, conn);
+ return conn;
+}
+