Move more socket code into socket.c
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
#include "peer.h"
|
#include "peer.h"
|
||||||
#include "proto.h"
|
#include "proto.h"
|
||||||
#include "raw.h"
|
#include "raw.h"
|
||||||
|
#include "socket.h"
|
||||||
#include "send.h"
|
#include "send.h"
|
||||||
#include "uuid.h"
|
#include "uuid.h"
|
||||||
|
|
||||||
@@ -132,8 +133,7 @@ void receive_cleanup() {
|
|||||||
void receive_new(int fd, void __attribute__((unused)) *passthrough, struct peer *on_close) {
|
void receive_new(int fd, void __attribute__((unused)) *passthrough, struct peer *on_close) {
|
||||||
peer_count_in++;
|
peer_count_in++;
|
||||||
|
|
||||||
int res = shutdown(fd, SHUT_WR);
|
socket_receive_init(fd);
|
||||||
assert(res == 0 || (res == -1 && errno == ENOTSOCK));
|
|
||||||
|
|
||||||
struct receive *receive = malloc(sizeof(*receive));
|
struct receive *receive = malloc(sizeof(*receive));
|
||||||
assert(receive);
|
assert(receive);
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include "peer.h"
|
#include "peer.h"
|
||||||
#include "proto.h"
|
#include "proto.h"
|
||||||
#include "raw.h"
|
#include "raw.h"
|
||||||
|
#include "socket.h"
|
||||||
#include "stats.h"
|
#include "stats.h"
|
||||||
#include "uuid.h"
|
#include "uuid.h"
|
||||||
|
|
||||||
@@ -114,8 +115,7 @@ struct serializer *send_get_serializer(char *name) {
|
|||||||
void send_new(int fd, struct serializer *serializer, struct peer *on_close) {
|
void send_new(int fd, struct serializer *serializer, struct peer *on_close) {
|
||||||
peer_count_out++;
|
peer_count_out++;
|
||||||
|
|
||||||
int res = shutdown(fd, SHUT_RD);
|
socket_send_init(fd);
|
||||||
assert(res == 0 || (res == -1 && errno == ENOTSOCK));
|
|
||||||
|
|
||||||
struct send *send = malloc(sizeof(*send));
|
struct send *send = malloc(sizeof(*send));
|
||||||
assert(send);
|
assert(send);
|
||||||
|
|||||||
@@ -8,16 +8,19 @@
|
|||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
|
|
||||||
void socket_pre_bind_init(int fd) {
|
void socket_pre_bind_init(int fd) {
|
||||||
|
// Called by transport code; safe to assume that fd is a socket
|
||||||
int optval = 1;
|
int optval = 1;
|
||||||
assert(!setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &optval, sizeof(optval)));
|
assert(!setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &optval, sizeof(optval)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void socket_bound_init(int fd) {
|
void socket_bound_init(int fd) {
|
||||||
|
// Called by transport code; safe to assume that fd is a socket
|
||||||
int qlen = 5;
|
int qlen = 5;
|
||||||
assert(!setsockopt(fd, SOL_TCP, TCP_FASTOPEN, &qlen, sizeof(qlen)));
|
assert(!setsockopt(fd, SOL_TCP, TCP_FASTOPEN, &qlen, sizeof(qlen)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void socket_connected_init(int fd) {
|
void socket_connected_init(int fd) {
|
||||||
|
// Called by transport code; safe to assume that fd is a socket
|
||||||
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;
|
||||||
@@ -27,3 +30,15 @@ void socket_connected_init(int fd) {
|
|||||||
optval = 3;
|
optval = 3;
|
||||||
assert(!setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &optval, sizeof(optval)));
|
assert(!setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &optval, sizeof(optval)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void socket_send_init(int fd) {
|
||||||
|
// Called by data flow code; NOT safe to assume that fd is a socket
|
||||||
|
int res = shutdown(fd, SHUT_RD);
|
||||||
|
assert(res == 0 || (res == -1 && errno == ENOTSOCK));
|
||||||
|
}
|
||||||
|
|
||||||
|
void socket_receive_init(int fd) {
|
||||||
|
// Called by data flow code; NOT safe to assume that fd is a socket
|
||||||
|
int res = shutdown(fd, SHUT_WR);
|
||||||
|
assert(res == 0 || (res == -1 && errno == ENOTSOCK));
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,3 +3,5 @@
|
|||||||
void socket_pre_bind_init(int);
|
void socket_pre_bind_init(int);
|
||||||
void socket_bound_init(int);
|
void socket_bound_init(int);
|
||||||
void socket_connected_init(int);
|
void socket_connected_init(int);
|
||||||
|
void socket_send_init(int);
|
||||||
|
void socket_receive_init(int);
|
||||||
|
|||||||
Reference in New Issue
Block a user