[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Chicken-hackers] [PATCH] disable SIGPIPE for sockets in iOS
From: |
Felix |
Subject: |
[Chicken-hackers] [PATCH] disable SIGPIPE for sockets in iOS |
Date: |
Mon, 17 Jun 2013 08:51:01 +0200 (CEST) |
The attached patch disables SIGPIPE for sockets, which appears
to be an iOS-specific "Feature", and uses setsockopt(2) with the
Mac/BSD-specific SO_NOSIGPIPE option. Pipe-errors are then returned
as EPIPE in the usual fashion.
cheers,
felix
>From 0d3e84bb647dc8899af724df583b79c1e0f1b07e Mon Sep 17 00:00:00 2001
From: felix <address@hidden>
Date: Sun, 16 Jun 2013 00:05:45 +0200
Subject: [PATCH 1/4] iOS needs socket-option to prevent SIGPIPE.
---
tcp.scm | 23 +++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)
diff --git a/tcp.scm b/tcp.scm
index 7e37721..2c41814 100644
--- a/tcp.scm
+++ b/tcp.scm
@@ -83,6 +83,24 @@ static WSADATA wsa;
#endif
static char addr_buffer[ 20 ];
+
+static int C_set_socket_options(int socket)
+{
+ int yes = 1;
+ int r;
+
+ r = setsockopt(socket, SOL_SOCKET, SO_REUSEADDR, (const char *)&yes,
sizeof(int));
+
+ if(r != 0) return r;
+
+#ifdef __APPLE__
+ /* avoid SIGPIPE on iOS */
+ r = setsockopt(socket, SOL_SOCKET, SO_NOSIGPIPE, (const char *)&yes,
sizeof(int));
+#endif
+
+ return r;
+}
+
EOF
) )
@@ -244,10 +262,7 @@ EOF
(##sys#update-errno)
(##sys#error "cannot create socket") )
;; PLT makes this an optional arg to tcp-listen. Should we as well?
- (when (eq? -1 ((foreign-lambda* int ((int socket))
- "int yes = 1;
- C_return(setsockopt(socket, SOL_SOCKET, SO_REUSEADDR,
(const char *)&yes, sizeof(int)));")
- s) )
+ (when (eq? -1 ((foreign-lambda int "C_set_socket_options" int) s))
(network-error 'tcp-listen "error while setting up socket" s) )
(let ((addr (make-string _sockaddr_in_size)))
(if host
--
1.7.9.5
- [Chicken-hackers] [PATCH] disable SIGPIPE for sockets in iOS,
Felix <=