From c2979e695ae2b35bdfe454c4b5e6864b1b0d2acd Mon Sep 17 00:00:00 2001 From: andrew-canaday Date: Sun, 2 Jun 2024 20:27:31 -0400 Subject: [PATCH] Minutiae: - conn: no longer needs conn->server->config - docs: add flask to requirements. conn: add loop getter (TODO: venv..) - UTF8: corrected in the wrong direction --- doc/requirements.txt | 1 + include/yimmo.h.in | 7 +++++++ src/core/ymo_conn.c | 18 ++++++++++++------ src/core/ymo_conn.h | 3 ++- src/core/ymo_net.c | 1 - src/core/ymo_server.c | 3 ++- src/core/ymo_test_proto.h | 4 ++-- src/core/ymo_util.c | 6 +++--- 8 files changed, 29 insertions(+), 14 deletions(-) diff --git a/doc/requirements.txt b/doc/requirements.txt index 22ab9df..7d30d6c 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -10,3 +10,4 @@ sphinxcontrib-qthelp==1.0.3 sphinxcontrib-serializinghtml==1.1.5 sphinxcontrib-spelling==7.3.0 sphinxcontrib-websupport==1.2.4 +flask diff --git a/include/yimmo.h.in b/include/yimmo.h.in index 28f96ae..dc3141f 100644 --- a/include/yimmo.h.in +++ b/include/yimmo.h.in @@ -489,6 +489,13 @@ void ymo_server_free(ymo_server_t* server); */ ymo_server_t* ymo_conn_server(const ymo_conn_t* conn); +/** Given a connection, return a pointer to the managing ev_loop. + * + * :param conn: valid ymo_conn_t + * :returns: the struct ev_loop* used to manage the connection I/O + */ +struct ev_loop* ymo_conn_loop(const ymo_conn_t* conn); + /** Given a connection, return a pointer to the current protocol * * :param conn: valid ymo_conn_t diff --git a/src/core/ymo_conn.c b/src/core/ymo_conn.c index decd0a3..bbc2c5b 100644 --- a/src/core/ymo_conn.c +++ b/src/core/ymo_conn.c @@ -32,7 +32,6 @@ #include #endif /* YMO_ENABLE_TLS */ -/* TODO: Connection shouldn't need server internals.. */ #include "yimmo.h" #include "ymo_log.h" #include "ymo_conn.h" @@ -73,6 +72,12 @@ ymo_proto_t* ymo_conn_proto(const ymo_conn_t* conn) } +struct ev_loop* ymo_conn_loop(const ymo_conn_t* conn) +{ + return conn->loop; +} + + void ymo_conn_id(uuid_t dst, const ymo_conn_t* conn) { uuid_copy(dst, conn->id); @@ -90,13 +95,14 @@ char* ymo_conn_id_str(const ymo_conn_t* conn) ymo_conn_t* ymo_conn_create( ymo_server_t* server, ymo_proto_t* proto, int client_fd, - ymo_ev_io_cb_t read_cb, ymo_ev_io_cb_t write_cb) + struct ev_loop* loop, ymo_ev_io_cb_t read_cb, ymo_ev_io_cb_t write_cb) { ymo_conn_t* conn = NULL; conn = YMO_NEW(ymo_conn_t); if( conn ) { conn->proto = proto; conn->fd = client_fd; + conn->loop = loop; ev_io_init(&conn->w_read, read_cb, client_fd, EV_READ); ev_io_init(&conn->w_write, write_cb, client_fd, EV_WRITE); conn->w_read.data = conn->w_write.data = (void*)conn; @@ -185,7 +191,7 @@ void ymo_conn_rx_enable(ymo_conn_t* conn, int flag) CONN_TRACE("RX-->%i; State at invocation: %s (conn: %p, fd: %i)", flag, c_state_names[conn->state], (void*)conn, conn->fd); - io_toggle[flag & 0x01](conn->server->config.loop, &conn->w_read); + io_toggle[flag & 0x01](conn->loop, &conn->w_read); } @@ -193,7 +199,7 @@ void ymo_conn_tx_enable(ymo_conn_t* conn, int flag) { CONN_TRACE("TX-->%i; State at invocation: %s (conn: %p, fd: %i)", flag, c_state_names[conn->state], (void*)conn, conn->fd); - io_toggle[flag & 0x01](conn->server->config.loop, &conn->w_write); + io_toggle[flag & 0x01](conn->loop, &conn->w_write); } @@ -257,14 +263,14 @@ ymo_status_t ymo_conn_send_buckets( void ymo_conn_tx_now(ymo_conn_t* conn) { - ev_invoke(conn->server->config.loop, &conn->w_write, EV_WRITE); + ev_invoke(conn->loop, &conn->w_write, EV_WRITE); return; } void ymo_conn_rx_now(ymo_conn_t* conn) { - ev_invoke(conn->server->config.loop, &conn->w_read, EV_READ); + ev_invoke(conn->loop, &conn->w_read, EV_READ); return; } diff --git a/src/core/ymo_conn.h b/src/core/ymo_conn.h index 1adf6eb..8c4fe4c 100644 --- a/src/core/ymo_conn.h +++ b/src/core/ymo_conn.h @@ -79,6 +79,7 @@ struct ymo_conn { bsat_timeout_t idle_timeout; /* Used to disconnect idle sessions */ uuid_t id; /* Unique ID */ int fd; /* The underlying file descriptor */ + struct ev_loop* loop; /* EV loop that manages this connection. */ struct ev_io w_read; /* Per-connection read watcher */ struct ev_io w_write; /* Per-connection write watcher */ ymo_conn_state_t state; /* Connection state */ @@ -108,7 +109,7 @@ typedef void (*ymo_ev_io_cb_t)( */ ymo_conn_t* ymo_conn_create( ymo_server_t* server, ymo_proto_t* proto, int client_fd, - ymo_ev_io_cb_t read_cb, ymo_ev_io_cb_t write_cb); + struct ev_loop* loop, ymo_ev_io_cb_t read_cb, ymo_ev_io_cb_t write_cb); /** Start idle disconnect timer for a given conn. diff --git a/src/core/ymo_net.c b/src/core/ymo_net.c index f4a8f64..9412ca9 100644 --- a/src/core/ymo_net.c +++ b/src/core/ymo_net.c @@ -28,7 +28,6 @@ #include #if HAVE_DECL_SENDFILE -/* TODO: have most of these already: */ #include #include #include diff --git a/src/core/ymo_server.c b/src/core/ymo_server.c index aefb5df..cbdf8c3 100644 --- a/src/core/ymo_server.c +++ b/src/core/ymo_server.c @@ -582,7 +582,8 @@ static void ymo_conn_accept(ymo_server_t* server, int client_fd) ymo_conn_t* conn = NULL; conn = ymo_conn_create( - server, server->proto, client_fd, ymo_read_cb, ymo_write_cb); + server, server->proto, client_fd, + server->config.loop, ymo_read_cb, ymo_write_cb); /* Bail on connection create failure: */ if( !conn ) { diff --git a/src/core/ymo_test_proto.h b/src/core/ymo_test_proto.h index c4e9964..b33b79b 100644 --- a/src/core/ymo_test_proto.h +++ b/src/core/ymo_test_proto.h @@ -141,8 +141,8 @@ static ymo_test_conn_t* test_conn_create(ymo_test_server_t* test_server) ymo_sock_nonblocking(test_conn->fd_read); test_conn->conn = ymo_conn_create( - test_server->server, test_server->proto, - test_conn->fd_send, ymo_read_cb, ymo_write_cb); + test_server->server, test_server->proto, test_conn->fd_send, + test_server->server->config.loop, ymo_read_cb, ymo_write_cb); if( !test_conn->conn ) { YMO_FREE(test_conn); return NULL; diff --git a/src/core/ymo_util.c b/src/core/ymo_util.c index 0ac0e3b..bcfa2be 100644 --- a/src/core/ymo_util.c +++ b/src/core/ymo_util.c @@ -433,9 +433,9 @@ ymo_status_t ymo_check_utf8( * ON an alignment boundary) * - we could do 128, 256, or 512 bits at a time with SIMD */ - if( len >= 4 && ((quartet(c,p) & 0x80808080) == 0) ) { - len -= 4; - p += 4; + if( len >= 3 && ((quartet(c,p) & 0x80808080) == 0) ) { + len -= 3; + p += 3; continue; }