Re: [twsocket] Large amount of OnDataAvailable calls
Markus Humm wrote: > errors first. I don't even accept the connection if asoc is already > assigned and without it being in a thread it worked reliably. Given that property ListenBacklog is set to 0 it actually would work. Otherwise (default value of ListenBacklog is 5), after the first trigger of OnSessionAvailable that denies the connection attempt _without accepting it first, all subsequent connection attempts would hang around in the listenbacklog queue, and event OnSessionAvailable won't be triggered any more. As I already said, my change probably has nothing to do with your problem, it just sprang to my mind that there's a problem in your code. --- Arno Garrels [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html > > Greetings > > Markus -- 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
Re: [twsocket] Large amount of OnDataAvailable calls
Hello, > > procedure TServerSocket.MyOnSessionAvailable(Sender: TObject; > > ErrCode: Word); > > var news:TSocket; begin > > if not assigned(asoc) then > > begin > > try > > { We need to accept the client connection } > > NewS := self.Accept; > > > > { And then associate this connection with our client socket } > > asoc:=TAnswerSocket.Create(callback, OnClose); > > asoc.Dup(news); > > except > > On e:exception do > > begin > > // log a message > > end; > > end; > > end; > > end; > That probably does not explain why you cannot send data, but > what happens if asoc is already assigned? > I would write it something like: > procedure TServerSocket.MyOnSessionAvailable(Sender: TObject; ErrCode: > Word); > var news: TSocket; > begin > if ErrCode <> 0 then >Exit > { We need to accept the client connection } > NewS := self.Accept; > if not assigned(asoc) then > begin > { And then associate this connection with our client socket } > asoc :=TAnswerSocket.Create(callback, OnClose); > asoc.Dup(news); > end > else >WSocket_closesocket(NewS); // we are busy > end; Sorry, I don't see much improvement in your code except checking for errors first. I don't even accept the connection if asoc is already assigned and without it being in a thread it worked reliably. Greetings Markus -- 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
Re: [twsocket] Large amount of OnDataAvailable calls
Markus Humm wrote: > procedure TServerSocket.MyOnSessionAvailable(Sender: TObject; > ErrCode: Word); > var news:TSocket; begin > if not assigned(asoc) then > begin > try > { We need to accept the client connection } > NewS := self.Accept; > > { And then associate this connection with our client socket } > asoc:=TAnswerSocket.Create(callback, OnClose); > asoc.Dup(news); > except > On e:exception do > begin > // log a message > end; > end; > end; > end; That probably does not explain why you cannot send data, but what happens if asoc is already assigned? I would write it something like: procedure TServerSocket.MyOnSessionAvailable(Sender: TObject; ErrCode: Word); var news: TSocket; begin if ErrCode <> 0 then Exit { We need to accept the client connection } NewS := self.Accept; if not assigned(asoc) then begin { And then associate this connection with our client socket } asoc :=TAnswerSocket.Create(callback, OnClose); asoc.Dup(news); end else WSocket_closesocket(NewS); // we are busy end; --- Arno Garrels [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html > > Greetings > > Markus -- 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
Re: [twsocket] Large amount of OnDataAvailable calls
Hello, here's my OnSessionAvailable. I use TWSocket insteat of TWSocketServer because it already works and I don't want to change that part of my program. procedure TServerSocket.MyOnSessionAvailable(Sender: TObject; ErrCode: Word); var news:TSocket; begin if not assigned(asoc) then begin try { We need to accept the client connection } NewS := self.Accept; { And then associate this connection with our client socket } asoc:=TAnswerSocket.Create(callback, OnClose); asoc.Dup(news); except On e:exception do begin // log a message end; end; end; end; Greetings Markus -- 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
Re: [twsocket] Large amount of OnDataAvailable calls andtimer/frozen main thread
Markus Humm wrote: > Hello, > > I tried the direct calling of the timer without succes (I think some > of the affected VCL-components [like ListView and JvSimScope from > JEDI] need windows messages for their updating as well). > > I also tried the thread based approach but without success. If I pack > the ICS communication into a thread I can connect but the rest doesn't > work. The thread looks like this: Please show us some code from your OnSessionAvailable handler. Also have a look at OnSessionAvailable of TWSocketServer. > - create which sets FreeOnTerminate and starts the thread > - execute which sets up a TWSocket as TCP-Server with > multithreaded:=true > - in the OnSessionAvailable of that TWSocket another one is created > with multithreaded:=true as well and the connection is handed over Why don't you use TWSocketServer or a modified TWSocketServer? Makes life much easier. > (just reused the code which wasn't in the thread before and worked > before packing it in the thread, but with a bad resonding GUI) > - in the execute I have a loop like this after creating the > server socket: > > while not terminated do > begin > GetMessage(msg, 0, 0, 0); > > if msg.message = wm_mythreadquit then break; > > TranslateMessage(msg); > DispatchMessage(msg); > end; That's OK, but you should also check result of GetMessage() which would be FALSE in case of message WM_QUIT. > > - the thread has a overriden Terminate which > PostThreadMessage(self.threadid, wm_mythreadquit); > > Terminating the thread works well but all ICS communication > doesn't work. > > Sending calls via the socket are done from outside the > thread's context and are embedded in other threads, but I > don't get a crash, Socket exceptions are silent if the application is not run in the debugger and OnBgException is not assigned. --- Arno Garrels [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html > so that's no problem except it simply > doesn't send... > > What's wrong here? > > Greetings > > Markus -- 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
Re: [twsocket] Large amount of OnDataAvailable calls and timer/frozen main thread
Hello, I tried the direct calling of the timer without succes (I think some of the affected VCL-components [like ListView and JvSimScope from JEDI] need windows messages for their updating as well). I also tried the thread based approach but without success. If I pack the ICS communication into a thread I can connect but the rest doesn't work. The thread looks like this: - create which sets FreeOnTerminate and starts the thread - execute which sets up a TWSocket as TCP-Server with multithreaded:=true - in the OnSessionAvailable of that TWSocket another one is created with multithreaded:=true as well and the connection is handed over (just reused the code which wasn't in the thread before and worked before packing it in the thread, but with a bad resonding GUI) - in the execute I have a loop like this after creating the server socket: while not terminated do begin GetMessage(msg, 0, 0, 0); if msg.message = wm_mythreadquit then break; TranslateMessage(msg); DispatchMessage(msg); end; - the thread has a overriden Terminate which PostThreadMessage(self.threadid, wm_mythreadquit); Terminating the thread works well but all ICS communication doesn't work. Sending calls via the socket are done from outside the thread's context and are embedded in other threads, but I don't get a crash, so that's no problem except it simply doesn't send... What's wrong here? Greetings Markus -- 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
Re: [twsocket] Large amount of OnDataAvailable calls and timer/frozen main thread
> - if the client sends requests as a huge bulk > (e.g. 10.000 requests in a relatively [not completely] tight loop) > the statistics don't get updated for a while > - in OnDataAvailabe check whether at least 1 sec. has been elapsed > and the manually call OnTimer. I've done that, the OnTimer event sets a variable from GetTickCount each time it runs, and other events can check the timer event has been called recently and if not do so. I have a little library of Tick timer related functions including checking the 49 day wrap around. Wonder if 64-bit Windows has a GetTickCount64? But in your case, if OnData events are firing, OnTimer should as well? Angus -- 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
Re: [twsocket] Large amount of OnDataAvailable calls and timer/frozenmain thread
> I've come to 2 ideas: > > - set up a secondary thread for ICS (but I already have several > threads running... ;-)) That's OK. You may set the thread priority above normal level so that the network I/O doesn't catch all available CPU. It looks like you have a CPU bound case. > - in OnDataAvailabe check whether at least 1 sec. has been elapsed and > the manually call OnTimer. That's a possibility. You may also want to try wsoNoReceiveLoop in TWSocket.Options. -- Contribute to the SSL Effort. Visit http://www.overbyte.be/eng/ssl.html -- [EMAIL PROTECTED] http://www.overbyte.be - Original Message - From: "Markus Humm" <[EMAIL PROTECTED]> To: "ICS support mailing" Sent: Friday, October 27, 2006 5:35 PM Subject: [twsocket] Large amount of OnDataAvailable calls and timer/frozenmain thread > Hello, > > I've the following case: > > - VCL mainform with a timer which updates some statistics shown > once a second > - TWSocket as TCP-Server which gets requests from a client > - if the client sends requests as a huge bulk > (e.g. 10.000 requests in a relatively [not completely] tight loop) > the statistics don't get updated for a while > > I know that TTimer uses windows messages as well as ICS and now I'm > looking for a way to decouple my statistic update and the receiving of > data (CPU load get's to 100% in this worst case scenario). > > I've come to 2 ideas: > > - set up a secondary thread for ICS (but I already have several > threads running... ;-)) > - in OnDataAvailabe check whether at least 1 sec. has been elapsed and > the manually call OnTimer. > > I'd be especially fond of the second approach but like to know whether > this can work. (can't just try it since I'm not in the office right now) > > Greetings > > Markus > -- > 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 -- 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