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. More... | |
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. More... | |
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. More... | |
nsapi_error_t(* | setstackopt )(nsapi_stack_t *stack, int level, int optname, const void *optval, unsigned optlen) |
Set stack-specific stack options. More... | |
nsapi_error_t(* | getstackopt )(nsapi_stack_t *stack, int level, int optname, void *optval, unsigned *optlen) |
Get stack-specific stack options. More... | |
nsapi_error_t(* | socket_open )(nsapi_stack_t *stack, nsapi_socket_t *socket, nsapi_protocol_t proto) |
Opens a socket. More... | |
nsapi_error_t(* | socket_close )(nsapi_stack_t *stack, nsapi_socket_t socket) |
Close the socket. More... | |
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. More... | |
nsapi_error_t(* | socket_listen )(nsapi_stack_t *stack, nsapi_socket_t socket, int backlog) |
Listen for connections on a TCP socket. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
nsapi_error_t(* | setsockopt )(nsapi_stack_t *stack, nsapi_socket_t socket, int level, int optname, const void *optval, unsigned optlen) |
Set stack-specific socket options. More... | |
nsapi_error_t(* | getsockopt )(nsapi_stack_t *stack, nsapi_socket_t socket, int level, int optname, void *optval, unsigned *optlen) |
Get stack-specific socket options. More... | |
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 349 of file nsapi_types.h.
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.
addr | Destination for the host address |
Definition at line 378 of file nsapi_types.h.
nsapi_addr_t(* get_ip_address) (nsapi_stack_t *stack) |
Get the local IP address.
stack | Stack handle |
Definition at line 355 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.
stack | Stack handle |
addr | Destination for the host IP address |
host | Hostname to resolve |
version | Address family |
Definition at line 371 of file nsapi_types.h.
nsapi_error_t(* getsockopt) (nsapi_stack_t *stack, nsapi_socket_t socket, int level, int optname, void *optval, unsigned *optlen) |
Get stack-specific socket options.
The getstackopt allow an application to retrieve stack-specific hints from the underlying stack. For unsupported options, NSAPI_ERROR_UNSUPPORTED is returned and optval is unmodified.
stack | Stack handle |
socket | Socket handle |
level | Stack-specific protocol level |
optname | Stack-specific option identifier |
optval | Destination for option value |
optlen | Length of the option value |
Definition at line 627 of file nsapi_types.h.
nsapi_error_t(* getstackopt) (nsapi_stack_t *stack, int level, int optname, void *optval, unsigned *optlen) |
Get stack-specific stack options.
The getstackopt allow an application to retrieve stack-specific hints from the underlying stack. For unsupported options, NSAPI_ERROR_UNSUPPORTED is returned and optval is unmodified.
stack | Stack handle |
level | Stack-specific protocol level |
optname | Stack-specific option identifier |
optval | Destination for option value |
optlen | Length of the option value |
Definition at line 409 of file nsapi_types.h.
nsapi_error_t(* setsockopt) (nsapi_stack_t *stack, nsapi_socket_t socket, int level, int optname, const void *optval, unsigned optlen) |
Set stack-specific socket options.
The setsockopt allow an application to pass stack-specific hints to the underlying stack. For unsupported options, NSAPI_ERROR_UNSUPPORTED is returned and the socket is unmodified.
stack | Stack handle |
socket | Socket handle |
level | Stack-specific protocol level |
optname | Stack-specific option identifier |
optval | Option value |
optlen | Length of the option value |
Definition at line 610 of file nsapi_types.h.
nsapi_error_t(* setstackopt) (nsapi_stack_t *stack, int level, int optname, const void *optval, unsigned optlen) |
Set stack-specific stack options.
The setstackopt allow an application to pass stack-specific hints to the underlying stack. For unsupported options, NSAPI_ERROR_UNSUPPORTED is returned and the stack is unmodified.
stack | Stack handle |
level | Stack-specific protocol level |
optname | Stack-specific option identifier |
optval | Option value |
optlen | Length of the option value |
Definition at line 393 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.
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 |
Definition at line 500 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.
stack | Stack handle |
socket | Socket handle |
callback | Function to call on state change |
data | Argument to pass to callback |
Definition at line 593 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 receive data. If the IP address is zeroed, only the port is bound.
stack | Stack handle |
socket | Socket handle |
addr | Local address to bind, may be null |
port | Local port to bind |
Definition at line 450 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.
stack | Stack handle |
socket | Socket handle |
Definition at line 437 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.
stack | Stack handle |
socket | Socket handle |
addr | The address of the remote host |
port | The port of the remote host |
Definition at line 477 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.
stack | Stack handle |
socket | Socket handle |
backlog | Number of pending connections that can be queued simultaneously |
Definition at line 464 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.
stack | Stack context |
socket | Destination for the handle to a newly created socket |
proto | Protocol of socket to open, NSAPI_TCP or NSAPI_UDP |
Definition at line 425 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.
stack | Stack handle |
socket | Socket handle |
data | Destination buffer for data received from the host |
size | Size of the buffer in bytes |
Definition at line 536 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.
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 |
Definition at line 576 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.
stack | Stack handle |
socket | Socket handle |
data | Buffer of data to send to the host |
size | Size of the buffer in bytes |
Definition at line 518 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.
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 |
Definition at line 556 of file nsapi_types.h.