Skip to content

Commit

Permalink
Minutiae:
Browse files Browse the repository at this point in the history
 - conn: no longer needs conn->server->config
 - docs: add flask to requirements. conn: add loop getter (TODO: venv..)
 - UTF8: corrected in the wrong direction
  • Loading branch information
andrew-canaday committed Jun 3, 2024
1 parent 4c65573 commit c2979e6
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 14 deletions.
1 change: 1 addition & 0 deletions doc/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions include/yimmo.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 12 additions & 6 deletions src/core/ymo_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include <openssl/err.h>
#endif /* YMO_ENABLE_TLS */

/* TODO: Connection shouldn't need server internals.. */
#include "yimmo.h"
#include "ymo_log.h"
#include "ymo_conn.h"
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -185,15 +191,15 @@ 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);
}


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);
}


Expand Down Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion src/core/ymo_conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion src/core/ymo_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <assert.h>

#if HAVE_DECL_SENDFILE
/* TODO: have most of these already: */
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/uio.h>
Expand Down
3 changes: 2 additions & 1 deletion src/core/ymo_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/ymo_test_proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/core/ymo_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit c2979e6

Please sign in to comment.