summaryrefslogtreecommitdiff
path: root/ghc/lib/misc/cbits/socketOpt.c
diff options
context:
space:
mode:
Diffstat (limited to 'ghc/lib/misc/cbits/socketOpt.c')
-rw-r--r--ghc/lib/misc/cbits/socketOpt.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/ghc/lib/misc/cbits/socketOpt.c b/ghc/lib/misc/cbits/socketOpt.c
new file mode 100644
index 0000000000..e8d5d843c1
--- /dev/null
+++ b/ghc/lib/misc/cbits/socketOpt.c
@@ -0,0 +1,63 @@
+#if 0
+%
+% (c) The GRASP/AQUA Project, Glasgow University, 1998
+%
+\subsection[socketOpt.lc]{Setting/Getting socket opts}
+
+\begin{code}
+#endif
+
+#define NON_POSIX_SOURCE
+#include "rtsdefs.h"
+#include "ghcSockets.h"
+
+StgInt
+getSocketOption__ (fd, opt)
+StgInt fd;
+StgInt opt;
+{
+ int level,optval, sz_optval,rc;
+
+ if ( opt == TCP_MAXSEG || opt == TCP_NODELAY ) {
+ level = IPPROTO_TCP;
+ } else {
+ level = SOL_SOCKET;
+ }
+
+ sz_optval = sizeof(int);
+
+ while ( (rc = getsockopt((int)fd, level, opt, &optval, &sz_optval)) < 0 ) {
+ if (errno != EINTR) {
+ cvtErrno();
+ stdErrno();
+ return -1;
+ }
+ }
+ return optval;
+}
+
+StgInt
+setSocketOption__ (fd, opt, val)
+StgInt fd;
+StgInt opt;
+StgInt val;
+{
+ int level, optval,rc;
+
+ if ( opt == TCP_MAXSEG || opt == TCP_NODELAY ) {
+ level = IPPROTO_TCP;
+ } else {
+ level = SOL_SOCKET;
+ }
+
+ optval = val;
+
+ while ( (rc = setsockopt((int)fd, level, opt, &optval, sizeof(optval))) < 0 ) {
+ if (errno != EINTR) {
+ cvtErrno();
+ stdErrno();
+ return -1;
+ }
+ }
+ return 0;
+}