[project @ 1998-12-02 13:17:09 by simonm]
[ghc-hetmet.git] / ghc / lib / misc / cbits / acceptSocket.c
index 1ded2d6..efd13b9 100644 (file)
@@ -8,8 +8,9 @@
 #endif
 
 #define NON_POSIX_SOURCE
-#include "rtsdefs.h"
+#include "Rts.h"
 #include "ghcSockets.h"
+#include "stgio.h"
 
 StgInt
 acceptSocket(I_ sockfd, A_ peer, A_ addrlen)
@@ -19,7 +20,31 @@ acceptSocket(I_ sockfd, A_ peer, A_ addrlen)
     while ((fd = accept((int)sockfd, (struct sockaddr *)peer, (int *)addrlen)) < 0) {
       if (errno != EINTR) {
          cvtErrno();
-         stdErrno();
+         switch (ghc_errno) {
+         default:
+             stdErrno();
+             break;
+         case GHC_EBADF:
+                     ghc_errtype = ERR_INVALIDARGUMENT;
+              ghc_errstr  = "Not a valid descriptor";
+             break;
+         case GHC_EFAULT:
+                     ghc_errtype = ERR_INVALIDARGUMENT;
+              ghc_errstr  = "Address not in writeable part of user address space";
+             break;
+         case GHC_ENOTSOCK:
+             ghc_errtype = ERR_INVALIDARGUMENT;
+             ghc_errstr  = "Descriptor not a socket";
+             break;
+         case GHC_EOPNOTSUPP:
+             ghc_errtype = ERR_INVALIDARGUMENT;
+             ghc_errstr  = "Socket not of type that supports listen";
+             break;
+         case GHC_EWOULDBLOCK:
+             ghc_errtype = ERR_OTHERERROR;
+             ghc_errstr  = "No sockets are present to be accepted";
+             break;
+         }
          return -1;
       }
     }