mirror of
				https://github.com/janet-lang/janet
				synced 2025-10-31 15:43:01 +00:00 
			
		
		
		
	Be aggressive with setting SO_NOSIGPIPE on BSD/Apple.
This commit is contained in:
		| @@ -139,6 +139,19 @@ static int janet_stream_close(void *p, size_t s) { | ||||
|     return 0; | ||||
| } | ||||
|  | ||||
|  | ||||
| static void nosigpipe(JSock s) { | ||||
| #ifdef SO_NOSIGPIPE | ||||
|     int enable = 1; | ||||
|     if (setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, &enable, sizeof(int)) < 0) { | ||||
|         JSOCKCLOSE(s); | ||||
|         janet_panic("setsockopt(SO_NOSIGPIPE) failed"); | ||||
|     } | ||||
| #else | ||||
|     (void) s; | ||||
| #endif | ||||
| } | ||||
|  | ||||
| /* | ||||
|  * Event loop | ||||
|  */ | ||||
| @@ -308,6 +321,7 @@ static size_t janet_loop_event(size_t index) { | ||||
|                 JSock connfd = accept(fd, NULL, NULL); | ||||
|                 if (JSOCKVALID(connfd)) { | ||||
|                     /* Made a new connection socket */ | ||||
|                     nosigpipe(connfd); | ||||
|                     JanetStream *stream = make_stream(connfd, JANET_STREAM_READABLE | JANET_STREAM_WRITABLE); | ||||
|                     Janet streamv = janet_wrap_abstract(stream); | ||||
|                     JanetFunction *handler = jlfd->data.read_accept.handler; | ||||
| @@ -497,18 +511,6 @@ static struct addrinfo *janet_get_addrinfo(Janet *argv, int32_t offset) { | ||||
|  * C Funs | ||||
|  */ | ||||
|  | ||||
| static void nosigpipe(JSock s) { | ||||
| #ifdef SO_NOSIGPIPE | ||||
|     int enable = 1; | ||||
|     if (setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, &enable, sizeof(int)) < 0) { | ||||
|         JSOCKCLOSE(s); | ||||
|         janet_panic("setsockopt(SO_NOSIGPIPE) failed"); | ||||
|     } | ||||
| #else | ||||
|     (void) s; | ||||
| #endif | ||||
| } | ||||
|  | ||||
| static Janet cfun_net_connect(int32_t argc, Janet *argv) { | ||||
|     janet_fixarity(argc, 2); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Calvin Rose
					Calvin Rose