Mistake on this page?
Report an issue in GitHub or email us
Public Types | Public Member Functions | Protected Member Functions | Friends
NetworkStack Class Referenceabstract
Inheritance diagram for NetworkStack:
DNS mbed::AT_CellularStack NetworkStackWrapper OnboardNetworkStack my_stack MyStack Nanostack

Public Types

typedef mbed::Callback< void(nsapi_error_t result, SocketAddress *address)> hostbyname_cb_t
 
- Public Types inherited from DNS
typedef mbed::Callback< void(nsapi_error_t result, SocketAddress *address)> hostbyname_cb_t
 

Public Member Functions

virtual const char * get_ip_address ()
 
virtual nsapi_error_t gethostbyname (const char *host, SocketAddress *address, nsapi_version_t version=NSAPI_UNSPEC)
 
virtual nsapi_value_or_error_t gethostbyname_async (const char *host, hostbyname_cb_t callback, nsapi_version_t version=NSAPI_UNSPEC)
 
virtual nsapi_error_t gethostbyname_async_cancel (int id)
 
virtual nsapi_error_t add_dns_server (const SocketAddress &address)
 
virtual nsapi_error_t get_dns_server (int index, SocketAddress *address)
 
virtual nsapi_error_t setstackopt (int level, int optname, const void *optval, unsigned optlen)
 
virtual nsapi_error_t getstackopt (int level, int optname, void *optval, unsigned *optlen)
 
virtual OnboardNetworkStackonboardNetworkStack ()
 

Protected Member Functions

virtual nsapi_error_t socket_open (nsapi_socket_t *handle, nsapi_protocol_t proto)=0
 
virtual nsapi_error_t socket_close (nsapi_socket_t handle)=0
 
virtual nsapi_error_t socket_bind (nsapi_socket_t handle, const SocketAddress &address)=0
 
virtual nsapi_error_t socket_listen (nsapi_socket_t handle, int backlog)=0
 
virtual nsapi_error_t socket_connect (nsapi_socket_t handle, const SocketAddress &address)=0
 
virtual nsapi_error_t socket_accept (nsapi_socket_t server, nsapi_socket_t *handle, SocketAddress *address=0)=0
 
virtual nsapi_size_or_error_t socket_send (nsapi_socket_t handle, const void *data, nsapi_size_t size)=0
 
virtual nsapi_size_or_error_t socket_recv (nsapi_socket_t handle, void *data, nsapi_size_t size)=0
 
virtual nsapi_size_or_error_t socket_sendto (nsapi_socket_t handle, const SocketAddress &address, const void *data, nsapi_size_t size)=0
 
virtual nsapi_size_or_error_t socket_recvfrom (nsapi_socket_t handle, SocketAddress *address, void *buffer, nsapi_size_t size)=0
 
virtual void socket_attach (nsapi_socket_t handle, void(*callback)(void *), void *data)=0
 
virtual nsapi_error_t setsockopt (nsapi_socket_t handle, int level, int optname, const void *optval, unsigned optlen)
 
virtual nsapi_error_t getsockopt (nsapi_socket_t handle, int level, int optname, void *optval, unsigned *optlen)
 

Friends

class Socket
 
class UDPSocket
 
class TCPSocket
 
class TCPServer
 

Member Typedef Documentation

Hostname translation callback (asynchronous)

Callback will be called after DNS resolution completes or a failure occurs.

Callback should not take more than 10ms to execute, otherwise it might prevent underlying thread processing. A portable user of the callback should not make calls to network operations due to stack size limitations. The callback should not perform expensive operations such as socket recv/send calls or blocking operations.

Parameters
status0 on success, negative error code on failure
addressOn success, destination for the host SocketAddress

Member Function Documentation

nsapi_error_t NetworkStack::add_dns_server ( const SocketAddress address)
virtual

Add a domain name server to list of servers to query

Parameters
addressDestination for the host address
Returns
0 on success, negative error code on failure

Implements DNS.

Reimplemented in NetworkStackWrapper.

nsapi_error_t NetworkStack::get_dns_server ( int  index,
SocketAddress address 
)
virtual

Get a domain name server from a list of servers to query

Returns a DNS server address for a index. If returns error no more DNS servers to read.

Parameters
indexIndex of the DNS server, starts from zero
addressDestination for the host address
Returns
0 on success, negative error code on failure
const char * NetworkStack::get_ip_address ( )
virtual

Get the local IP address

Returns
Null-terminated representation of the local IP address or null if not yet connected

Reimplemented in NetworkStackWrapper, Nanostack, and mbed::AT_CellularStack.

nsapi_error_t NetworkStack::gethostbyname ( const char *  host,
SocketAddress address,
nsapi_version_t  version = NSAPI_UNSPEC 
)
virtual

Translates a hostname to an IP address with specific version

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
hostHostname to resolve
addressDestination for the host SocketAddress
versionIP version of address to resolve, NSAPI_UNSPEC indicates version is chosen by the stack (defaults to NSAPI_UNSPEC)
Returns
0 on success, negative error code on failure

Implements DNS.

Reimplemented in NetworkStackWrapper.

