Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: DnsQuery
Dependents: WizFi310_TCP_Echo_Server_Example
Fork of NetworkSocketAPI by
NetworkInterface.h@101:9caa935c3baa, 2016-04-19 (annotated)
- Committer:
- Christopher Haster
- Date:
- Tue Apr 19 18:25:52 2016 -0500
- Revision:
- 101:9caa935c3baa
- Parent:
- 99:f51358e506c1
- Child:
- 103:37decbcb1108
Revisited documentation for NetworkInterface specific methods
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Christopher Haster |
89:b1d417383c0d | 1 | /* Socket |
| Christopher Haster |
89:b1d417383c0d | 2 | * Copyright (c) 2015 ARM Limited |
| Christopher Haster |
89:b1d417383c0d | 3 | * |
| Christopher Haster |
89:b1d417383c0d | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| Christopher Haster |
89:b1d417383c0d | 5 | * you may not use this file except in compliance with the License. |
| Christopher Haster |
89:b1d417383c0d | 6 | * You may obtain a copy of the License at |
| Christopher Haster |
89:b1d417383c0d | 7 | * |
| Christopher Haster |
89:b1d417383c0d | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| Christopher Haster |
89:b1d417383c0d | 9 | * |
| Christopher Haster |
89:b1d417383c0d | 10 | * Unless required by applicable law or agreed to in writing, software |
| Christopher Haster |
89:b1d417383c0d | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| Christopher Haster |
89:b1d417383c0d | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| Christopher Haster |
89:b1d417383c0d | 13 | * See the License for the specific language governing permissions and |
| Christopher Haster |
89:b1d417383c0d | 14 | * limitations under the License. |
| Christopher Haster |
89:b1d417383c0d | 15 | */ |
| Christopher Haster |
89:b1d417383c0d | 16 | |
| Christopher Haster |
89:b1d417383c0d | 17 | #ifndef NETWORK_INTERFACE_H |
| Christopher Haster |
89:b1d417383c0d | 18 | #define NETWORK_INTERFACE_H |
| Christopher Haster |
89:b1d417383c0d | 19 | |
| Christopher Haster |
89:b1d417383c0d | 20 | #include "mbed.h" |
| Christopher Haster |
89:b1d417383c0d | 21 | #include "SocketAddress.h" |
| Christopher Haster |
89:b1d417383c0d | 22 | |
| Christopher Haster |
94:644df37bb05b | 23 | |
| Christopher Haster |
101:9caa935c3baa | 24 | /** Enum of standardized error codes |
| Christopher Haster |
101:9caa935c3baa | 25 | * |
| Christopher Haster |
101:9caa935c3baa | 26 | * Valid error codes have negative values and may |
| Christopher Haster |
101:9caa935c3baa | 27 | * be returned by any network operation. |
| Christopher Haster |
101:9caa935c3baa | 28 | * |
| Christopher Haster |
96:656011e49d9f | 29 | * @enum nsapi_error_t |
| Christopher Haster |
89:b1d417383c0d | 30 | */ |
| Christopher Haster |
89:b1d417383c0d | 31 | enum nsapi_error_t { |
| Christopher Haster |
89:b1d417383c0d | 32 | NSAPI_ERROR_WOULD_BLOCK = -3001, /*!< no data is not available but call is non-blocking */ |
| Christopher Haster |
89:b1d417383c0d | 33 | NSAPI_ERROR_UNSUPPORTED = -3002, /*!< unsupported configuration */ |
| Christopher Haster |
89:b1d417383c0d | 34 | NSAPI_ERROR_NO_CONNECTION = -3003, /*!< not connected to a network */ |
| Christopher Haster |
89:b1d417383c0d | 35 | NSAPI_ERROR_NO_SOCKET = -3004, /*!< socket not available for use */ |
| Christopher Haster |
89:b1d417383c0d | 36 | NSAPI_ERROR_NO_ADDRESS = -3005, /*!< IP address is not known */ |
| Christopher Haster |
89:b1d417383c0d | 37 | NSAPI_ERROR_NO_MEMORY = -3006, /*!< memory resource not available */ |
| Christopher Haster |
89:b1d417383c0d | 38 | NSAPI_ERROR_DNS_FAILURE = -3007, /*!< DNS failed to complete successfully */ |
| Christopher Haster |
89:b1d417383c0d | 39 | NSAPI_ERROR_DHCP_FAILURE = -3008, /*!< DHCP failed to complete successfully */ |
| Christopher Haster |
89:b1d417383c0d | 40 | NSAPI_ERROR_AUTH_FAILURE = -3009, /*!< connection to access point faield */ |
| Christopher Haster |
89:b1d417383c0d | 41 | NSAPI_ERROR_DEVICE_ERROR = -3010, /*!< failure interfacing with the network procesor */ |
| Christopher Haster |
89:b1d417383c0d | 42 | }; |
| Christopher Haster |
89:b1d417383c0d | 43 | |
| Christopher Haster |
89:b1d417383c0d | 44 | /** Enum of socket protocols |
| Christopher Haster |
101:9caa935c3baa | 45 | * |
| Christopher Haster |
101:9caa935c3baa | 46 | * The socket protocol specifies a particular protocol to |
| Christopher Haster |
101:9caa935c3baa | 47 | * be used with a newly created socket. |
| Christopher Haster |
101:9caa935c3baa | 48 | * |
| Christopher Haster |
89:b1d417383c0d | 49 | * @enum protocol_t |
| Christopher Haster |
89:b1d417383c0d | 50 | */ |
| Christopher Haster |
89:b1d417383c0d | 51 | enum nsapi_protocol_t { |
| Christopher Haster |
89:b1d417383c0d | 52 | NSAPI_TCP, /*!< Socket is of TCP type */ |
| Christopher Haster |
89:b1d417383c0d | 53 | NSAPI_UDP, /*!< Socket is of UDP type */ |
| Christopher Haster |
89:b1d417383c0d | 54 | }; |
| Christopher Haster |
89:b1d417383c0d | 55 | |
| Christopher Haster |
94:644df37bb05b | 56 | /** Maximum size of MAC address representation |
| Christopher Haster |
94:644df37bb05b | 57 | */ |
| Christopher Haster |
94:644df37bb05b | 58 | #define NSAPI_MAC_SIZE 18 |
| Christopher Haster |
94:644df37bb05b | 59 | |
| Christopher Haster |
94:644df37bb05b | 60 | /** Maximum number of bytes for MAC address |
| Christopher Haster |
94:644df37bb05b | 61 | */ |
| Christopher Haster |
94:644df37bb05b | 62 | #define NSAPI_MAC_BYTES 6 |
| Christopher Haster |
94:644df37bb05b | 63 | |
| Christopher Haster |
94:644df37bb05b | 64 | |
| Christopher Haster |
89:b1d417383c0d | 65 | /** NetworkInterface class |
| Christopher Haster |
101:9caa935c3baa | 66 | * |
| Christopher Haster |
101:9caa935c3baa | 67 | * Common interface that is shared between hardware that |
| Christopher Haster |
101:9caa935c3baa | 68 | * can connect to a network over IP. By implementing the |
| Christopher Haster |
101:9caa935c3baa | 69 | * NetworkInterface, a network stack can be used as a target |
| Christopher Haster |
101:9caa935c3baa | 70 | * for instantiating network sockets. |
| Christopher Haster |
89:b1d417383c0d | 71 | */ |
| Christopher Haster |
89:b1d417383c0d | 72 | class NetworkInterface |
| Christopher Haster |
89:b1d417383c0d | 73 | { |
| Christopher Haster |
89:b1d417383c0d | 74 | public: |
| Christopher Haster |
89:b1d417383c0d | 75 | virtual ~NetworkInterface() {}; |
| Christopher Haster |
89:b1d417383c0d | 76 | |
| Christopher Haster |
89:b1d417383c0d | 77 | /** Get the internally stored IP address |
| Christopher Haster |
101:9caa935c3baa | 78 | * |
| Christopher Haster |
89:b1d417383c0d | 79 | * @return IP address of the interface or null if not yet connected |
| Christopher Haster |
89:b1d417383c0d | 80 | */ |
| Christopher Haster |
89:b1d417383c0d | 81 | virtual const char *get_ip_address() = 0; |
| Christopher Haster |
89:b1d417383c0d | 82 | |
| Christopher Haster |
89:b1d417383c0d | 83 | /** Get the internally stored MAC address |
| Christopher Haster |
101:9caa935c3baa | 84 | * |
| Christopher Haster |
89:b1d417383c0d | 85 | * @return MAC address of the interface |
| Christopher Haster |
89:b1d417383c0d | 86 | */ |
| Christopher Haster |
89:b1d417383c0d | 87 | virtual const char *get_mac_address() = 0; |
| Christopher Haster |
89:b1d417383c0d | 88 | |
| Christopher Haster |
101:9caa935c3baa | 89 | /** Translates a host name to an IP address |
| Christopher Haster |
101:9caa935c3baa | 90 | * |
| Christopher Haster |
101:9caa935c3baa | 91 | * The host name may be either a domain name or an IP address. |
| Christopher Haster |
101:9caa935c3baa | 92 | * If no stack-specific DNS resolution is provided, the host name |
| Christopher Haster |
101:9caa935c3baa | 93 | * will be resolve using a UDP socket on the stack. |
| Christopher Haster |
101:9caa935c3baa | 94 | * |
| Christopher Haster |
95:b3c679f20d13 | 95 | * @param address Destination for the host SocketAddress |
| Christopher Haster |
101:9caa935c3baa | 96 | * @param host Host name to lookup |
| Christopher Haster |
101:9caa935c3baa | 97 | * @return 0 on success, negative error code on failure |
| Christopher Haster |
89:b1d417383c0d | 98 | */ |
| Christopher Haster |
101:9caa935c3baa | 99 | virtual int gethostbyname(SocketAddress *address, const char *host); |
| Christopher Haster |
89:b1d417383c0d | 100 | |
| Christopher Haster |
101:9caa935c3baa | 101 | /* Set stack-specific stack options |
| Christopher Haster |
101:9caa935c3baa | 102 | * |
| Christopher Haster |
101:9caa935c3baa | 103 | * The setstackopt allow an application to pass stack-specific hints |
| Christopher Haster |
101:9caa935c3baa | 104 | * to the underlying stack. For unsupported options, |
| Christopher Haster |
101:9caa935c3baa | 105 | * NSAPI_ERROR_UNSUPPORTED is returned and the stack is unmodified. |
| Christopher Haster |
101:9caa935c3baa | 106 | * |
| Christopher Haster |
101:9caa935c3baa | 107 | * @param level Stack-specific protocol level |
| Christopher Haster |
101:9caa935c3baa | 108 | * @param optname Stack-specific option identifier |
| Christopher Haster |
99:f51358e506c1 | 109 | * @param optval Option value |
| Christopher Haster |
99:f51358e506c1 | 110 | * @param optlen Length of the option value |
| Christopher Haster |
101:9caa935c3baa | 111 | * @return 0 on success, negative error code on failure |
| Christopher Haster |
99:f51358e506c1 | 112 | */ |
| Christopher Haster |
99:f51358e506c1 | 113 | virtual int setstackopt(int level, int optname, const void *optval, unsigned optlen); |
| Christopher Haster |
99:f51358e506c1 | 114 | |
| Christopher Haster |
101:9caa935c3baa | 115 | /* Get stack-specific stack options |
| Christopher Haster |
101:9caa935c3baa | 116 | * |
| Christopher Haster |
101:9caa935c3baa | 117 | * The getstackopt allow an application to retrieve stack-specific hints |
| Christopher Haster |
101:9caa935c3baa | 118 | * from the underlying stack. For unsupported options, |
| Christopher Haster |
101:9caa935c3baa | 119 | * NSAPI_ERROR_UNSUPPORTED is returned and optval is unmodified. |
| Christopher Haster |
101:9caa935c3baa | 120 | * |
| Christopher Haster |
101:9caa935c3baa | 121 | * @param level Stack-specific protocol level |
| Christopher Haster |
101:9caa935c3baa | 122 | * @param optname Stack-specific option identifier |
| Christopher Haster |
101:9caa935c3baa | 123 | * @param optval Destination for option value |
| Christopher Haster |
99:f51358e506c1 | 124 | * @param optlen Length of the option value |
| Christopher Haster |
101:9caa935c3baa | 125 | * @return 0 on success, negative error code on failure |
| Christopher Haster |
99:f51358e506c1 | 126 | */ |
| Christopher Haster |
99:f51358e506c1 | 127 | virtual int getstackopt(int level, int optname, void *optval, unsigned *optlen); |
| Christopher Haster |
99:f51358e506c1 | 128 | |
| Christopher Haster |
89:b1d417383c0d | 129 | protected: |
| Christopher Haster |
89:b1d417383c0d | 130 | friend class Socket; |
| Christopher Haster |
89:b1d417383c0d | 131 | friend class UDPSocket; |
| Christopher Haster |
89:b1d417383c0d | 132 | friend class TCPSocket; |
| Christopher Haster |
89:b1d417383c0d | 133 | friend class TCPServer; |
| Christopher Haster |
89:b1d417383c0d | 134 | |
| Christopher Haster |
101:9caa935c3baa | 135 | /** Opens a socket |
| Christopher Haster |
101:9caa935c3baa | 136 | * |
| Christopher Haster |
101:9caa935c3baa | 137 | * Creates a socket for communication and stores it in the specified |
| Christopher Haster |
101:9caa935c3baa | 138 | * handle. The handle must be passed to following calls on the socket. |
| Christopher Haster |
101:9caa935c3baa | 139 | * |
| Christopher Haster |
101:9caa935c3baa | 140 | * A stack may have a finite number of sockets, in this case |
| Christopher Haster |
101:9caa935c3baa | 141 | * NSAPI_ERROR_NO_SOCKET is returned if no socket is available. |
| Christopher Haster |
101:9caa935c3baa | 142 | * |
| Christopher Haster |
101:9caa935c3baa | 143 | * @param handle Destination for the handle to a newly created socket |
| Christopher Haster |
101:9caa935c3baa | 144 | * @param proto Protocol of socket to open, NSAPI_TCP or NSAPI_UDP |
| Christopher Haster |
101:9caa935c3baa | 145 | * @return 0 on success, negative error code on failure |
| Christopher Haster |
89:b1d417383c0d | 146 | */ |
| Christopher Haster |
93:65a9f84862f0 | 147 | virtual int socket_open(void **handle, nsapi_protocol_t proto) = 0; |
| Christopher Haster |
89:b1d417383c0d | 148 | |
| Christopher Haster |
93:65a9f84862f0 | 149 | /** Close the socket |
| Christopher Haster |
101:9caa935c3baa | 150 | * |
| Christopher Haster |
101:9caa935c3baa | 151 | * Closes any open connection and deallocates any memory associated with |
| Christopher Haster |
101:9caa935c3baa | 152 | * the socket. |
| Christopher Haster |
101:9caa935c3baa | 153 | * |
| Christopher Haster |
93:65a9f84862f0 | 154 | * @param handle Socket handle |
| Christopher Haster |
101:9caa935c3baa | 155 | * @return 0 on success, negative error code on failure |
| Christopher Haster |
89:b1d417383c0d | 156 | */ |
| Christopher Haster |
93:65a9f84862f0 | 157 | virtual int socket_close(void *handle) = 0; |
| Christopher Haster |
89:b1d417383c0d | 158 | |
| Christopher Haster |
101:9caa935c3baa | 159 | /** Bind a specific address to a socket |
| Christopher Haster |
101:9caa935c3baa | 160 | * |
| Christopher Haster |
101:9caa935c3baa | 161 | * Binding a socket specifies the address and port on which to recieve |
| Christopher Haster |
101:9caa935c3baa | 162 | * data. If the IP address is zeroed, only the port is bound. |
| Christopher Haster |
101:9caa935c3baa | 163 | * |
| Christopher Haster |
89:b1d417383c0d | 164 | * @param handle Socket handle |
| Christopher Haster |
101:9caa935c3baa | 165 | * @param address Local address to bind |
| Christopher Haster |
101:9caa935c3baa | 166 | * @return 0 on success, negative error code on failure. |
| Christopher Haster |
89:b1d417383c0d | 167 | */ |
| Christopher Haster |
96:656011e49d9f | 168 | virtual int socket_bind(void *handle, const SocketAddress &address) = 0; |
| Christopher Haster |
89:b1d417383c0d | 169 | |
| Christopher Haster |
101:9caa935c3baa | 170 | /** Listen for connections on a TCP socket |
| Christopher Haster |
101:9caa935c3baa | 171 | * |
| Christopher Haster |
101:9caa935c3baa | 172 | * Marks the socket as a passive socket that can be used to accept |
| Christopher Haster |
101:9caa935c3baa | 173 | * incoming connections. |
| Christopher Haster |
101:9caa935c3baa | 174 | * |
| Christopher Haster |
89:b1d417383c0d | 175 | * @param handle Socket handle |
| Christopher Haster |
101:9caa935c3baa | 176 | * @param backlog Number of pending connections that can be queued |
| Christopher Haster |
101:9caa935c3baa | 177 | * simultaneously, defaults to 1 |
| Christopher Haster |
101:9caa935c3baa | 178 | * @return 0 on success, negative error code on failure |
| Christopher Haster |
89:b1d417383c0d | 179 | */ |
| Christopher Haster |
89:b1d417383c0d | 180 | virtual int socket_listen(void *handle, int backlog) = 0; |
| Christopher Haster |
89:b1d417383c0d | 181 | |
| Christopher Haster |
101:9caa935c3baa | 182 | /** Connects TCP socket to a remote host |
| Christopher Haster |
101:9caa935c3baa | 183 | * |
| Christopher Haster |
101:9caa935c3baa | 184 | * Initiates a connection to a remote server specified by the |
| Christopher Haster |
101:9caa935c3baa | 185 | * indicated address. |
| Christopher Haster |
101:9caa935c3baa | 186 | * |
| Christopher Haster |
89:b1d417383c0d | 187 | * @param handle Socket handle |
| Christopher Haster |
101:9caa935c3baa | 188 | * @param address The SocketAddress of the remote host |
| Christopher Haster |
101:9caa935c3baa | 189 | * @return 0 on success, negative error code on failure |
| Christopher Haster |
89:b1d417383c0d | 190 | */ |
| Christopher Haster |
89:b1d417383c0d | 191 | virtual int socket_connect(void *handle, const SocketAddress &address) = 0; |
| Christopher Haster |
89:b1d417383c0d | 192 | |
| Christopher Haster |
101:9caa935c3baa | 193 | /** Accepts a connection on a TCP socket |
| Christopher Haster |
101:9caa935c3baa | 194 | * |
| Christopher Haster |
101:9caa935c3baa | 195 | * The server socket must be bound and set to listen for connections. |
| Christopher Haster |
101:9caa935c3baa | 196 | * On a new connection, creates a socket stores it in the specified |
| Christopher Haster |
101:9caa935c3baa | 197 | * handle. The handle must be passed to following calls on the socket. |
| Christopher Haster |
101:9caa935c3baa | 198 | * |
| Christopher Haster |
101:9caa935c3baa | 199 | * A stack may have a finite number of sockets, in this case |
| Christopher Haster |
101:9caa935c3baa | 200 | * NSAPI_ERROR_NO_SOCKET is returned if no socket is available. |
| Christopher Haster |
101:9caa935c3baa | 201 | * |
| Christopher Haster |
101:9caa935c3baa | 202 | * This call is non-blocking. If accept would block, |
| Christopher Haster |
101:9caa935c3baa | 203 | * NSAPI_ERROR_WOULD_BLOCK is returned immediately. |
| Christopher Haster |
101:9caa935c3baa | 204 | * |
| Christopher Haster |
101:9caa935c3baa | 205 | * @param handle Destination for a handle to the newly created sockey |
| Christopher Haster |
93:65a9f84862f0 | 206 | * @param server Socket handle to server to accept from |
| Christopher Haster |
101:9caa935c3baa | 207 | * @return 0 on success, negative error code on failure |
| Christopher Haster |
89:b1d417383c0d | 208 | */ |
| Christopher Haster |
93:65a9f84862f0 | 209 | virtual int socket_accept(void **handle, void *server) = 0; |
| Christopher Haster |
89:b1d417383c0d | 210 | |
| Christopher Haster |
101:9caa935c3baa | 211 | /** Send data over a TCP socket |
| Christopher Haster |
101:9caa935c3baa | 212 | * |
| Christopher Haster |
101:9caa935c3baa | 213 | * The socket must be connected to a remote host. Returns the number of |
| Christopher Haster |
101:9caa935c3baa | 214 | * bytes sent from the buffer. |
| Christopher Haster |
101:9caa935c3baa | 215 | * |
| Christopher Haster |
101:9caa935c3baa | 216 | * This call is non-blocking. If send would block, |
| Christopher Haster |
101:9caa935c3baa | 217 | * NSAPI_ERROR_WOULD_BLOCK is returned immediately. |
| Christopher Haster |
101:9caa935c3baa | 218 | * |
| Christopher Haster |
89:b1d417383c0d | 219 | * @param handle Socket handle |
| Christopher Haster |
101:9caa935c3baa | 220 | * @param data Buffer of data to send to the host |
| Christopher Haster |
101:9caa935c3baa | 221 | * @param size Size of the buffer in bytes |
| Christopher Haster |
101:9caa935c3baa | 222 | * @return Number of sent bytes on success, negative error |
| Christopher Haster |
101:9caa935c3baa | 223 | * code on failure |
| Christopher Haster |
89:b1d417383c0d | 224 | */ |
| Christopher Haster |
89:b1d417383c0d | 225 | virtual int socket_send(void *handle, const void *data, unsigned size) = 0; |
| Christopher Haster |
89:b1d417383c0d | 226 | |
| Christopher Haster |
101:9caa935c3baa | 227 | /** Receive data over a TCP socket |
| Christopher Haster |
101:9caa935c3baa | 228 | * |
| Christopher Haster |
101:9caa935c3baa | 229 | * The socket must be connected to a remote host. Returns the number of |
| Christopher Haster |
101:9caa935c3baa | 230 | * bytes received into the buffer. |
| Christopher Haster |
101:9caa935c3baa | 231 | * |
| Christopher Haster |
101:9caa935c3baa | 232 | * This call is non-blocking. If recv would block, |
| Christopher Haster |
101:9caa935c3baa | 233 | * NSAPI_ERROR_WOULD_BLOCK is returned immediately. |
| Christopher Haster |
101:9caa935c3baa | 234 | * |
| Christopher Haster |
89:b1d417383c0d | 235 | * @param handle Socket handle |
| Christopher Haster |
101:9caa935c3baa | 236 | * @param data Destination buffer for data received from the host |
| Christopher Haster |
101:9caa935c3baa | 237 | * @param size Size of the buffer in bytes |
| Christopher Haster |
101:9caa935c3baa | 238 | * @return Number of received bytes on success, negative error |
| Christopher Haster |
101:9caa935c3baa | 239 | * code on failure |
| Christopher Haster |
89:b1d417383c0d | 240 | */ |
| Christopher Haster |
89:b1d417383c0d | 241 | virtual int socket_recv(void *handle, void *data, unsigned size) = 0; |
| Christopher Haster |
89:b1d417383c0d | 242 | |
| Christopher Haster |
101:9caa935c3baa | 243 | /** Send a packet over a UDP socket |
| Christopher Haster |
101:9caa935c3baa | 244 | * |
| Christopher Haster |
101:9caa935c3baa | 245 | * Sends data to the specified address. Returns the number of bytes |
| Christopher Haster |
101:9caa935c3baa | 246 | * sent from the buffer. |
| Christopher Haster |
101:9caa935c3baa | 247 | * |
| Christopher Haster |
101:9caa935c3baa | 248 | * This call is non-blocking. If sendto would block, |
| Christopher Haster |
101:9caa935c3baa | 249 | * NSAPI_ERROR_WOULD_BLOCK is returned immediately. |
| Christopher Haster |
101:9caa935c3baa | 250 | * |
| Christopher Haster |
89:b1d417383c0d | 251 | * @param handle Socket handle |
| Christopher Haster |
101:9caa935c3baa | 252 | * @param address The SocketAddress of the remote host |
| Christopher Haster |
101:9caa935c3baa | 253 | * @param data Buffer of data to send to the host |
| Christopher Haster |
101:9caa935c3baa | 254 | * @param size Size of the buffer in bytes |
| Christopher Haster |
101:9caa935c3baa | 255 | * @return Number of sent bytes on success, negative error |
| Christopher Haster |
101:9caa935c3baa | 256 | * code on failure |
| Christopher Haster |
89:b1d417383c0d | 257 | */ |
| Christopher Haster |
89:b1d417383c0d | 258 | virtual int socket_sendto(void *handle, const SocketAddress &address, const void *data, unsigned size) = 0; |
| Christopher Haster |
89:b1d417383c0d | 259 | |
| Christopher Haster |
101:9caa935c3baa | 260 | /** Receive a packet over a UDP socket |
| Christopher Haster |
101:9caa935c3baa | 261 | * |
| Christopher Haster |
101:9caa935c3baa | 262 | * Receives data and stores the source address in address if address |
| Christopher Haster |
101:9caa935c3baa | 263 | * is not NULL. Returns the number of bytes received into the buffer. |
| Christopher Haster |
101:9caa935c3baa | 264 | * |
| Christopher Haster |
101:9caa935c3baa | 265 | * This call is non-blocking. If recvfrom would block, |
| Christopher Haster |
101:9caa935c3baa | 266 | * NSAPI_ERROR_WOULD_BLOCK is returned immediately. |
| Christopher Haster |
101:9caa935c3baa | 267 | * |
| Christopher Haster |
89:b1d417383c0d | 268 | * @param handle Socket handle |
| Christopher Haster |
101:9caa935c3baa | 269 | * @param address Destination for the source address or NULL |
| Christopher Haster |
101:9caa935c3baa | 270 | * @param data Destination buffer for data received from the host |
| Christopher Haster |
101:9caa935c3baa | 271 | * @param size Size of the buffer in bytes |
| Christopher Haster |
101:9caa935c3baa | 272 | * @return Number of received bytes on success, negative error |
| Christopher Haster |
101:9caa935c3baa | 273 | * code on failure |
| Christopher Haster |
89:b1d417383c0d | 274 | */ |
| Christopher Haster |
89:b1d417383c0d | 275 | virtual int socket_recvfrom(void *handle, SocketAddress *address, void *buffer, unsigned size) = 0; |
| Christopher Haster |
89:b1d417383c0d | 276 | |
| Christopher Haster |
92:dd5f19874adf | 277 | /** Register a callback on state change of the socket |
| Christopher Haster |
101:9caa935c3baa | 278 | * |
| Christopher Haster |
101:9caa935c3baa | 279 | * The specified callback will be called on state changes such as when |
| Christopher Haster |
101:9caa935c3baa | 280 | * the socket can recv/send/accept successfully and on when an error |
| Christopher Haster |
101:9caa935c3baa | 281 | * occurs. The callback may also be called spuriously without reason. |
| Christopher Haster |
101:9caa935c3baa | 282 | * |
| Christopher Haster |
101:9caa935c3baa | 283 | * The callback may be called in an interrupt context and should not |
| Christopher Haster |
101:9caa935c3baa | 284 | * perform expensive operations such as recv/send calls. |
| Christopher Haster |
101:9caa935c3baa | 285 | * |
| Christopher Haster |
89:b1d417383c0d | 286 | * @param handle Socket handle |
| Christopher Haster |
92:dd5f19874adf | 287 | * @param callback Function to call on state change |
| Christopher Haster |
92:dd5f19874adf | 288 | * @param data Argument to pass to callback |
| Christopher Haster |
89:b1d417383c0d | 289 | */ |
| Christopher Haster |
92:dd5f19874adf | 290 | virtual void socket_attach(void *handle, void (*callback)(void *), void *data) = 0; |
| Christopher Haster |
99:f51358e506c1 | 291 | |
| Christopher Haster |
101:9caa935c3baa | 292 | /* Set stack-specific socked options |
| Christopher Haster |
101:9caa935c3baa | 293 | * |
| Christopher Haster |
101:9caa935c3baa | 294 | * The setsockopt allow an application to pass stack-specific hints |
| Christopher Haster |
101:9caa935c3baa | 295 | * to the underlying stack. For unsupported options, |
| Christopher Haster |
101:9caa935c3baa | 296 | * NSAPI_ERROR_UNSUPPORTED is returned and the socket is unmodified. |
| Christopher Haster |
101:9caa935c3baa | 297 | * |
| Christopher Haster |
99:f51358e506c1 | 298 | * @param handle Socket handle |
| Christopher Haster |
101:9caa935c3baa | 299 | * @param level Stack-specific protocol level |
| Christopher Haster |
101:9caa935c3baa | 300 | * @param optname Stack-specific option identifier |
| Christopher Haster |
99:f51358e506c1 | 301 | * @param optval Option value |
| Christopher Haster |
99:f51358e506c1 | 302 | * @param optlen Length of the option value |
| Christopher Haster |
101:9caa935c3baa | 303 | * @return 0 on success, negative error code on failure |
| Christopher Haster |
99:f51358e506c1 | 304 | */ |
| Christopher Haster |
99:f51358e506c1 | 305 | virtual int setsockopt(void *handle, int level, int optname, const void *optval, unsigned optlen); |
| Christopher Haster |
99:f51358e506c1 | 306 | |
| Christopher Haster |
101:9caa935c3baa | 307 | /* Get stack-specific socket options |
| Christopher Haster |
101:9caa935c3baa | 308 | * |
| Christopher Haster |
101:9caa935c3baa | 309 | * The getstackopt allow an application to retrieve stack-specific hints |
| Christopher Haster |
101:9caa935c3baa | 310 | * from the underlying stack. For unsupported options, |
| Christopher Haster |
101:9caa935c3baa | 311 | * NSAPI_ERROR_UNSUPPORTED is returned and optval is unmodified. |
| Christopher Haster |
101:9caa935c3baa | 312 | * |
| Christopher Haster |
99:f51358e506c1 | 313 | * @param handle Socket handle |
| Christopher Haster |
101:9caa935c3baa | 314 | * @param level Stack-specific protocol level |
| Christopher Haster |
101:9caa935c3baa | 315 | * @param optname Stack-specific option identifier |
| Christopher Haster |
101:9caa935c3baa | 316 | * @param optval Destination for option value |
| Christopher Haster |
99:f51358e506c1 | 317 | * @param optlen Length of the option value |
| Christopher Haster |
101:9caa935c3baa | 318 | * @return 0 on success, negative error code on failure |
| Christopher Haster |
99:f51358e506c1 | 319 | */ |
| Christopher Haster |
99:f51358e506c1 | 320 | virtual int getsockopt(void *handle, int level, int optname, void *optval, unsigned *optlen); |
| Christopher Haster |
89:b1d417383c0d | 321 | }; |
| Christopher Haster |
89:b1d417383c0d | 322 | |
| Christopher Haster |
89:b1d417383c0d | 323 | #endif |
