sock-tcp (Socket TCP)ï
Header: udo/sock-tcp.h
Table of contents (click to go)ï
Macrosï
Enumsï
Unionsï
Structsï
Functionsï
API Documentationï
udo_sock_tcp (private)ï
Structure defining UDO Socket TCP context.
-
struct udo_sock_tcpï
-
struct udo_log_error_struct err;ï
-
bool free;ï
-
int fd;ï
-
char ip_addr[INET6_ADDRSTRLEN];ï
-
int port;ï
-
struct sockaddr_in6 addr;ï
err- Stores information about the error that occuredfor the given context and may later be retrievedby caller.
freefd- File descriptor to the open TCP socket.
ip_addr- Textual network IP address to connect(2) to or accept(2) with.
port- Network port number to connect(2) to or accept(2) with.
addr- Stores network byte information about the TCP socket context.Is used for client connect(2) and server accept(2).
-
struct udo_log_error_struct err;ï
udo_sock_tcp_server_create_infoï
Structure passed to
udo_sock_tcp_server_create()used to define how to create the server.
-
struct udo_sock_tcp_server_create_infoï
-
ipv6- Boolean to determine if a socket is soley an ipv6socket or requires an ipv4-mapped-ipv6-address.
ip_addr- Textual network IP addresses to accept(2) with.
port- Network port to accept(2) with.
connections- Amount of connections that may be queuedat a given moment.
udo_sock_tcp_server_createï
-
struct udo_sock_tcp *udo_sock_tcp_server_create(struct udo_sock_tcp *sock, const void *sock_info);ï
Creates a socket that may be utilized for server socket operations.
Param
Decription
sock
IfNULLmemory will be allocated and return tocaller. If notNULLaddress passed will be usedto store the newly createdstructudo_sock_tcpcontext.sock_info
Implementation uses a pointer to astructudo_sock_tcp_server_create_info.
- Returns:
on success: Pointer to astructudo_sock_tcpon failure:NULL
udo_sock_tcp_server_acceptï
-
int udo_sock_tcp_server_accept(struct udo_sock_tcp *sock, struct sockaddr_in6 *addr);ï
Accepts client connections and returns the open
file descriptor to the connected client.
Param
Decription
sock
Must pass a pointer to astructudo_sock_tcp.addr
If not NULLaddris filled in via accept(2) call.
- Returns:
on success: Open file descriptor to accepted clienton failure: -1
udo_sock_tcp_client_create_infoï
Structure passed to
udo_sock_tcp_client_create()used to define how to create the client.
-
struct udo_sock_tcp_client_create_infoï
-
ipv6- Boolean to determine if a socket is soley an ipv6socket or requires an ipv4-mapped-ipv6-address.
ip_addr- Textual network IP addresses to connect(2)/send(2) to.
port- Network port to connect(2)/send(2) to.
udo_sock_tcp_client_createï
-
struct udo_sock_tcp *udo_sock_tcp_client_create(struct udo_sock_tcp *sock, const void *sock_info);ï
Creates a socket that may be utilized for client socket operations.
Param
Decription
sock
IfNULLmemory will be allocated and return tocaller. If notNULLaddress passed will be usedto store the newly createdstructudo_sock_tcpcontext.sock_info
Implementation uses a pointer to astructudo_sock_tcp_client_create_info.
- Returns:
on success: Pointer to astructudo_sock_tcpon failure:NULL
udo_sock_tcp_client_connectï
-
int udo_sock_tcp_client_connect(struct udo_sock_tcp *sock);ï
Connects client socket to address provided via
call to
udo_sock_tcp_client_create().
Param
Decription
sock
Must pass a pointer to astructudo_sock_tcp.
- Returns:
on success: 0on failure: -1
udo_sock_tcp_client_send_dataï
-
ssize_t udo_sock_tcp_client_send_data(struct udo_sock_tcp *sock, const void *data, const size_t size, const void *sock_info);ï
Send data to client socket address provided via
call to
udo_sock_tcp_client_create().
Param
Decription
sock
Must pass a pointer to astructudo_sock_tcp.data
Pointer to buffer to send through socket.size
Size of data to send through socket.sock_info
Reserved for future usage. For now usedto set the flag argument of send(2).
- Returns:
on success: Amount of bytes senton failure: # < 0
udo_sock_tcp_get_fdï
-
int udo_sock_tcp_get_fd(struct udo_sock_tcp *sock);ï
Acquire socket file descriptor associated with
struct udo_sock_tcp context.
Param
Decription
sock
Must pass a pointer to astructudo_sock_tcp.
- Returns:
on success: TCP socket file descriptoron failure: -1
udo_sock_tcp_get_ip_addrï
-
const char *udo_sock_tcp_get_ip_addr(struct udo_sock_tcp *sock);ï
Acquire textual network address in string format
associated with
struct udo_sock_tcp context.
Param
Decription
sock
Must pass a pointer to astructudo_sock_tcp.
- Returns:
on success: Textual network addresson failure:NULL
udo_sock_tcp_get_portï
-
int udo_sock_tcp_get_port(struct udo_sock_tcp *sock);ï
Acquire network port associated with
struct udo_sock_tcp context.
Param
Decription
sock
Must pass a pointer to astructudo_sock_tcp.
- Returns:
on success: Network port connected to contexton failure: -1
udo_sock_tcp_destroyï
-
void udo_sock_tcp_destroy(struct udo_sock_tcp *sock);ï
Frees any allocated memory and closes FDâs (if open) created after
Param
Decription
sock
Pointer to a validstructudo_sock_tcp.
udo_sock_tcp_get_sizeofï
-
int udo_sock_tcp_get_sizeof(void);ï
Returns size of the internal structure. So,
if caller decides to allocate memory outside
of API interface they know the exact amount
of bytes.
- Returns:
on success: sizeof(structudo_sock_tcp)on failure: sizeof(structudo_sock_tcp)
udo_sock_tcp_recv_dataï
-
ssize_t udo_sock_tcp_recv_data(const int sock_fd, void *data, const size_t size, const void *sock_info);ï
Receive data from socket file descriptor.
Param
Decription
sock_fd
Socket file descriptor to receive data from.data
Pointer to buffer to store data received from a socket.size
Size of data to receive from a socket.sock_info
Reserved for future usage. For now usedto set the flag argument of recv(2).
- Returns:
on success: Amount of bytes receivedon failure: # < 0
udo_sock_tcp_send_dataï
-
ssize_t udo_sock_tcp_send_data(const int sock_fd, const void *data, const size_t size, const void *sock_info);ï
Send data to socket file descriptor.
Param
Decription
sock_fd
Socket file descriptor to send data to.data
Pointer to buffer to send through socket.size
Size of data to send through socket.sock_info
Reserved for future usage. For now usedto set the flag argument of send(2).
- Returns:
on success: Amount of bytes senton failure: # < 0