[project @ 1998-12-02 13:17:09 by simonm]
[ghc-hetmet.git] / ghc / lib / misc / cbits / createSocket.c
index 31e91b8..8b30d72 100644 (file)
@@ -8,8 +8,9 @@
 #endif
 
 #define NON_POSIX_SOURCE
-#include "rtsdefs.h"
+#include "Rts.h"
 #include "ghcSockets.h"
+#include "stgio.h"
 
 StgInt
 createSocket(I_ family, I_ type, I_ protocol)
@@ -19,9 +20,33 @@ createSocket(I_ family, I_ type, I_ protocol)
     if ((fd = socket((int)family, (int)type, (int)protocol)) < 0) {
       if (errno != EINTR) {
          cvtErrno();
-         stdErrno();
-         return -1;
+         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;
       }
     }
-    return fd;
+    return (StgInt)fd;
 }