blob: 9a8ccaa1cc112ce7522aae5c0c17d8cfaf51bb68 (
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
53
54
55
56
57
58
59
60
|
#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;
long flags;
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;
}
}
/* set the non-blocking flag on this file descriptor */
#if !defined(_WIN32) || defined(__CYGWIN__) || defined(__CYGWIN32__)
flags = fcntl(fd, F_GETFL);
fcntl(fd, F_SETFL, flags | O_NONBLOCK);
#endif
return (StgInt)fd;
}
|