Host library for controlling a WiConnect enabled Wi-Fi module.

Dependents:   wiconnect-ota_example wiconnect-web_setup_example wiconnect-test-console wiconnect-tcp_server_example ... more

Committer:
dan_ackme
Date:
Sat Aug 23 05:39:17 2014 -0700
Revision:
17:7268f365676b
Fixes and documentation updates

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dan_ackme 17:7268f365676b 1 /* Copyright (C) 2012 mbed.org, MIT License
dan_ackme 17:7268f365676b 2 *
dan_ackme 17:7268f365676b 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
dan_ackme 17:7268f365676b 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
dan_ackme 17:7268f365676b 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
dan_ackme 17:7268f365676b 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
dan_ackme 17:7268f365676b 7 * furnished to do so, subject to the following conditions:
dan_ackme 17:7268f365676b 8 *
dan_ackme 17:7268f365676b 9 * The above copyright notice and this permission notice shall be included in all copies or
dan_ackme 17:7268f365676b 10 * substantial portions of the Software.
dan_ackme 17:7268f365676b 11 *
dan_ackme 17:7268f365676b 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
dan_ackme 17:7268f365676b 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
dan_ackme 17:7268f365676b 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
dan_ackme 17:7268f365676b 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
dan_ackme 17:7268f365676b 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
dan_ackme 17:7268f365676b 17 */
dan_ackme 17:7268f365676b 18 #ifndef SOCKET_H_
dan_ackme 17:7268f365676b 19 #define SOCKET_H_
dan_ackme 17:7268f365676b 20
dan_ackme 17:7268f365676b 21
dan_ackme 17:7268f365676b 22 #include "types/Socket/lwip/sockets.h"
dan_ackme 17:7268f365676b 23 #include "types/Socket/lwip/netdb.h"
dan_ackme 17:7268f365676b 24 #include "WiconnectTypes.h"
dan_ackme 17:7268f365676b 25 #include "types/WiconnectSocket.h"
dan_ackme 17:7268f365676b 26
dan_ackme 17:7268f365676b 27
dan_ackme 17:7268f365676b 28 using namespace wiconnect;
dan_ackme 17:7268f365676b 29
dan_ackme 17:7268f365676b 30
dan_ackme 17:7268f365676b 31 #define SOCKET_API_DEFAULT_RX_BUFFER_SIZE 128
dan_ackme 17:7268f365676b 32 #define SOCKET_API_DEFAULT_TX_BUFFER_SIZE 128
dan_ackme 17:7268f365676b 33
dan_ackme 17:7268f365676b 34
dan_ackme 17:7268f365676b 35 int gethostbyname_r(const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop);
dan_ackme 17:7268f365676b 36 struct hostent *gethostbyname(const char *name);
dan_ackme 17:7268f365676b 37
dan_ackme 17:7268f365676b 38
dan_ackme 17:7268f365676b 39
dan_ackme 17:7268f365676b 40
dan_ackme 17:7268f365676b 41 /** Socket file descriptor and select wrapper
dan_ackme 17:7268f365676b 42 */
dan_ackme 17:7268f365676b 43 class Socket {
dan_ackme 17:7268f365676b 44 public:
dan_ackme 17:7268f365676b 45 /** Socket
dan_ackme 17:7268f365676b 46 */
dan_ackme 17:7268f365676b 47 Socket();
dan_ackme 17:7268f365676b 48 Socket(int rxBufferLen, void *rxBuffer, int txBufferLen, void *txBuffer);
dan_ackme 17:7268f365676b 49
dan_ackme 17:7268f365676b 50 /** Set blocking or non-blocking mode of the socket and a timeout on
dan_ackme 17:7268f365676b 51 blocking socket operations
dan_ackme 17:7268f365676b 52
dan_ackme 17:7268f365676b 53 \note Currently the blocking/timeout functionality is only supported
dan_ackme 17:7268f365676b 54 for 'read' methods
dan_ackme 17:7268f365676b 55 \param blocking true for blocking mode, false for non-blocking mode.
dan_ackme 17:7268f365676b 56 \param timeout timeout in ms [Default: (1500)ms].
dan_ackme 17:7268f365676b 57 */
dan_ackme 17:7268f365676b 58 void set_blocking(bool blocking, unsigned int timeout=1500);
dan_ackme 17:7268f365676b 59
dan_ackme 17:7268f365676b 60 /** Set socket options
dan_ackme 17:7268f365676b 61 *
dan_ackme 17:7268f365676b 62 * \note NOT supported in this version.
dan_ackme 17:7268f365676b 63 *
dan_ackme 17:7268f365676b 64 \param level stack level (see: lwip/sockets.h)
dan_ackme 17:7268f365676b 65 \param optname option ID
dan_ackme 17:7268f365676b 66 \param optval option value
dan_ackme 17:7268f365676b 67 \param socklen_t length of the option value
dan_ackme 17:7268f365676b 68 \return 0 on success, -1 on failure
dan_ackme 17:7268f365676b 69 */
dan_ackme 17:7268f365676b 70 int set_option(int level, int optname, const void *optval, socklen_t optlen);
dan_ackme 17:7268f365676b 71
dan_ackme 17:7268f365676b 72 /** Get socket options
dan_ackme 17:7268f365676b 73 *
dan_ackme 17:7268f365676b 74 * \note NOT supported in this version.
dan_ackme 17:7268f365676b 75 *
dan_ackme 17:7268f365676b 76 \param level stack level (see: lwip/sockets.h)
dan_ackme 17:7268f365676b 77 \param optname option ID
dan_ackme 17:7268f365676b 78 \param optval buffer pointer where to write the option value
dan_ackme 17:7268f365676b 79 \param socklen_t length of the option value
dan_ackme 17:7268f365676b 80 \return 0 on success, -1 on failure
dan_ackme 17:7268f365676b 81 */
dan_ackme 17:7268f365676b 82 int get_option(int level, int optname, void *optval, socklen_t *optlen);
dan_ackme 17:7268f365676b 83
dan_ackme 17:7268f365676b 84 /** Close the socket
dan_ackme 17:7268f365676b 85 \param shutdown free the left-over data in message queues
dan_ackme 17:7268f365676b 86 */
dan_ackme 17:7268f365676b 87 int close(bool shutdown=true);
dan_ackme 17:7268f365676b 88
dan_ackme 17:7268f365676b 89 ~Socket();
dan_ackme 17:7268f365676b 90
dan_ackme 17:7268f365676b 91 protected:
dan_ackme 17:7268f365676b 92 bool _blocking;
dan_ackme 17:7268f365676b 93 unsigned int _timeout;
dan_ackme 17:7268f365676b 94
dan_ackme 17:7268f365676b 95 WiconnectSocket socket;
dan_ackme 17:7268f365676b 96 };
dan_ackme 17:7268f365676b 97
dan_ackme 17:7268f365676b 98 #endif /* SOCKET_H_ */