You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm in the process of designing a simple TCP networking API that would make it possible to create servers running in UVM. This API works with callbacks that tell you when a new connection request is incoming, or when data is available to read. Then, you can call the listen or read functions to accept a connection or read incoming data. If there is no incoming connection or data, then these functions will blocks, so the API can also be used in a synchronous mode as well. Having to call read functions also makes it so we don't have to preallocate global buffers to receive data, we can simply pass pointers to those buffers when calling the functions to read data.
// Syscall to create a TCP listening socket to accept incoming connections
u64 socket_id = net_listen_tcp(
u16 port_no,
ip_space, // IPV4 / IPV6
const char* net_iface, // Network interface address to listen on, null for any address
callback on_new_connection, // Called on new incoming connection
u64 flags // optional flags, default 0
)
The callback to be notified of an incoming connection request has the form:
void on_new_connection(u64 socket_id)
To accept new connections:
// Syscall to accept a new connection
// Gives you the client address in the buffer you define
// Will block if there is no incoming connection request
u64 socket_id = net_accept(u64 socket_id, client_addr_t *client_addr, callback on_incoming_data)
When there is incoming data to be read, we can be notified by a callback:
// Callback to notify you that incoming data is available to read
void on_incoming_data(u64 socket_id, u64 num_bytes)
To read and write data:
// Syscall to read data from a given socket into a buffer you specify
u64 num_bytes_read = net_read(u64 socket_id, void* buffer, u64 buf_len)
// Syscall to write data on a given socket
void net_write(u64 socket_id, void* buffer, u64 buf_len);
Finally, to close the socket:
// Syscall to close a socket
net_close(socket_id)
The text was updated successfully, but these errors were encountered:
I'm in the process of designing a simple TCP networking API that would make it possible to create servers running in UVM. This API works with callbacks that tell you when a new connection request is incoming, or when data is available to read. Then, you can call the
listen
orread
functions to accept a connection or read incoming data. If there is no incoming connection or data, then these functions will blocks, so the API can also be used in a synchronous mode as well. Having to call read functions also makes it so we don't have to preallocate global buffers to receive data, we can simply pass pointers to those buffers when calling the functions to read data.The callback to be notified of an incoming connection request has the form:
To accept new connections:
When there is incoming data to be read, we can be notified by a callback:
To read and write data:
Finally, to close the socket:
The text was updated successfully, but these errors were encountered: