This technique is used in fcl-net which should be cross-platform.
So I am right, when I say that also in Linux invald socket = -1
(in other words: in case of error syscall() returns always -1)

Becuase in other place I see another test "if socket < 0 then ..."
(which may mean that any negative value can be returned)

Most likely this is only because "socket < 0" is faster to write than "socket = -1" :-)

From Linux man page for socket:

RETURN VALUE
       On success, a file descriptor for the new socket is returned.  On
       error, -1 is returned, and errno is set appropriately.

Thanks for all repies.
For now I add to my unit:

{$IFDEF UNIX}
// not defined for POSIX; Linux syscall() returns -1 in case of error
const
  INVALID_SOCKET = -1;
  SOCKET_ERROR = -1;
{$ENDIF}

and later I use (in cross-platform code):
  Fsocket := fpsocket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  if Fsocket = INVALID_SOCKET then ...

-Laco.


_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to