Move more socket code into socket.c

This commit is contained in:
Ian Gulliver
2016-02-28 22:21:07 -08:00
parent 669b289e84
commit aa11eea121
4 changed files with 21 additions and 4 deletions

View File

@@ -8,16 +8,19 @@
#include "socket.h"
void socket_pre_bind_init(int fd) {
// Called by transport code; safe to assume that fd is a socket
int optval = 1;
assert(!setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &optval, sizeof(optval)));
}
void socket_bound_init(int fd) {
// Called by transport code; safe to assume that fd is a socket
int qlen = 5;
assert(!setsockopt(fd, SOL_TCP, TCP_FASTOPEN, &qlen, sizeof(qlen)));
}
void socket_connected_init(int fd) {
// Called by transport code; safe to assume that fd is a socket
int optval = 1;
assert(!setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof(optval)));
optval = 30;
@@ -27,3 +30,15 @@ void socket_connected_init(int fd) {
optval = 3;
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));
}