What is the proper way to handle TWSocket.DataAvailable?
I found this way in demo:
function TBinaryWSocket.TriggerDataAvailable(ErrCode: Word): Boolean;
Result := TRUE;
Rcvd := Receive(@FRcvBuf[FWriteOffs], (SizeOf(FRcvBuf) - FWriteOffs));
if Rcvd > 0 then
if FRemainingBytes > 0 then
while I previously used such way:
procedure SocketDataAvailable(Sender: TObject; ErrCode: Word);
if TWSocket(Sender).RcvdCount = 0 then Exit;
if ErrCode <> 0 then ; // do something
if FState in [csConnected, csRequesting, csReceivingInfo, csReceivingData]
else try FSocket.Receive(@ShitBuf, SizeOf(ShitBuf)) except end;
to check if there are data really available and to read everything from the
socket in case of closing state or something else.
Today I decided to get rid of RcvdCount checking like this:
procedure DoDataAvailable(Sender: TObject; ErrCode: Word);
if ErrCode <> 0 then
res := TWSocket(Sender).Receive(FCurrPtr, FDataNeeded);
if res < 0 then
Log('Error reading data: '+GetWinsockErr(WSocket_WSAGetLastError));
if FDataNeeded > 0 then Exit;
but I found that Receive returns -1 with WSAEWOULDBLOCK error when
DoDataAvailable is called with RcvdCount = 0.
So, the first question is: is it necessary to call method when no data
available in fact, and the second: how to implement DataAvailable code in
proper way? Is it possible for async Receive to returb some error besides
WSAEWOULDBLOCK (i.e. do I need to check the error and report about it)?
Thanks in advance.
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