mirror of
https://github.com/janet-lang/janet
synced 2025-02-21 18:50:02 +00:00
Address issue #1558
Don't attempt SO_REUSEPORT on unix domain sockets since it doesn't make sense and may cause a failure to bind without extra effort by the programmer.
This commit is contained in:
parent
5f550ea5d4
commit
9a892363a3
@ -2283,7 +2283,7 @@
|
||||
(def rawget (if (= tx :struct) struct/rawget table/rawget))
|
||||
(var ret false)
|
||||
(eachp [k v] x
|
||||
(if (deep-not= (rawget y k) v) (break (set ret true))))
|
||||
(if (deep-not= (rawget y k) v) (break (set ret true))))
|
||||
ret))
|
||||
(= tx :buffer) (not= 0 (- (length x) (length y)) (memcmp x y))
|
||||
(not= x y))))
|
||||
|
@ -578,17 +578,21 @@ JANET_CORE_FN(cfun_net_connect,
|
||||
net_sched_connect(stream);
|
||||
}
|
||||
|
||||
static const char *serverify_socket(JSock sfd, int reuse) {
|
||||
static const char *serverify_socket(JSock sfd, int reuse_addr, int reuse_port) {
|
||||
/* Set various socket options */
|
||||
int enable = 1;
|
||||
if (reuse) {
|
||||
if (reuse_addr) {
|
||||
if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, (char *) &enable, sizeof(int)) < 0) {
|
||||
return "setsockopt(SO_REUSEADDR) failed";
|
||||
}
|
||||
}
|
||||
if (reuse_port) {
|
||||
#ifdef SO_REUSEPORT
|
||||
if (setsockopt(sfd, SOL_SOCKET, SO_REUSEPORT, &enable, sizeof(int)) < 0) {
|
||||
return "setsockopt(SO_REUSEPORT) failed";
|
||||
}
|
||||
#else
|
||||
(void) reuse_port;
|
||||
#endif
|
||||
}
|
||||
janet_net_socknoblock(sfd);
|
||||
@ -668,7 +672,7 @@ JANET_CORE_FN(cfun_net_listen,
|
||||
janet_free(ai);
|
||||
janet_panicf("could not create socket: %V", janet_ev_lasterr());
|
||||
}
|
||||
const char *err = serverify_socket(sfd, reuse);
|
||||
const char *err = serverify_socket(sfd, reuse, 0);
|
||||
if (NULL != err || bind(sfd, (struct sockaddr *)ai, sizeof(struct sockaddr_un))) {
|
||||
JSOCKCLOSE(sfd);
|
||||
janet_free(ai);
|
||||
@ -691,7 +695,7 @@ JANET_CORE_FN(cfun_net_listen,
|
||||
sfd = socket(rp->ai_family, rp->ai_socktype | JSOCKFLAGS, rp->ai_protocol);
|
||||
#endif
|
||||
if (!JSOCKVALID(sfd)) continue;
|
||||
const char *err = serverify_socket(sfd, reuse);
|
||||
const char *err = serverify_socket(sfd, reuse, reuse);
|
||||
if (NULL != err) {
|
||||
JSOCKCLOSE(sfd);
|
||||
continue;
|
||||
|
@ -484,4 +484,10 @@
|
||||
(pp :foo)))
|
||||
(ev/chan-close c)
|
||||
|
||||
# soreuseport on unix domain sockets
|
||||
(compwhen (= :linux (os/which))
|
||||
(assert-no-error "unix-domain socket reuseaddr"
|
||||
(let [s (net/listen :unix "./unix-domain-socket" :stream)]
|
||||
(:close s))))
|
||||
|
||||
(end-suite)
|
||||
|
Loading…
x
Reference in New Issue
Block a user