Al 20/10/10 18:28, En/na Lukas Gebauer ha escrit:
>> Sorry to revive this old thread, but this code isn't in trunk yet. Is
>> there a reason or was it simply forgotten?
>
> 1. It is forgotten. :-/

Don't worry, I could live without this feature working, but it's nice to 
have


> 2. It does not preserve block/nonblock mode, what was setted before
> connect call.

Well, this is easily solvable just by doing it only if the socket is in 
blocking mode (untested, it should also solve the next objection):

procedure TBlockSocket.Connect(IP, Port: string);
var
   Sin: TVarSin;
begin
   SetSin(Sin, IP, Port);
   if FLastError = 0 then
   begin
     if FSocket = INVALID_SOCKET then
       InternalCreateSocket(Sin);
     if (GetSocketType=SOCK_STREAM) and (FConnectionTimeout > 0) and not 
NonBlockMode then
     begin
       // connect in non-blocking mode
       NonBlockMode := true;
       SockCheck(synsock.Connect(FSocket, Sin));
       if (FLastError = WSAEINPROGRESS) OR (FLastError = WSAEWOULDBLOCK) 
then
         if not CanWrite(FConnectionTimeout) then
         begin
           FLastError := WSAETIMEDOUT;
           FLastErrorDesc := GetErrorDesc(FLastError);
         end;
       NonBlockMode := false;
     end else begin
       // connect in blocking mode
       SockCheck(synsock.Connect(FSocket, Sin));
       if FLastError = 0 then
         GetSins;
     end;
     FBuffer := '';
     FLastCR := False;
     FLastLF := False;
   end;
   ExceptCheck;
   DoStatus(HR_Connect, IP + ':' + Port);
end;



> 3. This code is reasonable for stream socket types. For datagrams
> not.

Isn't connect essentially a noop for udp? (the "connect" man page says 
that it just set the default address where packets will be sent, in fact 
these are connectionless sockets, so connect doesn't really connect).
Anyway, the above code does it only for tcp.

> 4. I am not sure, if nonblock mode is supported on various operating
> systems. (Synapse runs on many system other then Win and Linux...)

It could be ifdefed for windows only (in linux the normal timeout seems 
to work for connect, but it could be just a side effect).
Anyway, the connection made in nonblocking mode, then switching to 
blocking after that, is documented in the Unix socket FAQ 
http://developerweb.net/viewtopic.php?id=3196 so it should work also 
with other unices.

Bye
-- 
Luca

------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store 
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
synalist-public mailing list
synalist-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/synalist-public

Reply via email to