Browse Source

* Fixed TInetSocket.Connect error handling which got broken in r39199

git-svn-id: trunk@39533 -
joost 7 years ago
parent
commit
3c18e12cc7
1 changed files with 18 additions and 8 deletions
  1. 18 8
      packages/fcl-net/src/ssockets.pp

+ 18 - 8
packages/fcl-net/src/ssockets.pp

@@ -1045,7 +1045,9 @@ begin
        begin
        begin
          fpgetsockopt(ASocket, SOL_SOCKET, SO_ERROR, @Err, @ErrLen);
          fpgetsockopt(ASocket, SOL_SOCKET, SO_ERROR, @Err, @ErrLen);
          if Err <> 0 then // 0 -> connected
          if Err <> 0 then // 0 -> connected
-           Result := Err;
+           // We are not interested in the real error-code (ESysEAGAIN,
+           // ESysEINTR etc, which values are positive)
+           Result := -1;
        end;
        end;
      end;
      end;
   {$else}
   {$else}
@@ -1072,12 +1074,11 @@ Var
   A : THostAddr;
   A : THostAddr;
   addr: TInetSockAddr;
   addr: TInetSockAddr;
   Res : Integer;
   Res : Integer;
+  Err: Integer;
 {$IFDEF HAVENONBLOCKING}
 {$IFDEF HAVENONBLOCKING}
   FDS: TFDSet;
   FDS: TFDSet;
   TimeV: TTimeVal;
   TimeV: TTimeVal;
 {$endif}
 {$endif}
-
-
 begin
 begin
   A := StrToHostAddr(FHost);
   A := StrToHostAddr(FHost);
   if A.s_bytes[1] = 0 then
   if A.s_bytes[1] = 0 then
@@ -1097,16 +1098,25 @@ begin
     SetSocketBlockingMode(Handle, bmNonBlocking, @FDS) ;
     SetSocketBlockingMode(Handle, bmNonBlocking, @FDS) ;
 {$ENDIF}
 {$ENDIF}
   {$ifdef unix}
   {$ifdef unix}
-  Res:=ESysEINTR;
-    While (Res=ESysEINTR) do
+  Err:=ESysEINTR;
+  Res:=-1;
+  While (Res<0) and (Err in [ESysEINTR, ESysEAGAIN]) do
   {$endif}
   {$endif}
+    begin
       Res:=fpConnect(Handle, @addr, sizeof(addr));
       Res:=fpConnect(Handle, @addr, sizeof(addr));
+      {$ifdef unix}
+      if Res < 0 then
+        Err:=socketerror;
+      {$else}
+      Err:=Res;
+      {$endif}
+    end;
 {$IFDEF HAVENONBLOCKING}
 {$IFDEF HAVENONBLOCKING}
-  if (ConnectTimeOut>0) then
-      begin
+  if (Err=ESysEINPROGRESS) and (ConnectTimeOut>0) then
+    begin
       Res:=CheckSocketConnectTimeout(Handle, @FDS, @TimeV);
       Res:=CheckSocketConnectTimeout(Handle, @FDS, @TimeV);
       SetSocketBlockingMode(Handle, bmBlocking, @FDS);
       SetSocketBlockingMode(Handle, bmBlocking, @FDS);
-      end;
+    end;
 {$ENDIF}
 {$ENDIF}
   If Not (Res<0) then
   If Not (Res<0) then
     if not FHandler.Connect then
     if not FHandler.Connect then