[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-hackers] [PATCH] disable SIGPIPE for sockets in iOS
From: |
Felix Winkelmann |
Subject: |
Re: [Chicken-hackers] [PATCH] disable SIGPIPE for sockets in iOS |
Date: |
Mon, 20 Jan 2014 16:28:46 +0100 (CET) |
Hi, again.
I modified the patch to apply to the current HEAD (well, I hope it does).
felix
>From 9ed4ee7642d23268c1f76b4235cd6485c47ed320 Mon Sep 17 00:00:00 2001
From: felix <address@hidden>
Date: Mon, 20 Jan 2014 16:22:08 +0100
Subject: [PATCH] iOS needs socket-option to prevent SIGPIPE.
Cleaned up patch to match latest HEAD.
Signed-off-by: felix <address@hidden>
---
tcp.scm | 29 ++++++++++++++++++++++++-----
1 file changed, 24 insertions(+), 5 deletions(-)
diff --git a/tcp.scm b/tcp.scm
index df31cda..a7fd4f5 100644
--- a/tcp.scm
+++ b/tcp.scm
@@ -116,6 +116,27 @@ static C_word make_socket_nonblocking (C_word sock) {
#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 SO_NOSIGPIPE
+ /*
+ * Avoid SIGPIPE (iOS uses *only* SIGPIPE otherwise, not returning EPIPE).
+ * For consistency we do this everywhere the option is supported.
+ */
+ r = setsockopt(socket, SOL_SOCKET, SO_NOSIGPIPE, (const char *)&yes,
sizeof(int));
+#endif
+
+ return r;
+}
+
EOF
) )
@@ -281,11 +302,7 @@ EOF
(when (eq? _invalid_socket s)
(##sys#error "cannot create socket") )
;; PLT makes this an optional arg to tcp-listen. Should we as well?
- (when (eq? _socket_error
- ((foreign-lambda* int ((int socket))
- "int yes = 1;
- C_return(setsockopt(socket, SOL_SOCKET, SO_REUSEADDR,
(const char *)&yes, sizeof(int)));")
- s) )
+ (when (eq? _socket_error ((foreign-lambda int "C_set_socket_options"
int) s) )
(network-error/close 'tcp-listen "error while setting up socket" s) )
(when (eq? _socket_error (##net#bind s addr _sockaddr_in_size))
(network-error/close 'tcp-listen "cannot bind to socket" s host port) )
@@ -573,6 +590,8 @@ EOF
(network-error 'tcp-connect "cannot create socket" host port) )
(unless (##core#inline "make_socket_nonblocking" s)
(network-error/close 'tcp-connect "fcntl() failed" s) )
+ (when (eq? _socket_error ((foreign-lambda int "C_set_socket_options"
int) s) )
+ (network-error/close 'tcp-connect "error while setting up socket" s) )
(let loop ()
(when (eq? _socket_error (##net#connect s addr _sockaddr_in_size))
(cond ((##net#in-progress?) ; Wait till it's available via select/poll
--
1.7.9.5
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [Chicken-hackers] [PATCH] disable SIGPIPE for sockets in iOS,
Felix Winkelmann <=