[project @ 1996-06-27 16:13:29 by partain]
[ghc-hetmet.git] / ghc / runtime / io / listenSocket.lc
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1996
3 %
4 \subsection[listenSocket.lc]{Indicate willingness to receive connections}
5
6 \begin{code}
7
8 #include "rtsdefs.h"
9 #include "stgio.h"
10
11 #ifdef HAVE_SYS_TYPES_H
12 #include <sys/types.h>
13 #endif
14
15 #ifdef HAVE_SYS_SOCKET_H
16 #include <sys/socket.h>
17 #endif
18
19 StgInt
20 listenSocket(int sockfd, int backlog)
21 {
22     int rc;
23     
24     while ((rc = listen(sockfd, backlog)) < 0) {
25       if (errno != EINTR) {
26           cvtErrno();
27           switch (ghc_errno) {
28           default:
29               stdErrno();
30               break;
31           case GHC_EBADF:
32               ghc_errtype = ERR_INVALIDARGUMENT;
33               ghc_errstr  = "Not a valid descriptor";
34               break;
35           case GHC_ENOTSOCK:
36               ghc_errtype = ERR_INVALIDARGUMENT;
37               ghc_errstr  = "Descriptor not a socket";
38               break;
39           case GHC_EOPNOTSUPP:
40               ghc_errtype = ERR_INVALIDARGUMENT;
41               ghc_errstr  = "Socket not of type that supports listen";
42               break;
43           }
44           return -1;
45       }
46     }
47     return 0;
48 }
49
50 \end{code}