Rtos API example
nsapi_stack_api Struct Reference
[Netsocket]
nsapi_stack_api structure More...
#include <nsapi_types.h>
Data Fields | |
nsapi_addr_t(* | get_ip_address )(nsapi_stack_t *stack) |
Get the local IP address. | |
nsapi_error_t(* | gethostbyname )(nsapi_stack_t *stack, const char *host, nsapi_addr_t *addr, nsapi_version_t version) |
Translates a hostname to an IP address. | |
nsapi_error_t(* | add_dns_server )(nsapi_stack_t *stack, nsapi_addr_t addr) |
Add a domain name server to list of servers to query. | |
nsapi_error_t(* | socket_open )(nsapi_stack_t *stack, nsapi_socket_t *socket, nsapi_protocol_t proto) |
Opens a socket. | |
nsapi_error_t(* | socket_close )(nsapi_stack_t *stack, nsapi_socket_t socket) |
Close the socket. | |
nsapi_error_t(* | socket_bind )(nsapi_stack_t *stack, nsapi_socket_t socket, nsapi_addr_t addr, uint16_t port) |
Bind a specific address to a socket. | |
nsapi_error_t(* | socket_listen )(nsapi_stack_t *stack, nsapi_socket_t socket, int backlog) |
Listen for connections on a TCP socket. | |
nsapi_error_t(* | socket_connect )(nsapi_stack_t *stack, nsapi_socket_t socket, nsapi_addr_t addr, uint16_t port) |
Connects TCP socket to a remote host. | |
nsapi_error_t(* | socket_accept )(nsapi_stack_t *stack, nsapi_socket_t server, nsapi_socket_t *socket, nsapi_addr_t *addr, uint16_t *port) |
Accepts a connection on a TCP socket. | |
nsapi_size_or_error_t(* | socket_send )(nsapi_stack_t *stack, nsapi_socket_t socket, const void *data, nsapi_size_t size) |
Send data over a TCP socket. | |
nsapi_size_or_error_t(* | socket_recv )(nsapi_stack_t *stack, nsapi_socket_t socket, void *data, nsapi_size_t size) |
Receive data over a TCP socket. | |
nsapi_size_or_error_t(* | socket_sendto )(nsapi_stack_t *stack, nsapi_socket_t socket, nsapi_addr_t addr, uint16_t port, const void *data, nsapi_size_t size) |
Send a packet over a UDP socket. | |
nsapi_size_or_error_t(* | socket_recvfrom )(nsapi_stack_t *stack, nsapi_socket_t socket, nsapi_addr_t *addr, uint16_t *port, void *buffer, nsapi_size_t size) |
Receive a packet over a UDP socket. | |
void(* | socket_attach )(nsapi_stack_t *stack, nsapi_socket_t socket, void(*callback)(void *), void *data) |
Register a callback on state change of the socket. |
Detailed Description
nsapi_stack_api structure
Common api structure for network stack operations. A network stack can provide a nsapi_stack_api structure filled out with the appropriate implementation.
Unsupported operations can be left as null pointers.
Definition at line 286 of file nsapi_types.h.
Field Documentation
nsapi_error_t(* add_dns_server)(nsapi_stack_t *stack, nsapi_addr_t addr) |
Add a domain name server to list of servers to query.
- Parameters:
-
addr Destination for the host address
- Returns:
- 0 on success, negative error code on failure
Definition at line 316 of file nsapi_types.h.
nsapi_addr_t(* get_ip_address)(nsapi_stack_t *stack) |
Get the local IP address.
- Parameters:
-
stack Stack handle
- Returns:
- Local IP Address or null address if not connected
Definition at line 293 of file nsapi_types.h.
nsapi_error_t(* gethostbyname)(nsapi_stack_t *stack, const char *host, nsapi_addr_t *addr, nsapi_version_t version) |
Translates a hostname to an IP address.
The hostname may be either a domain name or an IP address. If the hostname is an IP address, no network transactions will be performed.
If no stack-specific DNS resolution is provided, the hostname will be resolve using a UDP socket on the stack.
- Parameters:
-
stack Stack handle addr Destination for the host IP address host Hostname to resolve version Address family
- Returns:
- 0 on success, negative error code on failure
Definition at line 309 of file nsapi_types.h.
nsapi_error_t(* socket_accept)(nsapi_stack_t *stack, nsapi_socket_t server, nsapi_socket_t *socket, nsapi_addr_t *addr, uint16_t *port) |
Accepts a connection on a TCP socket.
The server socket must be bound and set to listen for connections. On a new connection, creates a network socket and stores it in the specified handle. The handle must be passed to following calls on the socket.
A stack may have a finite number of sockets, in this case NSAPI_ERROR_NO_SOCKET is returned if no socket is available.
This call is non-blocking. If accept would block, NSAPI_ERROR_WOULD_BLOCK is returned immediately.
- Parameters:
-
stack Stack handle server Socket handle to server to accept from socket Destination for a handle to the newly created socket addr Destination for the address of the remote host port Destination for the port of the remote host
- Returns:
- 0 on success, negative error code on failure
Definition at line 438 of file nsapi_types.h.
void(* socket_attach)(nsapi_stack_t *stack, nsapi_socket_t socket, void(*callback)(void *), void *data) |
Register a callback on state change of the socket.
The specified callback will be called on state changes such as when the socket can recv/send/accept successfully and on when an error occurs. The callback may also be called spuriously without reason.
The callback may be called in an interrupt context and should not perform expensive operations such as recv/send calls.
- Parameters:
-
stack Stack handle socket Socket handle callback Function to call on state change data Argument to pass to callback
Definition at line 531 of file nsapi_types.h.
nsapi_error_t(* socket_bind)(nsapi_stack_t *stack, nsapi_socket_t socket, nsapi_addr_t addr, uint16_t port) |
Bind a specific address to a socket.
Binding a socket specifies the address and port on which to recieve data. If the IP address is zeroed, only the port is bound.
- Parameters:
-
stack Stack handle socket Socket handle addr Local address to bind, may be null port Local port to bind
- Returns:
- 0 on success, negative error code on failure.
Definition at line 388 of file nsapi_types.h.
nsapi_error_t(* socket_close)(nsapi_stack_t *stack, nsapi_socket_t socket) |
Close the socket.
Closes any open connection and deallocates any memory associated with the socket.
- Parameters:
-
stack Stack handle socket Socket handle
- Returns:
- 0 on success, negative error code on failure
Definition at line 375 of file nsapi_types.h.
nsapi_error_t(* socket_connect)(nsapi_stack_t *stack, nsapi_socket_t socket, nsapi_addr_t addr, uint16_t port) |
Connects TCP socket to a remote host.
Initiates a connection to a remote server specified by the indicated address.
- Parameters:
-
stack Stack handle socket Socket handle addr The address of the remote host port The port of the remote host
- Returns:
- 0 on success, negative error code on failure
Definition at line 415 of file nsapi_types.h.
nsapi_error_t(* socket_listen)(nsapi_stack_t *stack, nsapi_socket_t socket, int backlog) |
Listen for connections on a TCP socket.
Marks the socket as a passive socket that can be used to accept incoming connections.
- Parameters:
-
stack Stack handle socket Socket handle backlog Number of pending connections that can be queued simultaneously
- Returns:
- 0 on success, negative error code on failure
Definition at line 402 of file nsapi_types.h.
nsapi_error_t(* socket_open)(nsapi_stack_t *stack, nsapi_socket_t *socket, nsapi_protocol_t proto) |
Opens a socket.
Creates a network socket and stores it in the specified handle. The handle must be passed to following calls on the socket.
A stack may have a finite number of sockets, in this case NSAPI_ERROR_NO_SOCKET is returned if no socket is available.
- Parameters:
-
stack Stack context socket Destination for the handle to a newly created socket proto Protocol of socket to open, NSAPI_TCP or NSAPI_UDP
- Returns:
- 0 on success, negative error code on failure
Definition at line 363 of file nsapi_types.h.
nsapi_size_or_error_t(* socket_recv)(nsapi_stack_t *stack, nsapi_socket_t socket, void *data, nsapi_size_t size) |
Receive data over a TCP socket.
The socket must be connected to a remote host. Returns the number of bytes received into the buffer.
This call is non-blocking. If recv would block, NSAPI_ERROR_WOULD_BLOCK is returned immediately.
- Parameters:
-
stack Stack handle socket Socket handle data Destination buffer for data received from the host size Size of the buffer in bytes
- Returns:
- Number of received bytes on success, negative error code on failure
Definition at line 474 of file nsapi_types.h.
nsapi_size_or_error_t(* socket_recvfrom)(nsapi_stack_t *stack, nsapi_socket_t socket, nsapi_addr_t *addr, uint16_t *port, void *buffer, nsapi_size_t size) |
Receive a packet over a UDP socket.
Receives data and stores the source address in address if address is not NULL. Returns the number of bytes received into the buffer.
This call is non-blocking. If recvfrom would block, NSAPI_ERROR_WOULD_BLOCK is returned immediately.
- Parameters:
-
stack Stack handle socket Socket handle addr Destination for the address of the remote host port Destination for the port of the remote host data Destination buffer for data received from the host size Size of the buffer in bytes
- Returns:
- Number of received bytes on success, negative error code on failure
Definition at line 514 of file nsapi_types.h.
nsapi_size_or_error_t(* socket_send)(nsapi_stack_t *stack, nsapi_socket_t socket, const void *data, nsapi_size_t size) |
Send data over a TCP socket.
The socket must be connected to a remote host. Returns the number of bytes sent from the buffer.
This call is non-blocking. If send would block, NSAPI_ERROR_WOULD_BLOCK is returned immediately.
- Parameters:
-
stack Stack handle socket Socket handle data Buffer of data to send to the host size Size of the buffer in bytes
- Returns:
- Number of sent bytes on success, negative error code on failure
Definition at line 456 of file nsapi_types.h.
nsapi_size_or_error_t(* socket_sendto)(nsapi_stack_t *stack, nsapi_socket_t socket, nsapi_addr_t addr, uint16_t port, const void *data, nsapi_size_t size) |
Send a packet over a UDP socket.
Sends data to the specified address. Returns the number of bytes sent from the buffer.
This call is non-blocking. If sendto would block, NSAPI_ERROR_WOULD_BLOCK is returned immediately.
- Parameters:
-
stack Stack handle socket Socket handle addr The address of the remote host port The port of the remote host data Buffer of data to send to the host size Size of the buffer in bytes
- Returns:
- Number of sent bytes on success, negative error code on failure
Definition at line 494 of file nsapi_types.h.
Generated on Sun Jul 17 2022 08:25:42 by 1.7.2