summaryrefslogtreecommitdiff
path: root/ghc/lib/misc/cbits/sendTo.c
blob: 1abe017b28f022f729dd996d7aa622ae4cf5a2c1 (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
61
62
63
64
65
66
#if 0
%
% (c) The GRASP/AQUA Project, Glasgow University, 1998
%
\subsection[sendTo.c]{sendTo run-time support}

\begin{code}
#endif

#define NON_POSIX_SOURCE
#include "rtsdefs.h"
#include "ghcSockets.h"

StgInt
sendTo__(fd, buf, nbytes, to, sz)
StgInt fd;
StgAddr buf;
StgInt nbytes;
StgAddr to;
StgInt  sz;
{
  StgInt count;
  int flags = 0;

  while ( (count = sendto((int)fd, (void*)buf, (int)nbytes, flags, (struct sockaddr*)to, sz)) < 0) {
      if (errno != EINTR) {
	  cvtErrno();
	  switch (ghc_errno) {
	  case GHC_EBADF:
       	      ghc_errtype = ERR_INVALIDARGUMENT;
              ghc_errstr  = "Not a valid read descriptor";
	      break;
	  case GHC_EBADMSG:
       	      ghc_errtype = ERR_SYSTEMERROR;
              ghc_errstr  = "Message waiting to be read is not a data message";
	      break;
	  case GHC_EFAULT:
       	      ghc_errtype = ERR_INVALIDARGUMENT;
              ghc_errstr  = "Data buffer not in readable part of user address space";
	      break;
	  case GHC_EINVAL:
	      ghc_errtype = ERR_INVALIDARGUMENT;
	      ghc_errstr  = "Seek pointer associated with descriptor negative";
	      break;
	  case GHC_EIO:
	      ghc_errtype = ERR_SYSTEMERROR;
	      ghc_errstr  = "I/O error occurred while reading";
	      break;
	  case GHC_EISDIR:
	      ghc_errtype = ERR_INAPPROPRIATETYPE;
	      ghc_errstr  = "Descriptor refers to a directory";
	      break;
	  case GHC_EAGAIN:
	  case GHC_EWOULDBLOCK:
	      ghc_errtype = ERR_OTHERERROR;
	      ghc_errstr  = "No data could be read immediately";
	      break;
	  default:
	      stdErrno();
	      break;
	  }
	  return -1;
      }
    }
    return count;
}