Read/write over the network. More...
Data Structures | |
struct | bio_socket_t |
Handle to a socket. More... | |
struct | bio_addr_t |
Net address. More... | |
Typedefs | |
typedef uint16_t | bio_port_t |
Port number in host byte order. | |
Enumerations | |
enum | bio_addr_type_t { BIO_ADDR_IPV4 , BIO_ADDR_IPV6 , BIO_ADDR_NAMED } |
Address type. More... | |
enum | bio_socket_type_t { BIO_SOCKET_STREAM , BIO_SOCKET_DATAGRAM } |
Socket type. More... | |
Functions | |
bool | bio_net_wrap (bio_socket_t *sock, uintptr_t handle, bio_addr_type_t addr_type, bio_error_t *error) |
Wrap a socket handle from the OS into a bio_socket_t. | |
uintptr_t | bio_net_unwrap (bio_socket_t socket) |
Retrieve an OS handle from a bio_socket_t. | |
bool | bio_net_listen (bio_socket_type_t socket_type, const bio_addr_t *addr, bio_port_t port, bio_socket_t *sock, bio_error_t *error) |
Create a listening socket. | |
bool | bio_net_accept (bio_socket_t socket, bio_socket_t *client, bio_error_t *error) |
Accept a new connection. | |
bool | bio_net_connect (bio_socket_type_t socket_type, const bio_addr_t *addr, bio_port_t port, bio_socket_t *socket, bio_error_t *error) |
Make an outgoing connection. | |
bool | bio_net_close (bio_socket_t socket, bio_error_t *error) |
Close a socket. | |
size_t | bio_net_send (bio_socket_t socket, const void *buf, size_t size, bio_error_t *error) |
Send to a socket. | |
size_t | bio_net_recv (bio_socket_t socket, void *buf, size_t size, bio_error_t *error) |
Receive from a socket. | |
size_t | bio_net_sendto (bio_socket_t socket, const bio_addr_t *addr, const void *buf, size_t size, bio_error_t *error) |
Not implemented. | |
size_t | bio_net_recvfrom (bio_socket_t socket, bio_addr_t *addr, void *buf, size_t size, bio_error_t *error) |
Not implemented. | |
int | bio_net_address_compare (const bio_addr_t *lhs, const bio_addr_t *rhs) |
Compare two addresses. | |
static size_t | bio_net_send_exactly (bio_socket_t socket, const void *buf, size_t size, bio_error_t *error) |
Helper to deal with short write. | |
static size_t | bio_net_recv_exactly (bio_socket_t socket, void *buf, size_t size, bio_error_t *error) |
Helper to deal with short read. | |
Variables | |
static const bio_port_t | BIO_PORT_ANY = 0 |
Any port. | |
static const bio_addr_t | BIO_ADDR_IPV4_ANY |
Any IPv4 address. | |
static const bio_addr_t | BIO_ADDR_IPV4_LOOPBACK |
Local loopback IPv4 address. | |
static const bio_addr_t | BIO_ADDR_IPV6_ANY |
Any IPv6 address. | |
static const bio_addr_t | BIO_ADDR_IPV6_LOOPBACK |
Local loopback IPv6 address. | |
Read/write over the network.
typedef uint16_t bio_port_t |
Port number in host byte order.
enum bio_addr_type_t |
enum bio_socket_type_t |
bool bio_net_accept | ( | bio_socket_t | socket, |
bio_socket_t * | client, | ||
bio_error_t * | error | ||
) |
Accept a new connection.
socket | A socket handle |
client | Pointer to a socket handle to receive the new connection |
error | Seee Error handling |
int bio_net_address_compare | ( | const bio_addr_t * | lhs, |
const bio_addr_t * | rhs | ||
) |
Compare two addresses.
bool bio_net_close | ( | bio_socket_t | socket, |
bio_error_t * | error | ||
) |
Close a socket.
bool bio_net_connect | ( | bio_socket_type_t | socket_type, |
const bio_addr_t * | addr, | ||
bio_port_t | port, | ||
bio_socket_t * | socket, | ||
bio_error_t * | error | ||
) |
Make an outgoing connection.
socket_type | The socket type |
addr | The remote address |
addr | The port number for IP socket. Ignored for "named" socket. |
sock | Pointer to a socket handle. This is only assigned if the operation is successful. |
error | Seee Error handling |
bool bio_net_listen | ( | bio_socket_type_t | socket_type, |
const bio_addr_t * | addr, | ||
bio_port_t | port, | ||
bio_socket_t * | sock, | ||
bio_error_t * | error | ||
) |
Create a listening socket.
socket_type | The socket type |
addr | The socket address to listen from |
addr | The port number for IP socket. Ignored for "named" socket. |
sock | Pointer to a socket handle. This is only assigned if the operation is successful. |
error | Seee Error handling |
size_t bio_net_recv | ( | bio_socket_t | socket, |
void * | buf, | ||
size_t | size, | ||
bio_error_t * | error | ||
) |
|
inlinestatic |
Helper to deal with short read.
size_t bio_net_recvfrom | ( | bio_socket_t | socket, |
bio_addr_t * | addr, | ||
void * | buf, | ||
size_t | size, | ||
bio_error_t * | error | ||
) |
Not implemented.
size_t bio_net_send | ( | bio_socket_t | socket, |
const void * | buf, | ||
size_t | size, | ||
bio_error_t * | error | ||
) |
|
inlinestatic |
Helper to deal with short write.
size_t bio_net_sendto | ( | bio_socket_t | socket, |
const bio_addr_t * | addr, | ||
const void * | buf, | ||
size_t | size, | ||
bio_error_t * | error | ||
) |
Not implemented.
uintptr_t bio_net_unwrap | ( | bio_socket_t | socket | ) |
Retrieve an OS handle from a bio_socket_t.
This can be used to call platform-specific API such as getsockopt
or WSAIoctl
For Unix platforms, this is will return a file descriptor. A value of -1 is possible if the socket was closed with bio_net_close.
For Windows, this will return a SOCKET
/HANDLE
. A value of INVALID_HANDLE_VALUE
/INVALID_SOCKET
may be returned.
bool bio_net_wrap | ( | bio_socket_t * | sock, |
uintptr_t | handle, | ||
bio_addr_type_t | addr_type, | ||
bio_error_t * | error | ||
) |
Wrap a socket handle from the OS into a bio_socket_t.
This can be used to handle platform-specific special sockets such as netlink socket on Linux.
sock | Pointer to a socket handle. This will only be assigned when the operation is successful. |
handle | The OS socket handle. On Unix platforms, this is a file descriptor. On Windows, this is a SOCKET /HANDLE . |
addr_type | The address type of the socket. This only matters on Windows as it uses two separate sets of APIs: one for named pipe and one for socket. |
error | See Error handling. |
|
static |
Any IPv4 address.
|
static |
Local loopback IPv4 address.
|
static |
Any IPv6 address.
|
static |
Local loopback IPv6 address.
|
static |
Any port.