3 % (c) The GRASP/AQUA Project, Glasgow University, 1995
5 \subsection[createSocket.lc]{Create a socket file descriptor}
10 #define NON_POSIX_SOURCE
12 #include "ghcSockets.h"
16 createSocket(I_ family, I_ type, I_ protocol)
21 if ((fd = socket((int)family, (int)type, (int)protocol)) < 0) {
29 ghc_errtype = ERR_PERMISSIONDENIED;
30 ghc_errstr = "cannot create socket";
33 ghc_errtype = ERR_RESOURCEEXHAUSTED;
34 ghc_errstr = "Too many open files";
37 ghc_errtype = ERR_RESOURCEEXHAUSTED;
38 ghc_errstr = "System file table overflow";
40 case GHC_EPROTONOSUPPORT:
41 ghc_errtype = ERR_UNSUPPORTEDOPERATION;
42 ghc_errstr = "Protocol type not supported";
45 ghc_errtype = ERR_INAPPROPRIATETYPE;
46 ghc_errstr = "Protocol wrong type for socket";
53 /* set the non-blocking flag on this file descriptor */
54 flags = fcntl(fd, F_GETFL);
55 fcntl(fd, F_SETFL, flags | O_NONBLOCK);