Re: [twsocket] Why is TWSocket.OnDataSent being called twice?
Doug Billi wrote: > I've heard a lot about IOCP > and wondered how much benefit (if any) such an implementation would > have over standard asynchronous sockets. I had thoughts, yes. I even wrote a little test server however speed didn't convince me. And of course, since IOCP is Windows only it would be not available on other platforms. -- Arno -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Why is TWSocket.OnDataSent being called twice?
Thanks for the clarification, I appreciate it. As a side note, I'm switching all of my code from Indy to ICS. The performance benefits are already paying off. What originally motivated the change was that the Indy code doesn't scale well at all. In just one example during my investigation, I found that the TCP client creates a separate hidden thread for each connection just for the timeout - I couldn't believe this is what the code was doing. The rate of thread creation/destruction just for this was crippling. Anyway, thanks to everyone on the ICS team for this alternative. I do have one question though, have there been any thoughts of providing an IOCP implementation of ICS? I've heard a lot about IOCP and wondered how much benefit (if any) such an implementation would have over standard asynchronous sockets. Thanks, Doug -Original Message- From: Arno Garrels [mailto:arno.garr...@gmx.de] Sent: Tuesday, November 06, 2012 10:35 PM To: ICS support mailing Subject: Re: [twsocket] Why is TWSocket.OnDataSent being called twice? Doug Billi wrote: > I've implemented a TWSocket client using a state machine, but after I > send the data using SendStr(), the OnDataSent() event gets fired > twice. That is normal behaviour. After a Connect two select messages are received from winsock, FD_Connect and FD_Write. The latter triggers DataSent. Then after a Send DataSent triggers again. -- Arno -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Why is TWSocket.OnDataSent being called twice?
Doug Billi wrote: > I've implemented a TWSocket client using a state machine, but after I > send the data using SendStr(), the OnDataSent() event gets fired > twice. That is normal behaviour. After a Connect two select messages are received from winsock, FD_Connect and FD_Write. The latter triggers DataSent. Then after a Send DataSent triggers again. -- Arno -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
[twsocket] Why is TWSocket.OnDataSent being called twice?
I've implemented a TWSocket client using a state machine, but after I send the data using SendStr(), the OnDataSent() event gets fired twice. I've confirmed that the data I'm sending is being put into a single buffer (it's 527 bytes), so I don't understand why the OnDataSent() method is being called twice. I've searched the ICS mailing list, but none of the posts I found so far answered this question specifically, other than to say that OnDataSent() is fired when the buffer is emptied, which is why I'm confused that I'd see it twice in this scenario (and I've confirmed with breakpoints that I'm only calling SendStr() once in the OnConnect event). Is this expected behavior? Thanks, Doug Pseudo code: procedure TMyClient.OnConnect(); begin FClientState := csSendingData; FSocket.SendStr(MyString); end; procedure TMyClient.OnDataSent(Sender: TObject; Error: Word); begin Assert(FClientState = csSendingData); <== FAILS HERE SECOND TIME (because FClientState was set to csWaitingForResponse the first time) * // buffered data has been sent, so wait for response FClientState := csWaitingForResponse; // set some other internal variables end; procedure TMyClient.OnDataAvailable(Sender: TObject; Error: Word); begin Assert(FClientState = csWaitingForResponse); MyReceivedData := FSocket.ReceiveStr; // do something with the data (e.g., post to a queue) end; procedure TMyClient.WaitUntilQuit; begin FSocket.MessageLoop; end; // pseudo code to initiate connection procedure DoSendRequest; var MyClient: TMyClient; begin MyClient := TMyClient.Create; MyClient.Connect; MyClient.WaitUntilQuit; end; -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be