kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 7f11e37161d9feab56ed518d5364346ce8d564ff
parent edc356ca6039e50d33f29797f0d250d0ed33ddd3
Author: Joris Vink <joris@coders.se>
Date:   Wed, 22 Feb 2017 13:23:30 -0800

Add kore_sockopt().

Use it where we before were using setsockopt().

Diffstat:
includes/kore.h | 1+
src/connection.c | 4+---
src/kore.c | 21++++++++++++++++-----
3 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/includes/kore.h b/includes/kore.h @@ -519,6 +519,7 @@ void kore_timer_remove(struct kore_timer *); struct kore_timer *kore_timer_add(void (*cb)(void *, u_int64_t), u_int64_t, void *, int); +int kore_sockopt(int, int, int); void kore_listener_cleanup(void); int kore_server_bind(const char *, const char *, const char *); #if !defined(KORE_NO_TLS) diff --git a/src/connection.c b/src/connection.c @@ -418,9 +418,7 @@ kore_connection_nonblock(int fd, int nodelay) } if (nodelay) { - flags = 1; - if (setsockopt(fd, IPPROTO_TCP, - TCP_NODELAY, (char *)&flags, sizeof(flags)) == -1) { + if (!kore_sockopt(fd, IPPROTO_TCP, TCP_NODELAY)) { kore_log(LOG_NOTICE, "failed to set TCP_NODELAY on %d", fd); } diff --git a/src/kore.c b/src/kore.c @@ -283,8 +283,8 @@ kore_tls_info_callback(const SSL *ssl, int flags, int ret) int kore_server_bind(const char *ip, const char *port, const char *ccb) { + int r; struct listener *l; - int on, r; struct addrinfo hints, *results; kore_debug("kore_server_bind(%s, %s)", ip, port); @@ -320,13 +320,10 @@ kore_server_bind(const char *ip, const char *port, const char *ccb) return (KORE_RESULT_ERROR); } - on = 1; - if (setsockopt(l->fd, SOL_SOCKET, - SO_REUSEADDR, (const char *)&on, sizeof(on)) == -1) { + if (!kore_sockopt(l->fd, SOL_SOCKET, SO_REUSEADDR)) { close(l->fd); kore_free(l); freeaddrinfo(results); - kore_log(LOG_ERR, "setsockopt(): %s", errno_s); return (KORE_RESULT_ERROR); } @@ -372,6 +369,20 @@ kore_server_bind(const char *ip, const char *port, const char *ccb) return (KORE_RESULT_OK); } +int +kore_sockopt(int fd, int what, int opt) +{ + int on; + + on = 1; + if (setsockopt(fd, what, opt, (const char *)&on, sizeof(on)) == -1) { + kore_log(LOG_ERR, "setsockopt(): %s", errno_s); + return (KORE_RESULT_ERROR); + } + + return (KORE_RESULT_OK); +} + void kore_listener_cleanup(void) {