Re: [twsocket] Multiple OnDataAvailable calls when no data to read

2008-12-01 Thread Arno Garrels
Anton Sviridov wrote:

 1) What's the meainng of SendBinString in Server, it is never used?

It's never used.

 What for do you use PutDataInSendBuffer? 

It puts data into the send buffer without actually sending the data,
it's not required, however saves on internal call to socket.send.  

2) I see alot of code to
 implement a data buffer which imho does the same things that socket
 buffer do. 

It's similar, however needs less data copies, IMO. 

 Isn't it necessary to construct such sophisticated logic
 every time when data parsing is needed? Moreover (maybe I haven't
 detected) what do you do, if FRcvBuf is going to be filled? That is, 
 
 FRcvBuf: [_] [_] [_] [_] [D] [D] [D]
  |
 [_] - already parsed data
 [D] - data to be parsed
 - current pointer
 
 and there are some more bytes to be received, but buffer is over...
 I've found only one Move(), but it's located inside if FReceiveMode =
 rmLine section, but no copying is done when mode is binary.

In mode rmBinary OnBinaryReceived will trigger. Data move is left
to the component user. 

 
 3)  if FReceiveMode = rmLine then
begin
  ...
end;
 
if FReceiveMode  rmBinary then
Exit;
 
 strange construction, concerning that FReceiveMode could be only
 rmLine or rmBinary... maybe if..else ? 

It is because after TriggerLineReceived the receive mode may have 
changed to rmBinary and I did not want to call ParseReceiveBuffer
recursively after TriggerLineReceived, it could be optimized though.
 
 
 4)  while (Length(RcvdLine)  0) and
  (RcvdLine[Length(RcvdLine)] in [#13, #10]) do
RcvdLine := Copy(RcvdLine, 1, Length(RcvdLine) - 1);
 
while (Length(RcvdLine)  0) and
  (RcvdLine[Length(RcvdLine)] in [#13, #10]) do
SetLength(RcvdLine, Length(RcvdLine) - 1); ?
 

This code is from the (very old) TcpSrv demo which I did not
changed. 

BTW: I uploaded the BinCliDemo to the SVN repository last week with
a small fix in:

function FindCrLf(Buf: PAnsiChar; Count: Integer): Integer;
begin
for Result := 0 to Count - 1 do
begin
if (Buf[Result] = #13) and (Result + 1  Count) and
   (Buf[Result + 1] = #10) then
Exit;
end;
Result := -1;
end; 

--
Arno Garrels [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html
  

 --
 Best regards, Anton
-- 
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] Multiple OnDataAvailable calls when no data to read

2008-11-26 Thread Wilfried Mestdagh
Hello Anton,

 *embarrassed* how these two statements combine?
 Why several Receives should cause troubles?

it is by design, only 1 receive call in the event.

 And another question. Is TWSocket.RcvdCount value reliable, i.e. if
 it = 0, then there is really no data in the socket?

Microsoft reports that the RcvdCount is not always reliable. Even if
null then beste is to try to receive. See4 ReceiveStr as excmple.

---
Rgds, Wilfried [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html
http://www.mestdagh.biz

-- 
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] Multiple OnDataAvailable calls when no data to read

2008-11-25 Thread Wilfried Mestdagh
Hello Anton,

Don't worry. You don't have to do anything on the 'would block' winsock
error. TWSocket deals with it.

when OnDataAvailable fires, just try to receive all data. When Receive
return 0 or -1 then just exit the event handler.

-1 is error (don't worry), and 0 is if the peer has closed.

---
Rgds, Wilfried [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html
http://www.mestdagh.biz

Tuesday, November 25, 2008, 15:29, Anton Sviridov wrote:

 I'm now implementing a server on the base of TWSocketServer. In the
 client app I send some message to the server app, which receives it
 inside ServerIn_ClientDataAvailable procedure. Receiving is realized
 step by step to find a signature of message - i.e., there are several
 client.Receive in the method.
 I faced with strange thing: after whole message is read (and no
 data is sent yet), client's OnDataAvailable is executed some more
 times. TMsgReceiveSocket(Sender).RcvdCount returns 0, and Receive
 returns -1 with error code Would block. So the question: why
 OnDataAvailable is executed when there is actually no data to be read?

 --
 Best regards, Anton

-- 
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] Multiple OnDataAvailable calls when no data to read

2008-11-25 Thread Arno Garrels
Wilfried Mestdagh wrote:
 Hello Anton,
 
 Don't worry. You don't have to do anything on the 'would block'
 winsock error. TWSocket deals with it.
 
 when OnDataAvailable fires, just try to receive all data. When Receive
 return 0 or -1 then just exit the event handler.
 
 -1 is error (don't worry), and 0 is if the peer has closed.

As I understand the OP calls receive multiple times in OnDataAvailable
which is not a good idea.

--
Arno Garrels [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html


 
 ---
 Rgds, Wilfried [TeamICS]
 http://www.overbyte.be/eng/overbyte/teamics.html
 http://www.mestdagh.biz
 
 Tuesday, November 25, 2008, 15:29, Anton Sviridov wrote:
 
 I'm now implementing a server on the base of TWSocketServer. In the
 client app I send some message to the server app, which receives it
 inside ServerIn_ClientDataAvailable procedure. Receiving is realized
 step by step to find a signature of message - i.e., there are several
 client.Receive in the method.
 I faced with strange thing: after whole message is read (and no
 data is sent yet), client's OnDataAvailable is executed some more
 times. TMsgReceiveSocket(Sender).RcvdCount returns 0, and Receive
 returns -1 with error code Would block. So the question: why
 OnDataAvailable is executed when there is actually no data to be
 read? 
 
 --
 Best regards, Anton
-- 
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] Multiple OnDataAvailable calls when no data to read

2008-11-25 Thread Arno Garrels
Anton Sviridov wrote:
 Hello, Wilfried!
 You have calmed me :)
 
 Arno Garrels [TeamICS] wrote:
 As I understand the OP calls receive multiple times in
 OnDataAvailable which is not a good idea.
 
 So, each Recv launches one more OnDataAvail in the future? 

AFAIK no, only if you do not read all available data OnDataAvailable 
will trigger again.

 If so,
 can I easily read from socket block-by-block? Here's what i do for
 now: 

You should read from the socket once in OnDataAvailable.
OnDataAvailable will trigger again when new data is available or 
in case you did not read everything. ICS uses asynchron sockets which
requires messages being processed. Thus calling Receive multiple times
in a loop in on DataAvailable would not work properly.
 
--
Arno Garrels
-- 
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