blob: 8b30d7278fce6e2794d76c9b7133eab0c3c35ecf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#if 0
%
% (c) The GRASP/AQUA Project, Glasgow University, 1995
%
\subsection[createSocket.lc]{Create a socket file descriptor}
\begin{code}
#endif
#define NON_POSIX_SOURCE
#include "Rts.h"
#include "ghcSockets.h"
#include "stgio.h"
StgInt
createSocket(I_ family, I_ type, I_ protocol)
{
int fd;
if ((fd = socket((int)family, (int)type, (int)protocol)) < 0) {
if (errno != EINTR) {
cvtErrno();
switch (ghc_errno) {
default:
stdErrno();
break;
case GHC_EACCES:
ghc_errtype = ERR_PERMISSIONDENIED;
ghc_errstr = "cannot create socket";
break;
case GHC_EMFILE:
ghc_errtype = ERR_RESOURCEEXHAUSTED;
ghc_errstr = "Too many open files";
break;
case GHC_ENFILE:
ghc_errtype = ERR_RESOURCEEXHAUSTED;
ghc_errstr = "System file table overflow";
break;
case GHC_EPROTONOSUPPORT:
ghc_errtype = ERR_UNSUPPORTEDOPERATION;
ghc_errstr = "Protocol type not supported";
break;
case GHC_EPROTOTYPE:
ghc_errtype = ERR_INAPPROPRIATETYPE;
ghc_errstr = "Protocol wrong type for socket";
break;
}
return (StgInt)-1;
}
}
return (StgInt)fd;
}
|