Protocols¶
Protocols are used to implement parsing and domain-specific functionality on top of the raw I/O functionality provided by the server.
Implementing Protocols
New protocols can be implemented by:
Providing an implementation for each of the protocol callback types.
Populating a
ymo_proto
with some protocol metadata and filling out theymo_proto_vt
vtable
.Providing a pointer to that structure in an invocation to
ymo_server_create()
.
Callbacks¶
-
type ymo_proto_init_cb_t¶
Protocol alloc/init callback type. [REQUIRED]
Individual protocols provide functions which match this signature in order to provide allocation/initialization.
- Proto_data
private data for this protocol
- Server
the server issuing the callback
Returns a status indicating protocol is ready for use
be separated into two distinct callbacks.
typedef ymo_status_t (*ymo_proto_init_cb_t)( ymo_proto_t* proto, ymo_server_t* server);
-
type ymo_proto_cleanup_cb_t¶
Protocol-level cleanup/dealloc callback type. [REQUIRED]
Individual protocols provide a function which matches this signature in order to perform cleanup/deallocation.
- Proto
the protocol being destroyed
- Server
the server which is issuing the callback
be separated into two distinct callbacks.
typedef void (*ymo_proto_cleanup_cb_t)( ymo_proto_t* proto, ymo_server_t* server);
-
type ymo_proto_conn_init_cb_t¶
Protocol-level connection init callback. [OPTIONAL]
Gives protocols a chance to do alloc/init per-connection data.
- Proto_data
the protocol data against which this is being invoked.
- Conn
the newly created connection object
Returns per-connection protocol data (or NULL)
typedef void* (*ymo_proto_conn_init_cb_t)( void* proto_data, ymo_conn_t* conn);
-
type ymo_proto_conn_ready_cb_t¶
Protocol-level connection ready callback. [OPTIONAL]
Gives protocols a chance to do “on-open” style notification to user space.
- Proto_data
the protocol data against which this is being invoked.
- Conn
the newly created connection object
- Returns
per-connection protocol data (or NULL)
typedef ymo_status_t (*ymo_proto_conn_ready_cb_t)( void* proto_data, ymo_conn_t* conn, void* conn_data);
-
type ymo_proto_conn_cleanup_cb_t¶
Protocol-level connection cleanup callback.
Gives protocols a chance to do cleanup/deallocate per-connection data.
- Proto_data
the protocol data against which this is being invoked
- Conn
the connection object that’s being destroyed
- Conn_data
the per-connection data associated with this connection
typedef void (*ymo_proto_conn_cleanup_cb_t)( void* proto_data, ymo_conn_t* conn, void* conn_data);
-
type ymo_proto_read_cb_t¶
Protocol-level read callback.
typedef ssize_t (*ymo_proto_read_cb_t)( void* proto_data, ymo_conn_t* conn, void* conn_data, char* buf_in, size_t len);
-
type ymo_proto_write_cb_t¶
Protocol-level write callback.
typedef ymo_status_t (*ymo_proto_write_cb_t)( void* proto_data, ymo_conn_t* conn, void* conn_data, int socket);
Types¶
-
struct ymo_proto_vt¶
Protocol callback “vtable”.
struct ymo_proto_vt { ymo_proto_init_cb_t init_cb; /* Protocol init callback */ ymo_proto_cleanup_cb_t cleanup_cb; /* Protocol cleanup callback */ ymo_proto_conn_init_cb_t conn_init_cb; /* Client init callback */ ymo_proto_conn_ready_cb_t conn_ready_cb; /* Client ready callback */ ymo_proto_conn_cleanup_cb_t conn_cleanup_cb; /* Client cleanup callback */ ymo_proto_read_cb_t read_cb; /* Protocol read callback */ ymo_proto_write_cb_t write_cb; /* Protocol write callback */ };
-
struct ymo_proto¶
Data structure used to define a single protocol.
struct ymo_proto { const char* name; /* Plain text protocol name */ void* data; struct ymo_proto_vt vtable; };