f345fd6a9aca464fd357b183e712cbe4e1013bd7
[ghc-hetmet.git] / ghc / lib / misc / cbits / recvFrom.c
1 #if 0
2 %
3 % (c) The GRASP/AQUA Project, Glasgow University, 1998
4 %
5 \subsection[recvFrom.lc]{recvFrom run-time support}
6
7 \begin{code}
8 #endif
9
10 #define NON_POSIX_SOURCE
11 #include "rtsdefs.h"
12 #include "ghcSockets.h"
13
14 StgInt
15 recvFrom__(fd, buf, nbytes, from)
16 StgInt fd;
17 StgAddr buf;
18 StgInt nbytes;
19 StgAddr from;
20 {
21   StgInt count;
22   int sz;
23   int flags = 0;
24
25   sz = sizeof(struct sockaddr_in);
26
27   while ( (count = recvfrom((int)fd, (void*)buf, (int)nbytes, flags, (struct sockaddr*)from, &sz)) < 0) {
28       if (errno != EINTR) {
29           cvtErrno();
30           stdErrno();
31           return -1;
32       }
33   }
34   return count;
35 }