From b62b44e66c71b6cc602d3fff153c3001d8e4a91b Mon Sep 17 00:00:00 2001 From: sof Date: Tue, 11 Aug 1998 19:24:36 +0000 Subject: [PATCH] [project @ 1998-08-11 19:24:33 by sof] stubs for recvfrom() and sendto() --- ghc/lib/misc/cbits/ghcSockets.h | 6 ++++ ghc/lib/misc/cbits/readDescriptor.c | 14 ++++---- ghc/lib/misc/cbits/recvFrom.c | 68 +++++++++++++++++++++++++++++++++++ ghc/lib/misc/cbits/sendTo.c | 66 ++++++++++++++++++++++++++++++++++ 4 files changed, 147 insertions(+), 7 deletions(-) create mode 100644 ghc/lib/misc/cbits/recvFrom.c create mode 100644 ghc/lib/misc/cbits/sendTo.c diff --git a/ghc/lib/misc/cbits/ghcSockets.h b/ghc/lib/misc/cbits/ghcSockets.h index 5457aed..48654a2 100644 --- a/ghc/lib/misc/cbits/ghcSockets.h +++ b/ghc/lib/misc/cbits/ghcSockets.h @@ -70,6 +70,12 @@ StgInt shutdownSocket PROTO((StgInt, StgInt)); /* readDescriptor.lc */ StgInt readDescriptor PROTO((StgInt, StgAddr, StgInt)); +/* recvFrom.c */ +StgInt recvFrom__ PROTO((StgInt, StgAddr, StgInt, StgAddr)); + +/* sendTo.c */ +StgInt sendTo__ PROTO((StgInt, StgAddr, StgInt, StgAddr, StgInt)); + /* writeDescriptor.lc */ StgInt writeDescriptor PROTO((StgInt, StgAddr, StgInt)); diff --git a/ghc/lib/misc/cbits/readDescriptor.c b/ghc/lib/misc/cbits/readDescriptor.c index 21714bf..bef2ec9 100644 --- a/ghc/lib/misc/cbits/readDescriptor.c +++ b/ghc/lib/misc/cbits/readDescriptor.c @@ -20,12 +20,9 @@ readDescriptor(I_ fd, A_ buf, I_ nbytes) if (errno != EINTR) { cvtErrno(); switch (ghc_errno) { - default: - stdErrno(); - break; case GHC_EBADF: ghc_errtype = ERR_INVALIDARGUMENT; - ghc_errstr = "Not a valid write descriptor"; + ghc_errstr = "Not a valid read descriptor"; break; case GHC_EBADMSG: ghc_errtype = ERR_SYSTEMERROR; @@ -33,7 +30,7 @@ readDescriptor(I_ fd, A_ buf, I_ nbytes) break; case GHC_EFAULT: ghc_errtype = ERR_INVALIDARGUMENT; - ghc_errstr = "Data buffer not in writeable part of user address space"; + ghc_errstr = "Data buffer not in readable part of user address space"; break; case GHC_EINVAL: ghc_errtype = ERR_INVALIDARGUMENT; @@ -41,7 +38,7 @@ readDescriptor(I_ fd, A_ buf, I_ nbytes) break; case GHC_EIO: ghc_errtype = ERR_SYSTEMERROR; - ghc_errstr = "I/O error occurred while writing to file system"; + ghc_errstr = "I/O error occurred while reading"; break; case GHC_EISDIR: ghc_errtype = ERR_INAPPROPRIATETYPE; @@ -50,7 +47,10 @@ readDescriptor(I_ fd, A_ buf, I_ nbytes) case GHC_EAGAIN: case GHC_EWOULDBLOCK: ghc_errtype = ERR_OTHERERROR; - ghc_errstr = "No data could be written immediately"; + ghc_errstr = "No data could be read immediately"; + break; + default: + stdErrno(); break; } return -1; diff --git a/ghc/lib/misc/cbits/recvFrom.c b/ghc/lib/misc/cbits/recvFrom.c new file mode 100644 index 0000000..c1e10df --- /dev/null +++ b/ghc/lib/misc/cbits/recvFrom.c @@ -0,0 +1,68 @@ +#if 0 +% +% (c) The GRASP/AQUA Project, Glasgow University, 1998 +% +\subsection[recvFrom.lc]{recvFrom run-time support} + +\begin{code} +#endif + +#define NON_POSIX_SOURCE +#include "rtsdefs.h" +#include "ghcSockets.h" + +StgInt +recvFrom__(fd, buf, nbytes, from) +StgInt fd; +StgAddr buf; +StgInt nbytes; +StgAddr from; +{ + StgInt count; + int sz; + int flags = 0; + + sz = sizeof(struct sockaddr_in); + + while ( (count = recvfrom((int)fd, (void*)buf, (int)nbytes, flags, (struct sockaddr*)from, &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; +} diff --git a/ghc/lib/misc/cbits/sendTo.c b/ghc/lib/misc/cbits/sendTo.c new file mode 100644 index 0000000..1abe017 --- /dev/null +++ b/ghc/lib/misc/cbits/sendTo.c @@ -0,0 +1,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; +} -- 1.7.10.4