Re: [twsocket] Why is TWSocket.OnDataSent being called twice?

2012-11-07 Thread Arno Garrels
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


[twsocket] Why is TWSocket.OnDataSent being called twice?

2012-11-06 Thread Doug Billi
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


Re: [twsocket] Why is TWSocket.OnDataSent being called twice?

2012-11-06 Thread Arno Garrels
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