cc3000 hostdriver with the mbed socket interface
Dependents: cc3000_hello_world_demo cc3000_simple_socket_demo cc3000_ntp_demo cc3000_ping_demo ... more
Socket/Socket.h@48:192e2fde71e9, 2015-02-28 (annotated)
- Committer:
- frankvnk
- Date:
- Sat Feb 28 16:40:39 2015 +0000
- Revision:
- 48:192e2fde71e9
- Parent:
- 5:245ac5b73132
Have TCPSocketServer::accept return the real accept values as defined in http://processors.wiki.ti.com/index.php/Non_blocking_accept; Fixed cc3000::init(const char *ip, const char *mask, const char *gateway) - missing _wlan.start(0);
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kojto | 5:245ac5b73132 | 1 | /* Copyright (C) 2013 mbed.org, MIT License |
Kojto | 0:615c697c33b0 | 2 | * |
Kojto | 0:615c697c33b0 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
Kojto | 0:615c697c33b0 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
Kojto | 0:615c697c33b0 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
Kojto | 0:615c697c33b0 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
Kojto | 0:615c697c33b0 | 7 | * furnished to do so, subject to the following conditions: |
Kojto | 0:615c697c33b0 | 8 | * |
Kojto | 0:615c697c33b0 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
Kojto | 0:615c697c33b0 | 10 | * substantial portions of the Software. |
Kojto | 0:615c697c33b0 | 11 | * |
Kojto | 0:615c697c33b0 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
Kojto | 0:615c697c33b0 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
Kojto | 0:615c697c33b0 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
Kojto | 0:615c697c33b0 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
Kojto | 0:615c697c33b0 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Kojto | 0:615c697c33b0 | 17 | */ |
Kojto | 5:245ac5b73132 | 18 | #ifndef SOCKET_H |
Kojto | 5:245ac5b73132 | 19 | #define SOCKET_H |
Kojto | 0:615c697c33b0 | 20 | |
Kojto | 0:615c697c33b0 | 21 | #include "cc3000.h" |
Kojto | 0:615c697c33b0 | 22 | |
Kojto | 0:615c697c33b0 | 23 | using namespace mbed_cc3000; |
Kojto | 0:615c697c33b0 | 24 | |
Kojto | 0:615c697c33b0 | 25 | class TimeInterval; |
Kojto | 0:615c697c33b0 | 26 | |
Kojto | 0:615c697c33b0 | 27 | /** Socket file descriptor and select wrapper |
Kojto | 0:615c697c33b0 | 28 | */ |
Kojto | 0:615c697c33b0 | 29 | class Socket { |
Kojto | 0:615c697c33b0 | 30 | public: |
Kojto | 0:615c697c33b0 | 31 | /** Socket |
Kojto | 0:615c697c33b0 | 32 | */ |
Kojto | 0:615c697c33b0 | 33 | Socket(); |
Kojto | 0:615c697c33b0 | 34 | |
Kojto | 0:615c697c33b0 | 35 | /** Set blocking or non-blocking mode of the socket and a timeout on |
Kojto | 0:615c697c33b0 | 36 | blocking socket operations |
Kojto | 0:615c697c33b0 | 37 | \param blocking true for blocking mode, false for non-blocking mode. |
Kojto | 0:615c697c33b0 | 38 | \param timeout timeout in ms [Default: (1500)ms]. |
Kojto | 0:615c697c33b0 | 39 | */ |
Kojto | 0:615c697c33b0 | 40 | void set_blocking(bool blocking, unsigned int timeout=1500); |
Kojto | 0:615c697c33b0 | 41 | |
Kojto | 0:615c697c33b0 | 42 | /** Set socket options |
Kojto | 0:615c697c33b0 | 43 | \param level stack level (see: lwip/sockets.h) |
Kojto | 0:615c697c33b0 | 44 | \param optname option ID |
Kojto | 0:615c697c33b0 | 45 | \param optval option value |
Kojto | 0:615c697c33b0 | 46 | \param socklen_t length of the option value |
Kojto | 0:615c697c33b0 | 47 | \return 0 on success, -1 on failure |
Kojto | 0:615c697c33b0 | 48 | */ |
Kojto | 0:615c697c33b0 | 49 | int set_option(int level, int optname, const void *optval, socklen_t optlen); |
Kojto | 0:615c697c33b0 | 50 | |
Kojto | 0:615c697c33b0 | 51 | /** Get socket options |
Kojto | 0:615c697c33b0 | 52 | \param level stack level (see: lwip/sockets.h) |
Kojto | 0:615c697c33b0 | 53 | \param optname option ID |
Kojto | 0:615c697c33b0 | 54 | \param optval buffer pointer where to write the option value |
Kojto | 0:615c697c33b0 | 55 | \param socklen_t length of the option value |
Kojto | 0:615c697c33b0 | 56 | \return 0 on success, -1 on failure |
Kojto | 0:615c697c33b0 | 57 | */ |
Kojto | 0:615c697c33b0 | 58 | int get_option(int level, int optname, void *optval, socklen_t *optlen); |
Kojto | 0:615c697c33b0 | 59 | |
Kojto | 0:615c697c33b0 | 60 | |
Kojto | 0:615c697c33b0 | 61 | /** Close the socket file descriptor |
Kojto | 0:615c697c33b0 | 62 | */ |
Kojto | 0:615c697c33b0 | 63 | int close(); |
Kojto | 0:615c697c33b0 | 64 | |
Kojto | 0:615c697c33b0 | 65 | ~Socket(); |
Kojto | 0:615c697c33b0 | 66 | |
Kojto | 0:615c697c33b0 | 67 | protected: |
Kojto | 0:615c697c33b0 | 68 | int _sock_fd; |
Kojto | 0:615c697c33b0 | 69 | |
Kojto | 4:15b58c119a0a | 70 | int init_socket(int type, int protocol); |
Kojto | 4:15b58c119a0a | 71 | |
Kojto | 0:615c697c33b0 | 72 | int wait_readable(TimeInterval& timeout); |
Kojto | 0:615c697c33b0 | 73 | int wait_writable(TimeInterval& timeout); |
Kojto | 0:615c697c33b0 | 74 | |
Kojto | 0:615c697c33b0 | 75 | bool _blocking; |
Kojto | 0:615c697c33b0 | 76 | int _timeout; |
Kojto | 0:615c697c33b0 | 77 | |
Kojto | 0:615c697c33b0 | 78 | cc3000 *_cc3000_module; |
Kojto | 0:615c697c33b0 | 79 | private: |
Kojto | 0:615c697c33b0 | 80 | int select(struct timeval *timeout, bool read, bool write); |
Kojto | 0:615c697c33b0 | 81 | }; |
Kojto | 0:615c697c33b0 | 82 | |
Kojto | 0:615c697c33b0 | 83 | /** Time interval class used to specify timeouts |
Kojto | 0:615c697c33b0 | 84 | */ |
Kojto | 0:615c697c33b0 | 85 | class TimeInterval { |
Kojto | 0:615c697c33b0 | 86 | friend class Socket; |
Kojto | 0:615c697c33b0 | 87 | |
Kojto | 0:615c697c33b0 | 88 | public: |
Kojto | 0:615c697c33b0 | 89 | /** Time Interval |
Kojto | 0:615c697c33b0 | 90 | \param ms time interval expressed in milliseconds |
Kojto | 0:615c697c33b0 | 91 | */ |
Kojto | 0:615c697c33b0 | 92 | TimeInterval(unsigned int ms); |
Kojto | 0:615c697c33b0 | 93 | |
Kojto | 0:615c697c33b0 | 94 | private: |
Kojto | 0:615c697c33b0 | 95 | struct timeval _time; |
Kojto | 0:615c697c33b0 | 96 | }; |
Kojto | 0:615c697c33b0 | 97 | |
Kojto | 5:245ac5b73132 | 98 | #endif /* SOCKET_H */ |