3 % (c) The GRASP/AQUA Project, Glasgow University, 1996
5 \subsection[acceptSocket.lc]{Server wait for client to connect}
10 #define NON_POSIX_SOURCE
12 #include "ghcSockets.h"
16 acceptSocket(I_ sockfd, A_ peer, A_ addrlen)
21 while ((fd = accept((int)sockfd, (struct sockaddr *)peer, (int *)addrlen)) < 0) {
22 if (errno == EAGAIN) {
24 return FILEOBJ_BLOCKED_READ;
26 } else if (errno != EINTR) {
33 ghc_errtype = ERR_INVALIDARGUMENT;
34 ghc_errstr = "Not a valid descriptor";
37 ghc_errtype = ERR_INVALIDARGUMENT;
38 ghc_errstr = "Address not in writeable part of user address space";
41 ghc_errtype = ERR_INVALIDARGUMENT;
42 ghc_errstr = "Descriptor not a socket";
45 ghc_errtype = ERR_INVALIDARGUMENT;
46 ghc_errstr = "Socket not of type that supports listen";
49 ghc_errtype = ERR_OTHERERROR;
50 ghc_errstr = "No sockets are present to be accepted";
57 /* set the non-blocking flag on this file descriptor */
58 flags = fcntl(fd, F_GETFL);
59 fcntl(fd, F_SETFL, flags | O_NONBLOCK);