[fpc-pascal] INVALID_SOCKET constant not defined for Linux

Marco van de Voort marcov at stack.nl
Tue Mar 28 11:52:39 CEST 2017

In our previous episode, LacaK said:
> I am porting application from Windows to Linux. I use Sockets unit.
> There is defined on Windows (and also on BeOS, FreeBSD, OS2):
>    INVALID_SOCKET = TSocket(Not 0); // or -1
>    SOCKET_ERROR = -1;
> But not for Linux. Does it means, that result of unsuccessfull call to 
> Sockets.FPSocket can be other than -1 ?
> (in fcl-net is used test for -1 to check invalid socket so I think, that 
> it is crossplatform ... if yes why isn't INVALID_SOCKET defined also for 
> Linux in RTL?)

Under *nix socket calls are just general runtime calls, and they use the
same convention and constants for errorhandling as all other calls.

Under Windows, the winsock part is separate from the C runtime and uses own
constants. Invalid_socket is a winsock constant added to sockets for
convenience (but not portable). Strictly speaking we could add a "platform;"
now to it.

I guess I did't want to encourage winsock (which is the odd one out) coding
in general *nix code.

More information about the fpc-pascal mailing list