Start of fastopen support.
This commit is contained in:
@@ -65,7 +65,7 @@ static void incoming_handler(struct peer *peer) {
|
|||||||
local_hbuf, local_sbuf,
|
local_hbuf, local_sbuf,
|
||||||
peer_hbuf, peer_sbuf);
|
peer_hbuf, peer_sbuf);
|
||||||
|
|
||||||
socket_init(fd);
|
socket_connected_init(fd);
|
||||||
|
|
||||||
incoming->handler(fd, incoming->passthrough, NULL);
|
incoming->handler(fd, incoming->passthrough, NULL);
|
||||||
}
|
}
|
||||||
@@ -99,6 +99,8 @@ static void incoming_listen(struct incoming *incoming) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
socket_bound_init(incoming->peer.fd);
|
||||||
|
|
||||||
assert(listen(incoming->peer.fd, 255) == 0);
|
assert(listen(incoming->peer.fd, 255) == 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,8 @@ static void outgoing_connect_next(struct outgoing *outgoing) {
|
|||||||
outgoing->peer.fd = socket(outgoing->addr->ai_family, outgoing->addr->ai_socktype | SOCK_NONBLOCK | SOCK_CLOEXEC, outgoing->addr->ai_protocol);
|
outgoing->peer.fd = socket(outgoing->addr->ai_family, outgoing->addr->ai_socktype | SOCK_NONBLOCK | SOCK_CLOEXEC, outgoing->addr->ai_protocol);
|
||||||
assert(outgoing->peer.fd >= 0);
|
assert(outgoing->peer.fd >= 0);
|
||||||
|
|
||||||
int result = connect(outgoing->peer.fd, outgoing->addr->ai_addr, outgoing->addr->ai_addrlen);
|
char buf[1];
|
||||||
|
int result = (int) sendto(outgoing->peer.fd, buf, 0, MSG_FASTOPEN, outgoing->addr->ai_addr, outgoing->addr->ai_addrlen);
|
||||||
outgoing_connect_result(outgoing, result == 0 ? result : errno);
|
outgoing_connect_result(outgoing, result == 0 ? result : errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +92,7 @@ static void outgoing_connect_result(struct outgoing *outgoing, int result) {
|
|||||||
case 0:
|
case 0:
|
||||||
fprintf(stderr, "O %s: Connected to %s/%s\n", outgoing->id, hbuf, sbuf);
|
fprintf(stderr, "O %s: Connected to %s/%s\n", outgoing->id, hbuf, sbuf);
|
||||||
freeaddrinfo(outgoing->addrs);
|
freeaddrinfo(outgoing->addrs);
|
||||||
socket_init(outgoing->peer.fd);
|
socket_connected_init(outgoing->peer.fd);
|
||||||
outgoing->attempt = 0;
|
outgoing->attempt = 0;
|
||||||
int fd = outgoing->peer.fd;
|
int fd = outgoing->peer.fd;
|
||||||
outgoing->peer.fd = -1;
|
outgoing->peer.fd = -1;
|
||||||
|
|||||||
@@ -7,7 +7,12 @@
|
|||||||
|
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
|
|
||||||
void socket_init(int fd) {
|
void socket_bound_init(int fd) {
|
||||||
|
int qlen = 5;
|
||||||
|
assert(!setsockopt(fd, SOL_TCP, TCP_FASTOPEN, &qlen, sizeof(qlen)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void socket_connected_init(int fd) {
|
||||||
int optval = 1;
|
int optval = 1;
|
||||||
assert(!setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof(optval)));
|
assert(!setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof(optval)));
|
||||||
optval = 30;
|
optval = 30;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
void socket_init(int);
|
void socket_bound_init(int);
|
||||||
|
void socket_connected_init(int);
|
||||||
|
|||||||
Reference in New Issue
Block a user