Mistake on this page?
Report an issue in GitHub or email us
Data Fields
nsapi_stack_api Struct Reference

#include <nsapi_types.h>

Data Fields

nsapi_addr_t(* get_ip_address )(nsapi_stack_t *stack)
 
nsapi_error_t(* gethostbyname )(nsapi_stack_t *stack, const char *host, nsapi_addr_t *addr, nsapi_version_t version)
 
nsapi_error_t(* add_dns_server )(nsapi_stack_t *stack, nsapi_addr_t addr)
 
nsapi_error_t(* setstackopt )(nsapi_stack_t *stack, int level, int optname, const void *optval, unsigned optlen)
 
nsapi_error_t(* getstackopt )(nsapi_stack_t *stack, int level, int optname, void *optval, unsigned *optlen)
 
nsapi_error_t(* socket_open )(nsapi_stack_t *stack, nsapi_socket_t *socket, nsapi_protocol_t proto)
 
nsapi_error_t(* socket_close )(nsapi_stack_t *stack, nsapi_socket_t socket)
 
nsapi_error_t(* socket_bind )(nsapi_stack_t *stack, nsapi_socket_t socket, nsapi_addr_t addr, uint16_t port)
 
nsapi_error_t(* socket_listen )(nsapi_stack_t *stack, nsapi_socket_t socket, int backlog)
 
nsapi_error_t(* socket_connect )(nsapi_stack_t *stack, nsapi_socket_t socket, nsapi_addr_t addr, uint16_t port)
 
nsapi_error_t(* socket_accept )(nsapi_stack_t *stack, nsapi_socket_t server, nsapi_socket_t *socket, nsapi_addr_t *addr, uint16_t *port)
 
nsapi_size_or_error_t(* socket_send )(nsapi_stack_t *stack, nsapi_socket_t socket, const void *data, nsapi_size_t size)
 
nsapi_size_or_error_t(* socket_recv )(nsapi_stack_t *stack, nsapi_socket_t socket, void *data, nsapi_size_t size)
 
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)
 
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)
 
void(* socket_attach )(nsapi_stack_t *stack, nsapi_socket_t socket, void(*callback)(void *), void *data)
 
nsapi_error_t(* setsockopt )(nsapi_stack_t *stack, nsapi_socket_t socket, int level, int optname, const void *optval, unsigned optlen)
 
nsapi_error_t(* getsockopt )(nsapi_stack_t *stack, nsapi_socket_t socket, int level, int optname, void *optval, unsigned *optlen)
 

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.

Field Documentation

nsapi_error_t(* nsapi_stack_api::add_dns_server) (nsapi_stack_t *stack, nsapi_addr_t addr)

Add a domain name server to list of servers to query

Parameters
addrDestination for the host address
Returns
0 on success, negative error code on failure
nsapi_addr_t(* nsapi_stack_api::get_ip_address) (nsapi_stack_t *stack)

Get the local IP address

Parameters
stackStack handle
Returns
Local IP Address or null address if not connected
nsapi_error_t(* nsapi_stack_api::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
stackStack handle
addrDestination for the host IP address
hostHostname to resolve
versionAddress family
Returns
0 on success, negative error code on failure
nsapi_error_t(* nsapi_stack_api::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
stackStack handle
serverSocket handle to server to accept from
socketDestination for a handle to the newly created socket
addrDestination for the address of the remote host
portDestination for the port of the remote host
Returns
0 on success, negative error code on failure
void(* nsapi_stack_api::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
stackStack handle
socketSocket handle
callbackFunction to call on state change
dataArgument to pass to callback
nsapi_error_t(* nsapi_stack_api::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.

Parameters
stackStack handle
socketSocket handle
addrLocal address to bind, may be null
portLocal port to bind
Returns
0 on success, negative error code on failure.
nsapi_error_t(* nsapi_stack_api::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
stackStack handle
socketSocket handle
Returns
0 on success, negative error code on failure
nsapi_error_t(* nsapi_stack_api::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
stackStack handle
socketSocket handle
addrThe address of the remote host
portThe port of the remote host
Returns
0 on success, negative error code on failure
nsapi_error_t(* nsapi_stack_api::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
stackStack handle
socketSocket handle
backlogNumber of pending connections that can be queued simultaneously
Returns
0 on success, negative error code on failure
nsapi_error_t(* nsapi_stack_api::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
stackStack context
socketDestination for the handle to a newly created socket
protoProtocol of socket to open, NSAPI_TCP or NSAPI_UDP
Returns
0 on success, negative error code on failure
nsapi_size_or_error_t(* nsapi_stack_api::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
stackStack handle
socketSocket handle
dataDestination buffer for data received from the host
sizeSize of the buffer in bytes
Returns
Number of received bytes on success, negative error code on failure
nsapi_size_or_error_t(* nsapi_stack_api::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
stackStack handle
socketSocket handle
addrDestination for the address of the remote host
portDestination for the port of the remote host
dataDestination buffer for data received from the host
sizeSize of the buffer in bytes
Returns
Number of received bytes on success, negative error code on failure
nsapi_size_or_error_t(* nsapi_stack_api::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
stackStack handle
socketSocket handle
dataBuffer of data to send to the host
sizeSize of the buffer in bytes
Returns
Number of sent bytes on success, negative error code on failure
nsapi_size_or_error_t(* nsapi_stack_api::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
stackStack handle
socketSocket handle
addrThe address of the remote host
portThe port of the remote host
dataBuffer of data to send to the host
sizeSize of the buffer in bytes
Returns
Number of sent bytes on success, negative error code on failure

The documentation for this struct was generated from the following file:
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.