Hello, I have a modified THttpServer called THttpMTServer. In thic component, there are worker threads which are pooled and connection objects (THttpMTConnection) which are also pooled. I have the following code called from ConnectionDataSent:
void __fastcall httpServerClientClass::ConnectionDataSent(TObject *Sender, WORD Error) { if(!FDocStream) return; if(DataSent >= DataToBeSent || Error) { this->Error = Error; endOfResponse(); return; } ... Now in endOfResponse(): void __fastcall httpServerClientClass::endOfResponse(void) { if(CGIISAPIInAction) { scheduledToDestroy = true; return; } if(responseEnded) return; responseEnded = true; ... if(FSessionClosedFlag) { if(pendingHeaderAvailable && availableDataBufferLen <= 2) { pendingHeaderAvailable = false; availableDataBufferLen = 0; availableDataBuffer.SetLength(0); } } else if(!KeepAlive || Error) Shutdown(1); } Also in OnClientDisconnected: void __fastcall httpServerThread::HTTPServerClientDisconnected(TObject *Sender, TObject *Client, WORD Error) { httpServerClientClass *clientObject = (httpServerClientClass*)Client; ... clientObject->Error = Error; clientObject->endOfResponse(); clientObject->beginDetach(); } //--------------------------------------------------------------------------- and in beginDetach(): void __fastcall httpServerClientClass::beginDetach(void) { if(CGIISAPIInAction) { scheduledToDestroy = true; return; } if(!detachBegan) { detachBegan = true; while(!PostThreadMessage(affinityThread->ThreadID, WM_HTTP_CLIENT_THREAD_DETACH, (WPARAM)this, 0)) ::Sleep(1); } } //--------------------------------------------------------------------------- For some reason sometimes with slow/WAN connections, when clients are remote, this code does not work and the client object is "hung", eventually filling the maximum number of connections. I have a strong feeling that under some circumstances, the OnClientDisconnected is not being called. Or maybe there is something else wrong. (BTW, the flags such as detachBegan are correctly reset after each THREAD_ATTACH.) BR, Gorkem -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be