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

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...
 

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 349 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
addrDestination for the host address
Returns
0 on success, negative error code on failure

Definition at line 378 of file nsapi_types.h.

nsapi_addr_t(* 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

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.

Parameters
stackStack handle
addrDestination for the host IP address
hostHostname to resolve
versionAddress family
Returns
0 on success, negative error code on failure

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.

Parameters
stackStack handle
socketSocket handle
levelStack-specific protocol level
optnameStack-specific option identifier
optvalDestination for option value
optlenLength of the option value
Returns
0 on success, negative error code on failure

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.

Parameters
stackStack handle
levelStack-specific protocol level
optnameStack-specific option identifier
optvalDestination for option value
optlenLength of the option value
Returns
0 on success, negative error code on failure

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.

Parameters
stackStack handle
socketSocket handle
levelStack-specific protocol level
optnameStack-specific option identifier
optvalOption value
optlenLength of the option value
Returns
0 on success, negative error code on failure

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.

Parameters
stackStack handle
levelStack-specific protocol level
optnameStack-specific option identifier
optvalOption value
optlenLength of the option value
Returns
0 on success, negative error code on failure

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.

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

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.

Parameters
stackStack handle
socketSocket handle
callbackFunction to call on state change
dataArgument 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.

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.

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.

Parameters
stackStack handle
socketSocket handle
Returns
0 on success, negative error code on failure

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.

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

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.

Parameters
stackStack handle
socketSocket handle
backlogNumber of pending connections that can be queued simultaneously
Returns
0 on success, negative error code on failure

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.

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

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.

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

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.

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

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.

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

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.

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

Definition at line 556 of file nsapi_types.h.

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.