nsapi_value_or_error_t NetworkStack::gethostbyname_async ( const char *  host,
hostbyname_cb_t  callback,
nsapi_version_t  version = NSAPI_UNSPEC 
)
virtual

Translates a hostname to an IP address (asynchronous)

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.

Call is non-blocking. Result of the DNS operation is returned by the callback. If this function returns failure, callback will not be called. In case result is success (IP address was found from DNS cache), callback will be called before function returns.

Parameters
hostHostname to resolve
callbackCallback that is called for result
versionIP version of address to resolve, NSAPI_UNSPEC indicates version is chosen by the stack (defaults to NSAPI_UNSPEC)
Returns
0 on immediate success, negative error code on immediate failure or a positive unique id that represents the hostname translation operation and can be passed to cancel

Implements DNS.

nsapi_error_t NetworkStack::gethostbyname_async_cancel ( int  id)
virtual

Cancels asynchronous hostname translation

When translation is cancelled, callback will not be called.

Parameters
idUnique id of the hostname translation operation
Returns
0 on success, negative error code on failure

Implements DNS.

virtual OnboardNetworkStack* NetworkStack::onboardNetworkStack ( )
inlinevirtual

Dynamic downcast to a OnboardNetworkStack

virtual nsapi_error_t NetworkStack::socket_accept ( nsapi_socket_t  server,
nsapi_socket_t handle,
SocketAddress address = 0 
)
protectedpure virtual

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
serverSocket handle to server to accept from
handleDestination for a handle to the newly created socket
addressDestination for the remote address or NULL
Returns
0 on success, negative error code on failure

Implemented in NetworkStackWrapper, Nanostack, MyStack, and mbed::AT_CellularStack.

virtual void NetworkStack::socket_attach ( nsapi_socket_t  handle,
void(*)(void *)  callback,
void *  data 
)
protectedpure virtual

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
handleSocket handle
callbackFunction to call on state change
dataArgument to pass to callback

Implemented in NetworkStackWrapper, Nanostack, MyStack, and mbed::AT_CellularStack.

virtual nsapi_error_t NetworkStack::socket_bind ( nsapi_socket_t  handle,
const SocketAddress address 
)
protectedpure virtual

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
handleSocket handle
addressLocal address to bind
Returns
0 on success, negative error code on failure.

Implemented in NetworkStackWrapper, Nanostack, MyStack, and mbed::AT_CellularStack.

virtual nsapi_error_t NetworkStack::socket_close ( nsapi_socket_t  handle)
protectedpure virtual

Close the socket

Closes any open connection and deallocates any memory associated with the socket.

Parameters
handleSocket handle
Returns
0 on success, negative error code on failure

Implemented in NetworkStackWrapper, MyStack, Nanostack, and mbed::AT_CellularStack.

virtual nsapi_error_t NetworkStack::socket_connect ( nsapi_socket_t  handle,
const SocketAddress address 
)
protectedpure virtual

Connects TCP socket to a remote host

Initiates a connection to a remote server specified by the indicated address.

Parameters
handleSocket handle
addressThe SocketAddress of the remote host
Returns
0 on success, negative error code on failure

Implemented in NetworkStackWrapper, Nanostack, MyStack, and mbed::AT_CellularStack.

virtual nsapi_error_t NetworkStack::socket_listen ( nsapi_socket_t  handle,
int  backlog 
)
protectedpure virtual

Listen for connections on a TCP socket

Marks the socket as a passive socket that can be used to accept incoming connections.

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

Implemented in NetworkStackWrapper, Nanostack, MyStack, and mbed::AT_CellularStack.

virtual nsapi_error_t NetworkStack::socket_open ( nsapi_socket_t handle,
nsapi_protocol_t  proto 
)
protectedpure virtual

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

Implemented in NetworkStackWrapper, MyStack, Nanostack, and mbed::AT_CellularStack.

virtual nsapi_size_or_error_t NetworkStack::socket_recv ( nsapi_socket_t  handle,
void *  data,
nsapi_size_t  size 
)
protectedpure virtual

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

Implemented in NetworkStackWrapper, Nanostack, MyStack, and mbed::AT_CellularStack.

virtual nsapi_size_or_error_t NetworkStack::socket_recvfrom ( nsapi_socket_t  handle,
SocketAddress address,
void *  buffer,
nsapi_size_t  size 
)
protectedpure virtual

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
handleSocket handle
addressDestination for the source address or NULL
bufferDestination 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

Implemented in NetworkStackWrapper, Nanostack, MyStack, and mbed::AT_CellularStack.

virtual nsapi_size_or_error_t NetworkStack::socket_send ( nsapi_socket_t  handle,
const void *  data,
nsapi_size_t  size 
)
protectedpure virtual

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

Implemented in NetworkStackWrapper, Nanostack, MyStack, and mbed::AT_CellularStack.

virtual nsapi_size_or_error_t NetworkStack::socket_sendto ( nsapi_socket_t  handle,
const SocketAddress address,
const void *  data,
nsapi_size_t  size 
)
protectedpure virtual

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
handleSocket handle
addressThe SocketAddress 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

Implemented in NetworkStackWrapper, Nanostack, MyStack, and mbed::AT_CellularStack.


The documentation for this class was generated from the following files:
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.