Pinned to some recent date

Committer:
Simon Cooksey
Date:
Thu Nov 17 16:43:53 2016 +0000
Revision:
0:fb7af294d5d9
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Simon Cooksey 0:fb7af294d5d9 1
Simon Cooksey 0:fb7af294d5d9 2 /** \addtogroup netsocket */
Simon Cooksey 0:fb7af294d5d9 3 /** @{*/
Simon Cooksey 0:fb7af294d5d9 4 /* NetworkStack
Simon Cooksey 0:fb7af294d5d9 5 * Copyright (c) 2015 ARM Limited
Simon Cooksey 0:fb7af294d5d9 6 *
Simon Cooksey 0:fb7af294d5d9 7 * Licensed under the Apache License, Version 2.0 (the "License");
Simon Cooksey 0:fb7af294d5d9 8 * you may not use this file except in compliance with the License.
Simon Cooksey 0:fb7af294d5d9 9 * You may obtain a copy of the License at
Simon Cooksey 0:fb7af294d5d9 10 *
Simon Cooksey 0:fb7af294d5d9 11 * http://www.apache.org/licenses/LICENSE-2.0
Simon Cooksey 0:fb7af294d5d9 12 *
Simon Cooksey 0:fb7af294d5d9 13 * Unless required by applicable law or agreed to in writing, software
Simon Cooksey 0:fb7af294d5d9 14 * distributed under the License is distributed on an "AS IS" BASIS,
Simon Cooksey 0:fb7af294d5d9 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Simon Cooksey 0:fb7af294d5d9 16 * See the License for the specific language governing permissions and
Simon Cooksey 0:fb7af294d5d9 17 * limitations under the License.
Simon Cooksey 0:fb7af294d5d9 18 */
Simon Cooksey 0:fb7af294d5d9 19
Simon Cooksey 0:fb7af294d5d9 20 #ifndef NETWORK_STACK_H
Simon Cooksey 0:fb7af294d5d9 21 #define NETWORK_STACK_H
Simon Cooksey 0:fb7af294d5d9 22
Simon Cooksey 0:fb7af294d5d9 23 #include "nsapi_types.h"
Simon Cooksey 0:fb7af294d5d9 24 #include "netsocket/SocketAddress.h"
Simon Cooksey 0:fb7af294d5d9 25 #include "netsocket/NetworkInterface.h"
Simon Cooksey 0:fb7af294d5d9 26
Simon Cooksey 0:fb7af294d5d9 27
Simon Cooksey 0:fb7af294d5d9 28 /** NetworkStack class
Simon Cooksey 0:fb7af294d5d9 29 *
Simon Cooksey 0:fb7af294d5d9 30 * Common interface that is shared between hardware that
Simon Cooksey 0:fb7af294d5d9 31 * can connect to a network over IP. By implementing the
Simon Cooksey 0:fb7af294d5d9 32 * NetworkStack, a network stack can be used as a target
Simon Cooksey 0:fb7af294d5d9 33 * for instantiating network sockets.
Simon Cooksey 0:fb7af294d5d9 34 */
Simon Cooksey 0:fb7af294d5d9 35 class NetworkStack
Simon Cooksey 0:fb7af294d5d9 36 {
Simon Cooksey 0:fb7af294d5d9 37 public:
Simon Cooksey 0:fb7af294d5d9 38 virtual ~NetworkStack() {};
Simon Cooksey 0:fb7af294d5d9 39
Simon Cooksey 0:fb7af294d5d9 40 /** Get the local IP address
Simon Cooksey 0:fb7af294d5d9 41 *
Simon Cooksey 0:fb7af294d5d9 42 * @return Null-terminated representation of the local IP address
Simon Cooksey 0:fb7af294d5d9 43 * or null if not yet connected
Simon Cooksey 0:fb7af294d5d9 44 */
Simon Cooksey 0:fb7af294d5d9 45 virtual const char *get_ip_address() = 0;
Simon Cooksey 0:fb7af294d5d9 46
Simon Cooksey 0:fb7af294d5d9 47 /** Translates a hostname to an IP address with specific version
Simon Cooksey 0:fb7af294d5d9 48 *
Simon Cooksey 0:fb7af294d5d9 49 * The hostname may be either a domain name or an IP address. If the
Simon Cooksey 0:fb7af294d5d9 50 * hostname is an IP address, no network transactions will be performed.
Simon Cooksey 0:fb7af294d5d9 51 *
Simon Cooksey 0:fb7af294d5d9 52 * If no stack-specific DNS resolution is provided, the hostname
Simon Cooksey 0:fb7af294d5d9 53 * will be resolve using a UDP socket on the stack.
Simon Cooksey 0:fb7af294d5d9 54 *
Simon Cooksey 0:fb7af294d5d9 55 * @param host Hostname to resolve
Simon Cooksey 0:fb7af294d5d9 56 * @param address Destination for the host SocketAddress
Simon Cooksey 0:fb7af294d5d9 57 * @param version IP version of address to resolve, NSAPI_UNSPEC indicates
Simon Cooksey 0:fb7af294d5d9 58 * version is chosen by the stack (defaults to NSAPI_UNSPEC)
Simon Cooksey 0:fb7af294d5d9 59 * @return 0 on success, negative error code on failure
Simon Cooksey 0:fb7af294d5d9 60 */
Simon Cooksey 0:fb7af294d5d9 61 virtual int gethostbyname(const char *host, SocketAddress *address, nsapi_version_t version = NSAPI_UNSPEC);
Simon Cooksey 0:fb7af294d5d9 62
Simon Cooksey 0:fb7af294d5d9 63 /** Add a domain name server to list of servers to query
Simon Cooksey 0:fb7af294d5d9 64 *
Simon Cooksey 0:fb7af294d5d9 65 * @param addr Destination for the host address
Simon Cooksey 0:fb7af294d5d9 66 * @return 0 on success, negative error code on failure
Simon Cooksey 0:fb7af294d5d9 67 */
Simon Cooksey 0:fb7af294d5d9 68 virtual int add_dns_server(const SocketAddress &address);
Simon Cooksey 0:fb7af294d5d9 69
Simon Cooksey 0:fb7af294d5d9 70 /* Set stack-specific stack options
Simon Cooksey 0:fb7af294d5d9 71 *
Simon Cooksey 0:fb7af294d5d9 72 * The setstackopt allow an application to pass stack-specific hints
Simon Cooksey 0:fb7af294d5d9 73 * to the underlying stack. For unsupported options,
Simon Cooksey 0:fb7af294d5d9 74 * NSAPI_ERROR_UNSUPPORTED is returned and the stack is unmodified.
Simon Cooksey 0:fb7af294d5d9 75 *
Simon Cooksey 0:fb7af294d5d9 76 * @param level Stack-specific protocol level
Simon Cooksey 0:fb7af294d5d9 77 * @param optname Stack-specific option identifier
Simon Cooksey 0:fb7af294d5d9 78 * @param optval Option value
Simon Cooksey 0:fb7af294d5d9 79 * @param optlen Length of the option value
Simon Cooksey 0:fb7af294d5d9 80 * @return 0 on success, negative error code on failure
Simon Cooksey 0:fb7af294d5d9 81 */
Simon Cooksey 0:fb7af294d5d9 82 virtual int setstackopt(int level, int optname, const void *optval, unsigned optlen);
Simon Cooksey 0:fb7af294d5d9 83
Simon Cooksey 0:fb7af294d5d9 84 /* Get stack-specific stack options
Simon Cooksey 0:fb7af294d5d9 85 *
Simon Cooksey 0:fb7af294d5d9 86 * The getstackopt allow an application to retrieve stack-specific hints
Simon Cooksey 0:fb7af294d5d9 87 * from the underlying stack. For unsupported options,
Simon Cooksey 0:fb7af294d5d9 88 * NSAPI_ERROR_UNSUPPORTED is returned and optval is unmodified.
Simon Cooksey 0:fb7af294d5d9 89 *
Simon Cooksey 0:fb7af294d5d9 90 * @param level Stack-specific protocol level
Simon Cooksey 0:fb7af294d5d9 91 * @param optname Stack-specific option identifier
Simon Cooksey 0:fb7af294d5d9 92 * @param optval Destination for option value
Simon Cooksey 0:fb7af294d5d9 93 * @param optlen Length of the option value
Simon Cooksey 0:fb7af294d5d9 94 * @return 0 on success, negative error code on failure
Simon Cooksey 0:fb7af294d5d9 95 */
Simon Cooksey 0:fb7af294d5d9 96 virtual int getstackopt(int level, int optname, void *optval, unsigned *optlen);
Simon Cooksey 0:fb7af294d5d9 97
Simon Cooksey 0:fb7af294d5d9 98 protected:
Simon Cooksey 0:fb7af294d5d9 99 friend class Socket;
Simon Cooksey 0:fb7af294d5d9 100 friend class UDPSocket;
Simon Cooksey 0:fb7af294d5d9 101 friend class TCPSocket;
Simon Cooksey 0:fb7af294d5d9 102 friend class TCPServer;
Simon Cooksey 0:fb7af294d5d9 103
Simon Cooksey 0:fb7af294d5d9 104 /** Opens a socket
Simon Cooksey 0:fb7af294d5d9 105 *
Simon Cooksey 0:fb7af294d5d9 106 * Creates a network socket and stores it in the specified handle.
Simon Cooksey 0:fb7af294d5d9 107 * The handle must be passed to following calls on the socket.
Simon Cooksey 0:fb7af294d5d9 108 *
Simon Cooksey 0:fb7af294d5d9 109 * A stack may have a finite number of sockets, in this case
Simon Cooksey 0:fb7af294d5d9 110 * NSAPI_ERROR_NO_SOCKET is returned if no socket is available.
Simon Cooksey 0:fb7af294d5d9 111 *
Simon Cooksey 0:fb7af294d5d9 112 * @param handle Destination for the handle to a newly created socket
Simon Cooksey 0:fb7af294d5d9 113 * @param proto Protocol of socket to open, NSAPI_TCP or NSAPI_UDP
Simon Cooksey 0:fb7af294d5d9 114 * @return 0 on success, negative error code on failure
Simon Cooksey 0:fb7af294d5d9 115 */
Simon Cooksey 0:fb7af294d5d9 116 virtual int socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto) = 0;
Simon Cooksey 0:fb7af294d5d9 117
Simon Cooksey 0:fb7af294d5d9 118 /** Close the socket
Simon Cooksey 0:fb7af294d5d9 119 *
Simon Cooksey 0:fb7af294d5d9 120 * Closes any open connection and deallocates any memory associated
Simon Cooksey 0:fb7af294d5d9 121 * with the socket.
Simon Cooksey 0:fb7af294d5d9 122 *
Simon Cooksey 0:fb7af294d5d9 123 * @param handle Socket handle
Simon Cooksey 0:fb7af294d5d9 124 * @return 0 on success, negative error code on failure
Simon Cooksey 0:fb7af294d5d9 125 */
Simon Cooksey 0:fb7af294d5d9 126 virtual int socket_close(nsapi_socket_t handle) = 0;
Simon Cooksey 0:fb7af294d5d9 127
Simon Cooksey 0:fb7af294d5d9 128 /** Bind a specific address to a socket
Simon Cooksey 0:fb7af294d5d9 129 *
Simon Cooksey 0:fb7af294d5d9 130 * Binding a socket specifies the address and port on which to recieve
Simon Cooksey 0:fb7af294d5d9 131 * data. If the IP address is zeroed, only the port is bound.
Simon Cooksey 0:fb7af294d5d9 132 *
Simon Cooksey 0:fb7af294d5d9 133 * @param handle Socket handle
Simon Cooksey 0:fb7af294d5d9 134 * @param address Local address to bind
Simon Cooksey 0:fb7af294d5d9 135 * @return 0 on success, negative error code on failure.
Simon Cooksey 0:fb7af294d5d9 136 */
Simon Cooksey 0:fb7af294d5d9 137 virtual int socket_bind(nsapi_socket_t handle, const SocketAddress &address) = 0;
Simon Cooksey 0:fb7af294d5d9 138
Simon Cooksey 0:fb7af294d5d9 139 /** Listen for connections on a TCP socket
Simon Cooksey 0:fb7af294d5d9 140 *
Simon Cooksey 0:fb7af294d5d9 141 * Marks the socket as a passive socket that can be used to accept
Simon Cooksey 0:fb7af294d5d9 142 * incoming connections.
Simon Cooksey 0:fb7af294d5d9 143 *
Simon Cooksey 0:fb7af294d5d9 144 * @param handle Socket handle
Simon Cooksey 0:fb7af294d5d9 145 * @param backlog Number of pending connections that can be queued
Simon Cooksey 0:fb7af294d5d9 146 * simultaneously
Simon Cooksey 0:fb7af294d5d9 147 * @return 0 on success, negative error code on failure
Simon Cooksey 0:fb7af294d5d9 148 */
Simon Cooksey 0:fb7af294d5d9 149 virtual int socket_listen(nsapi_socket_t handle, int backlog) = 0;
Simon Cooksey 0:fb7af294d5d9 150
Simon Cooksey 0:fb7af294d5d9 151 /** Connects TCP socket to a remote host
Simon Cooksey 0:fb7af294d5d9 152 *
Simon Cooksey 0:fb7af294d5d9 153 * Initiates a connection to a remote server specified by the
Simon Cooksey 0:fb7af294d5d9 154 * indicated address.
Simon Cooksey 0:fb7af294d5d9 155 *
Simon Cooksey 0:fb7af294d5d9 156 * @param handle Socket handle
Simon Cooksey 0:fb7af294d5d9 157 * @param address The SocketAddress of the remote host
Simon Cooksey 0:fb7af294d5d9 158 * @return 0 on success, negative error code on failure
Simon Cooksey 0:fb7af294d5d9 159 */
Simon Cooksey 0:fb7af294d5d9 160 virtual int socket_connect(nsapi_socket_t handle, const SocketAddress &address) = 0;
Simon Cooksey 0:fb7af294d5d9 161
Simon Cooksey 0:fb7af294d5d9 162 /** Accepts a connection on a TCP socket
Simon Cooksey 0:fb7af294d5d9 163 *
Simon Cooksey 0:fb7af294d5d9 164 * The server socket must be bound and set to listen for connections.
Simon Cooksey 0:fb7af294d5d9 165 * On a new connection, creates a network socket and stores it in the
Simon Cooksey 0:fb7af294d5d9 166 * specified handle. The handle must be passed to following calls on
Simon Cooksey 0:fb7af294d5d9 167 * the socket.
Simon Cooksey 0:fb7af294d5d9 168 *
Simon Cooksey 0:fb7af294d5d9 169 * A stack may have a finite number of sockets, in this case
Simon Cooksey 0:fb7af294d5d9 170 * NSAPI_ERROR_NO_SOCKET is returned if no socket is available.
Simon Cooksey 0:fb7af294d5d9 171 *
Simon Cooksey 0:fb7af294d5d9 172 * This call is non-blocking. If accept would block,
Simon Cooksey 0:fb7af294d5d9 173 * NSAPI_ERROR_WOULD_BLOCK is returned immediately.
Simon Cooksey 0:fb7af294d5d9 174 *
Simon Cooksey 0:fb7af294d5d9 175 * @param server Socket handle to server to accept from
Simon Cooksey 0:fb7af294d5d9 176 * @param handle Destination for a handle to the newly created socket
Simon Cooksey 0:fb7af294d5d9 177 * @param address Destination for the remote address or NULL
Simon Cooksey 0:fb7af294d5d9 178 * @return 0 on success, negative error code on failure
Simon Cooksey 0:fb7af294d5d9 179 */
Simon Cooksey 0:fb7af294d5d9 180 virtual int socket_accept(nsapi_socket_t server, nsapi_socket_t *handle, SocketAddress *address=0) = 0;
Simon Cooksey 0:fb7af294d5d9 181
Simon Cooksey 0:fb7af294d5d9 182 /** Send data over a TCP socket
Simon Cooksey 0:fb7af294d5d9 183 *
Simon Cooksey 0:fb7af294d5d9 184 * The socket must be connected to a remote host. Returns the number of
Simon Cooksey 0:fb7af294d5d9 185 * bytes sent from the buffer.
Simon Cooksey 0:fb7af294d5d9 186 *
Simon Cooksey 0:fb7af294d5d9 187 * This call is non-blocking. If send would block,
Simon Cooksey 0:fb7af294d5d9 188 * NSAPI_ERROR_WOULD_BLOCK is returned immediately.
Simon Cooksey 0:fb7af294d5d9 189 *
Simon Cooksey 0:fb7af294d5d9 190 * @param handle Socket handle
Simon Cooksey 0:fb7af294d5d9 191 * @param data Buffer of data to send to the host
Simon Cooksey 0:fb7af294d5d9 192 * @param size Size of the buffer in bytes
Simon Cooksey 0:fb7af294d5d9 193 * @return Number of sent bytes on success, negative error
Simon Cooksey 0:fb7af294d5d9 194 * code on failure
Simon Cooksey 0:fb7af294d5d9 195 */
Simon Cooksey 0:fb7af294d5d9 196 virtual int socket_send(nsapi_socket_t handle, const void *data, unsigned size) = 0;
Simon Cooksey 0:fb7af294d5d9 197
Simon Cooksey 0:fb7af294d5d9 198 /** Receive data over a TCP socket
Simon Cooksey 0:fb7af294d5d9 199 *
Simon Cooksey 0:fb7af294d5d9 200 * The socket must be connected to a remote host. Returns the number of
Simon Cooksey 0:fb7af294d5d9 201 * bytes received into the buffer.
Simon Cooksey 0:fb7af294d5d9 202 *
Simon Cooksey 0:fb7af294d5d9 203 * This call is non-blocking. If recv would block,
Simon Cooksey 0:fb7af294d5d9 204 * NSAPI_ERROR_WOULD_BLOCK is returned immediately.
Simon Cooksey 0:fb7af294d5d9 205 *
Simon Cooksey 0:fb7af294d5d9 206 * @param handle Socket handle
Simon Cooksey 0:fb7af294d5d9 207 * @param data Destination buffer for data received from the host
Simon Cooksey 0:fb7af294d5d9 208 * @param size Size of the buffer in bytes
Simon Cooksey 0:fb7af294d5d9 209 * @return Number of received bytes on success, negative error
Simon Cooksey 0:fb7af294d5d9 210 * code on failure
Simon Cooksey 0:fb7af294d5d9 211 */
Simon Cooksey 0:fb7af294d5d9 212 virtual int socket_recv(nsapi_socket_t handle, void *data, unsigned size) = 0;
Simon Cooksey 0:fb7af294d5d9 213
Simon Cooksey 0:fb7af294d5d9 214 /** Send a packet over a UDP socket
Simon Cooksey 0:fb7af294d5d9 215 *
Simon Cooksey 0:fb7af294d5d9 216 * Sends data to the specified address. Returns the number of bytes
Simon Cooksey 0:fb7af294d5d9 217 * sent from the buffer.
Simon Cooksey 0:fb7af294d5d9 218 *
Simon Cooksey 0:fb7af294d5d9 219 * This call is non-blocking. If sendto would block,
Simon Cooksey 0:fb7af294d5d9 220 * NSAPI_ERROR_WOULD_BLOCK is returned immediately.
Simon Cooksey 0:fb7af294d5d9 221 *
Simon Cooksey 0:fb7af294d5d9 222 * @param handle Socket handle
Simon Cooksey 0:fb7af294d5d9 223 * @param address The SocketAddress of the remote host
Simon Cooksey 0:fb7af294d5d9 224 * @param data Buffer of data to send to the host
Simon Cooksey 0:fb7af294d5d9 225 * @param size Size of the buffer in bytes
Simon Cooksey 0:fb7af294d5d9 226 * @return Number of sent bytes on success, negative error
Simon Cooksey 0:fb7af294d5d9 227 * code on failure
Simon Cooksey 0:fb7af294d5d9 228 */
Simon Cooksey 0:fb7af294d5d9 229 virtual int socket_sendto(nsapi_socket_t handle, const SocketAddress &address, const void *data, unsigned size) = 0;
Simon Cooksey 0:fb7af294d5d9 230
Simon Cooksey 0:fb7af294d5d9 231 /** Receive a packet over a UDP socket
Simon Cooksey 0:fb7af294d5d9 232 *
Simon Cooksey 0:fb7af294d5d9 233 * Receives data and stores the source address in address if address
Simon Cooksey 0:fb7af294d5d9 234 * is not NULL. Returns the number of bytes received into the buffer.
Simon Cooksey 0:fb7af294d5d9 235 *
Simon Cooksey 0:fb7af294d5d9 236 * This call is non-blocking. If recvfrom would block,
Simon Cooksey 0:fb7af294d5d9 237 * NSAPI_ERROR_WOULD_BLOCK is returned immediately.
Simon Cooksey 0:fb7af294d5d9 238 *
Simon Cooksey 0:fb7af294d5d9 239 * @param handle Socket handle
Simon Cooksey 0:fb7af294d5d9 240 * @param address Destination for the source address or NULL
Simon Cooksey 0:fb7af294d5d9 241 * @param data Destination buffer for data received from the host
Simon Cooksey 0:fb7af294d5d9 242 * @param size Size of the buffer in bytes
Simon Cooksey 0:fb7af294d5d9 243 * @return Number of received bytes on success, negative error
Simon Cooksey 0:fb7af294d5d9 244 * code on failure
Simon Cooksey 0:fb7af294d5d9 245 */
Simon Cooksey 0:fb7af294d5d9 246 virtual int socket_recvfrom(nsapi_socket_t handle, SocketAddress *address, void *buffer, unsigned size) = 0;
Simon Cooksey 0:fb7af294d5d9 247
Simon Cooksey 0:fb7af294d5d9 248 /** Register a callback on state change of the socket
Simon Cooksey 0:fb7af294d5d9 249 *
Simon Cooksey 0:fb7af294d5d9 250 * The specified callback will be called on state changes such as when
Simon Cooksey 0:fb7af294d5d9 251 * the socket can recv/send/accept successfully and on when an error
Simon Cooksey 0:fb7af294d5d9 252 * occurs. The callback may also be called spuriously without reason.
Simon Cooksey 0:fb7af294d5d9 253 *
Simon Cooksey 0:fb7af294d5d9 254 * The callback may be called in an interrupt context and should not
Simon Cooksey 0:fb7af294d5d9 255 * perform expensive operations such as recv/send calls.
Simon Cooksey 0:fb7af294d5d9 256 *
Simon Cooksey 0:fb7af294d5d9 257 * @param handle Socket handle
Simon Cooksey 0:fb7af294d5d9 258 * @param callback Function to call on state change
Simon Cooksey 0:fb7af294d5d9 259 * @param data Argument to pass to callback
Simon Cooksey 0:fb7af294d5d9 260 */
Simon Cooksey 0:fb7af294d5d9 261 virtual void socket_attach(nsapi_socket_t handle, void (*callback)(void *), void *data) = 0;
Simon Cooksey 0:fb7af294d5d9 262
Simon Cooksey 0:fb7af294d5d9 263 /* Set stack-specific socket options
Simon Cooksey 0:fb7af294d5d9 264 *
Simon Cooksey 0:fb7af294d5d9 265 * The setsockopt allow an application to pass stack-specific hints
Simon Cooksey 0:fb7af294d5d9 266 * to the underlying stack. For unsupported options,
Simon Cooksey 0:fb7af294d5d9 267 * NSAPI_ERROR_UNSUPPORTED is returned and the socket is unmodified.
Simon Cooksey 0:fb7af294d5d9 268 *
Simon Cooksey 0:fb7af294d5d9 269 * @param handle Socket handle
Simon Cooksey 0:fb7af294d5d9 270 * @param level Stack-specific protocol level
Simon Cooksey 0:fb7af294d5d9 271 * @param optname Stack-specific option identifier
Simon Cooksey 0:fb7af294d5d9 272 * @param optval Option value
Simon Cooksey 0:fb7af294d5d9 273 * @param optlen Length of the option value
Simon Cooksey 0:fb7af294d5d9 274 * @return 0 on success, negative error code on failure
Simon Cooksey 0:fb7af294d5d9 275 */
Simon Cooksey 0:fb7af294d5d9 276 virtual int setsockopt(nsapi_socket_t handle, int level, int optname, const void *optval, unsigned optlen);
Simon Cooksey 0:fb7af294d5d9 277
Simon Cooksey 0:fb7af294d5d9 278 /* Get stack-specific socket options
Simon Cooksey 0:fb7af294d5d9 279 *
Simon Cooksey 0:fb7af294d5d9 280 * The getstackopt allow an application to retrieve stack-specific hints
Simon Cooksey 0:fb7af294d5d9 281 * from the underlying stack. For unsupported options,
Simon Cooksey 0:fb7af294d5d9 282 * NSAPI_ERROR_UNSUPPORTED is returned and optval is unmodified.
Simon Cooksey 0:fb7af294d5d9 283 *
Simon Cooksey 0:fb7af294d5d9 284 * @param handle Socket handle
Simon Cooksey 0:fb7af294d5d9 285 * @param level Stack-specific protocol level
Simon Cooksey 0:fb7af294d5d9 286 * @param optname Stack-specific option identifier
Simon Cooksey 0:fb7af294d5d9 287 * @param optval Destination for option value
Simon Cooksey 0:fb7af294d5d9 288 * @param optlen Length of the option value
Simon Cooksey 0:fb7af294d5d9 289 * @return 0 on success, negative error code on failure
Simon Cooksey 0:fb7af294d5d9 290 */
Simon Cooksey 0:fb7af294d5d9 291 virtual int getsockopt(nsapi_socket_t handle, int level, int optname, void *optval, unsigned *optlen);
Simon Cooksey 0:fb7af294d5d9 292 };
Simon Cooksey 0:fb7af294d5d9 293
Simon Cooksey 0:fb7af294d5d9 294
Simon Cooksey 0:fb7af294d5d9 295 /** Convert a raw nsapi_stack_t object into a C++ NetworkStack object
Simon Cooksey 0:fb7af294d5d9 296 *
Simon Cooksey 0:fb7af294d5d9 297 * @param stack Reference to an object that can be converted to a stack
Simon Cooksey 0:fb7af294d5d9 298 * - A raw nsapi_stack_t object
Simon Cooksey 0:fb7af294d5d9 299 * - A reference to a network stack
Simon Cooksey 0:fb7af294d5d9 300 * - A reference to a network interface
Simon Cooksey 0:fb7af294d5d9 301 * @return Reference to the underlying network stack
Simon Cooksey 0:fb7af294d5d9 302 */
Simon Cooksey 0:fb7af294d5d9 303 NetworkStack *nsapi_create_stack(nsapi_stack_t *stack);
Simon Cooksey 0:fb7af294d5d9 304 NetworkStack *nsapi_create_stack(NetworkStack *stack);
Simon Cooksey 0:fb7af294d5d9 305
Simon Cooksey 0:fb7af294d5d9 306 template <typename IF>
Simon Cooksey 0:fb7af294d5d9 307 NetworkStack *nsapi_create_stack(IF *iface)
Simon Cooksey 0:fb7af294d5d9 308 {
Simon Cooksey 0:fb7af294d5d9 309 return nsapi_create_stack(static_cast<NetworkInterface *>(iface)->get_stack());
Simon Cooksey 0:fb7af294d5d9 310 }
Simon Cooksey 0:fb7af294d5d9 311
Simon Cooksey 0:fb7af294d5d9 312
Simon Cooksey 0:fb7af294d5d9 313 #endif
Simon Cooksey 0:fb7af294d5d9 314
Simon Cooksey 0:fb7af294d5d9 315 /** @}*/