ap

Dependencies:   DnsQuery

Dependents:   WizFi310_TCP_Echo_Server_Example

Fork of NetworkSocketAPI by NetworkSocketAPI

Committer:
Christopher Haster
Date:
Tue Apr 05 09:07:28 2016 -0500
Revision:
76:bbe51641f405
Parent:
75:dea0cdb42241
Child:
77:b66a6984ed2d
Added rough NetworkInterface

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Christopher Haster 72:6a8b52ee83ed 1 /* Copyright (C) 2012 mbed.org, MIT License
Christopher Haster 72:6a8b52ee83ed 2 *
Christopher Haster 72:6a8b52ee83ed 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
Christopher Haster 72:6a8b52ee83ed 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
Christopher Haster 72:6a8b52ee83ed 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
Christopher Haster 72:6a8b52ee83ed 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
Christopher Haster 72:6a8b52ee83ed 7 * furnished to do so, subject to the following conditions:
Christopher Haster 72:6a8b52ee83ed 8 *
Christopher Haster 72:6a8b52ee83ed 9 * The above copyright notice and this permission notice shall be included in all copies or
Christopher Haster 72:6a8b52ee83ed 10 * substantial portions of the Software.
Christopher Haster 72:6a8b52ee83ed 11 *
Christopher Haster 72:6a8b52ee83ed 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
Christopher Haster 72:6a8b52ee83ed 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Christopher Haster 72:6a8b52ee83ed 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
Christopher Haster 72:6a8b52ee83ed 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Christopher Haster 72:6a8b52ee83ed 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Christopher Haster 72:6a8b52ee83ed 17 */
Christopher Haster 72:6a8b52ee83ed 18 #ifndef SOCKET_H
Christopher Haster 72:6a8b52ee83ed 19 #define SOCKET_H
Christopher Haster 72:6a8b52ee83ed 20
Christopher Haster 74:ef2470ca328b 21 /**
Christopher Haster 74:ef2470ca328b 22 * @enum ns_error_t
Christopher Haster 74:ef2470ca328b 23 * @brief enum of standardized error codes
Christopher Haster 74:ef2470ca328b 24 */
Christopher Haster 74:ef2470ca328b 25 enum ns_error_t {
Christopher Haster 76:bbe51641f405 26 NSAPI_ERROR_WOULD_BLOCK = -3001, /*!< no data is not available but call is non-blocking */
Christopher Haster 76:bbe51641f405 27 NSAPI_ERROR_UNSUPPORTED = -3002, /*!< unsupported configuration */
Christopher Haster 76:bbe51641f405 28 NSAPI_ERROR_NO_CONNECTION = -3003, /*!< not connected to a network */
Christopher Haster 76:bbe51641f405 29 NSAPI_ERROR_NO_SOCKET = -3004, /*!< socket not available for use */
Christopher Haster 76:bbe51641f405 30 NSAPI_ERROR_NO_ADDRESS = -3005, /*!< IP address is not known */
Christopher Haster 76:bbe51641f405 31 NSAPI_ERROR_NO_MEMORY = -3006, /*!< memory resource not available */
Christopher Haster 76:bbe51641f405 32 NSAPI_ERROR_DNS_FAILURE = -3007, /*!< DNS failed to complete successfully */
Christopher Haster 76:bbe51641f405 33 NSAPI_ERROR_DHCP_FAILURE = -3008, /*!< DHCP failed to complete successfully */
Christopher Haster 76:bbe51641f405 34 NSAPI_ERROR_AUTH_FAILURE = -3009, /*!< connection to access point faield */
Christopher Haster 76:bbe51641f405 35 NSAPI_ERROR_DEVICE_ERROR = -3010, /*!< failure interfacing with the network procesor */
Christopher Haster 74:ef2470ca328b 36 };
Christopher Haster 74:ef2470ca328b 37
Christopher Haster 74:ef2470ca328b 38 /**
Christopher Haster 74:ef2470ca328b 39 * @enum ns_opt_t
Christopher Haster 74:ef2470ca328b 40 * @brief enum of available options
Christopher Haster 74:ef2470ca328b 41 */
Christopher Haster 74:ef2470ca328b 42 enum ns_opt_t {
Christopher Haster 74:ef2470ca328b 43 };
Christopher Haster 74:ef2470ca328b 44
Christopher Haster 74:ef2470ca328b 45
Christopher Haster 72:6a8b52ee83ed 46 /** Abstract socket class
Christopher Haster 74:ef2470ca328b 47 */
Christopher Haster 72:6a8b52ee83ed 48 class Socket {
Christopher Haster 72:6a8b52ee83ed 49 public:
Christopher Haster 72:6a8b52ee83ed 50 /** Socket lifetime
Christopher Haster 72:6a8b52ee83ed 51 */
Christopher Haster 72:6a8b52ee83ed 52 Socket();
Christopher Haster 72:6a8b52ee83ed 53 ~Socket();
Christopher Haster 72:6a8b52ee83ed 54
Christopher Haster 72:6a8b52ee83ed 55 /** Set blocking or non-blocking mode of the socket
Christopher Haster 72:6a8b52ee83ed 56 \param blocking true for blocking mode, false for non-blocking mode.
Christopher Haster 72:6a8b52ee83ed 57 */
Christopher Haster 72:6a8b52ee83ed 58 void set_blocking(bool blocking);
Christopher Haster 72:6a8b52ee83ed 59
Christopher Haster 74:ef2470ca328b 60 /** Set timeout on a socket operation if blocking behaviour is enabled
Christopher Haster 72:6a8b52ee83ed 61 \param timeout timeout in ms
Christopher Haster 72:6a8b52ee83ed 62 */
Christopher Haster 72:6a8b52ee83ed 63 void set_timeout(unsigned int timeout);
Christopher Haster 72:6a8b52ee83ed 64
Christopher Haster 72:6a8b52ee83ed 65 /** Set socket options
Christopher Haster 76:bbe51641f405 66 \param optname Option ID
Christopher Haster 76:bbe51641f405 67 \param optval Option value
Christopher Haster 76:bbe51641f405 68 \param optlen Length of the option value
Christopher Haster 76:bbe51641f405 69 \return 0 on success, negative on failure
Christopher Haster 72:6a8b52ee83ed 70 */
Christopher Haster 74:ef2470ca328b 71 int set_option(int optname, const void *optval, unsigned int optlen);
Christopher Haster 72:6a8b52ee83ed 72
Christopher Haster 72:6a8b52ee83ed 73 /** Get socket options
Christopher Haster 76:bbe51641f405 74 \param optname Option ID
Christopher Haster 76:bbe51641f405 75 \param optval Buffer pointer where to write the option value
Christopher Haster 76:bbe51641f405 76 \param optlen Length of the option value
Christopher Haster 76:bbe51641f405 77 \return 0 on success, negative on failure
Christopher Haster 72:6a8b52ee83ed 78 */
Christopher Haster 74:ef2470ca328b 79 int get_option(int optname, void *optval, unsigned int *optlen);
Christopher Haster 72:6a8b52ee83ed 80
Christopher Haster 72:6a8b52ee83ed 81 /** Close the socket
Christopher Haster 72:6a8b52ee83ed 82 \param shutdown free the left-over data in message queues
Christopher Haster 72:6a8b52ee83ed 83 */
Christopher Haster 72:6a8b52ee83ed 84 int close(bool shutdown=true);
Christopher Haster 72:6a8b52ee83ed 85 };
Christopher Haster 72:6a8b52ee83ed 86
Christopher Haster 72:6a8b52ee83ed 87 #endif