+}
+
+VOID
+TCPAcceptEventHandler(void *arg, PTCP_PCB newpcb)
+{
+ PCONNECTION_ENDPOINT Connection = (PCONNECTION_ENDPOINT)arg;
+ PTDI_BUCKET Bucket;
+ PLIST_ENTRY Entry;
+ PIRP Irp;
+ NTSTATUS Status;
+ KIRQL OldIrql;
+
+ ReferenceObject(Connection);
+
+ while ((Entry = ExInterlockedRemoveHeadList(&Connection->ListenRequest, &Connection->Lock)))
+ {
+ PIO_STACK_LOCATION IrpSp;
+
+ Bucket = CONTAINING_RECORD( Entry, TDI_BUCKET, Entry );
+
+ Irp = Bucket->Request.RequestContext;
+ IrpSp = IoGetCurrentIrpStackLocation( Irp );
+
+ TI_DbgPrint(DEBUG_TCP,("[IP, TCPAcceptEventHandler] Getting the socket\n"));
+
+ Status = TCPCheckPeerForAccept(newpcb,
+ (PTDI_REQUEST_KERNEL)&IrpSp->Parameters);
+
+ TI_DbgPrint(DEBUG_TCP,("Socket: Status: %x\n", Status));
+
+ Bucket->Status = Status;
+ Bucket->Information = 0;
+
+ if (Status == STATUS_SUCCESS)
+ {
+ LockObject(Bucket->AssociatedEndpoint, &OldIrql);
+
+ /* sanity assert...this should never be in anything else but a CLOSED state */
+ ASSERT( ((PTCP_PCB)Bucket->AssociatedEndpoint->SocketContext)->state == CLOSED );
+
+ /* free socket context created in FileOpenConnection, as we're using a new one */
+ LibTCPClose(Bucket->AssociatedEndpoint, TRUE, FALSE);
+
+ /* free previously created socket context (we don't use it, we use newpcb) */
+ Bucket->AssociatedEndpoint->SocketContext = newpcb;
+
+ LibTCPAccept(newpcb, (PTCP_PCB)Connection->SocketContext, Bucket->AssociatedEndpoint);
+
+ UnlockObject(Bucket->AssociatedEndpoint, OldIrql);
+ }
+
+ DereferenceObject(Bucket->AssociatedEndpoint);
+
+ CompleteBucket(Connection, Bucket, FALSE);