Connections

Types

struct ymo_conn

Internal structure used to manage a yimmo conn.

Definition
struct ymo_conn {
    ymo_server_t*     server;          /* Pointer to managing server */
    ymo_proto_t*      proto;           /* Current protocol managing this connection */
    void*             proto_data;      /* Protocol-specific connection data */
    void*             user;            /* User-code per-connection data */
    bsat_toq_t*       toq;             /* HACK HACK: fix cancel for now. */
    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 */
#if YMO_ENABLE_TLS
    SSL*              ssl;             /* Optional SSL connection info */
#endif /* YMO_ENABLE_TLS */
#if defined(YMO_CONN_LOCK) && (YMO_CONN_LOCK == 1)
    pthread_mutexattr_t  lattr;        /* Per-connection mutex attributes */
    pthread_mutex_t      lock;         /* Per-connection mutex */
#endif /* YMO_CONN_LOCK */
};
type ymo_ev_io_cb_t

We typedef the callback signature for ev_io_watcher’s, purely as a matter of convenience.

Definition
typedef void (*ymo_ev_io_cb_t)(
        struct ev_loop* loop,
        struct ev_io* watcher,
        int revents);
ymo_conn_t *ymo_conn_create(ymo_server_t *server, ymo_proto_t *proto, int client_fd, struct ev_loop *loop, ymo_ev_io_cb_t read_cb, ymo_ev_io_cb_t write_cb)

Create a new conn object.

void ymo_conn_start_idle_timeout(ymo_conn_t *conn, bsat_toq_t *idle_toq)

Start idle disconnect timer for a given conn.

void ymo_conn_reset_idle_timeout(ymo_conn_t *conn, bsat_toq_t *idle_toq)

Reset idle disconnect timer for a given conn.

void ymo_conn_cancel_idle_timeout(ymo_conn_t *conn)

Cancel idle disconnect timer for a given conn.

ymo_status_t ymo_conn_transition_proto(ymo_conn_t *conn, ymo_proto_t *proto_new)

Transition a connection to a new protocol.

ymo_status_t ymo_conn_send_buckets(ymo_conn_t *conn, ymo_bucket_t **head_p)

Send buckets over the wire.

void ymo_conn_rx_enable(ymo_conn_t *conn, int flag)

Turn receiving on/off, according to flag (0 = off; 1 = on)

void ymo_conn_tx_enable(ymo_conn_t *conn, int flag)

Turn receiving on/off, according to flag (0 = off; 1 = on)

void ymo_conn_tx_now(ymo_conn_t *conn)

Trigger the write callback right now, as if ev_run had invoked it.

void ymo_conn_rx_now(ymo_conn_t *conn)

Trigger the read callback right now, as if ev_run had invoked it.

ymo_conn_state_t ymo_conn_close(ymo_conn_t *conn, int clean)

Close a conn object.

Parameters
  • conn – The connection to close.

  • clean – if 1 perform a clean close using shutdown. If 0, just close the file descriptor.

Returns

the connection state after invocation.

void ymo_conn_free(ymo_conn_t *conn)

Free a conn object.