[project @ 1996-06-27 16:13:29 by partain]
[ghc-hetmet.git] / ghc / runtime / io / shutdownSocket.lc
diff --git a/ghc/runtime/io/shutdownSocket.lc b/ghc/runtime/io/shutdownSocket.lc
new file mode 100644 (file)
index 0000000..96edb9f
--- /dev/null
@@ -0,0 +1,42 @@
+%
+% (c) The GRASP/AQUA Project, Glasgow University, 1996
+%
+\subsection[shutdownSocket.lc]{Shut down part of full duplex connection}
+
+\begin{code}
+
+#include "rtsdefs.h"
+#include "stgio.h"
+
+StgInt
+shutdownSocket(int sockfd, int how)
+{
+    StgInt rc;
+    
+    while ((rc = shutdown(sockfd, how)) < 0) {
+      if (errno != EINTR) {
+         cvtErrno();
+         switch (ghc_errno) {
+         default:
+             stdErrno();
+             break;
+         case GHC_EBADF:
+                     ghc_errtype = ERR_INVALIDARGUMENT;
+              ghc_errstr  = "Not a valid write descriptor";
+             break;
+         case GHC_ENOTCONN:
+             ghc_errtype = ERR_INVALIDARGUMENT;
+             ghc_errstr  = "Socket not connected";
+             break;
+         case GHC_ENOTSOCK:
+             ghc_errtype = ERR_INVALIDARGUMENT;
+             ghc_errstr  = "Descriptor is not a socket";
+             break;
+         }
+         return -1;
+      }
+    }
+    return rc;
+}
+
+\end{code}