KDDI Fx0 hackathon
/
MurataTypeYD_Websocket_Sample_full
Websocket_Sample for MurataTypeYD
SNICInterface_mod/Socket/Socket.h@1:b5ac0f971f43, 2015-03-12 (annotated)
- Committer:
- komoritan
- Date:
- Thu Mar 12 12:15:46 2015 +0000
- Revision:
- 1:b5ac0f971f43
- Parent:
- 0:14bd24b5a77f
Fixed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
komoritan | 0:14bd24b5a77f | 1 | /* Copyright (C) 2012 mbed.org, MIT License |
komoritan | 0:14bd24b5a77f | 2 | * |
komoritan | 0:14bd24b5a77f | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
komoritan | 0:14bd24b5a77f | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
komoritan | 0:14bd24b5a77f | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
komoritan | 0:14bd24b5a77f | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
komoritan | 0:14bd24b5a77f | 7 | * furnished to do so, subject to the following conditions: |
komoritan | 0:14bd24b5a77f | 8 | * |
komoritan | 0:14bd24b5a77f | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
komoritan | 0:14bd24b5a77f | 10 | * substantial portions of the Software. |
komoritan | 0:14bd24b5a77f | 11 | * |
komoritan | 0:14bd24b5a77f | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
komoritan | 0:14bd24b5a77f | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
komoritan | 0:14bd24b5a77f | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
komoritan | 0:14bd24b5a77f | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
komoritan | 0:14bd24b5a77f | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
komoritan | 0:14bd24b5a77f | 17 | */ |
komoritan | 0:14bd24b5a77f | 18 | /* Copyright (C) 2014 Murata Manufacturing Co.,Ltd., MIT License |
komoritan | 0:14bd24b5a77f | 19 | * port to the muRata, SWITCH SCIENCE Wi-FI module TypeYD SNIC-UART. |
komoritan | 0:14bd24b5a77f | 20 | */ |
komoritan | 0:14bd24b5a77f | 21 | #ifndef SOCKET_H_ |
komoritan | 0:14bd24b5a77f | 22 | #define SOCKET_H_ |
komoritan | 0:14bd24b5a77f | 23 | |
komoritan | 0:14bd24b5a77f | 24 | #include "SNIC_Core.h" |
komoritan | 0:14bd24b5a77f | 25 | #include "SNIC_UartMsgUtil.h" |
komoritan | 0:14bd24b5a77f | 26 | |
komoritan | 0:14bd24b5a77f | 27 | #define htons(x) __REV16(x) |
komoritan | 0:14bd24b5a77f | 28 | #define ntohs(x) __REV16(x) |
komoritan | 0:14bd24b5a77f | 29 | #define htonl(x) __REV(x) |
komoritan | 0:14bd24b5a77f | 30 | #define ntohl(x) __REV(x) |
komoritan | 0:14bd24b5a77f | 31 | |
komoritan | 0:14bd24b5a77f | 32 | typedef unsigned long socklen_t; |
komoritan | 0:14bd24b5a77f | 33 | |
komoritan | 0:14bd24b5a77f | 34 | /** Socket file descriptor and select wrapper |
komoritan | 0:14bd24b5a77f | 35 | */ |
komoritan | 0:14bd24b5a77f | 36 | class Socket { |
komoritan | 0:14bd24b5a77f | 37 | public: |
komoritan | 0:14bd24b5a77f | 38 | /** Socket |
komoritan | 0:14bd24b5a77f | 39 | */ |
komoritan | 0:14bd24b5a77f | 40 | Socket(); |
komoritan | 0:14bd24b5a77f | 41 | |
komoritan | 0:14bd24b5a77f | 42 | /** Set blocking or non-blocking mode of the socket and a timeout on |
komoritan | 0:14bd24b5a77f | 43 | blocking socket operations |
komoritan | 0:14bd24b5a77f | 44 | \param blocking true for blocking mode, false for non-blocking mode. |
komoritan | 0:14bd24b5a77f | 45 | \param timeout timeout in ms [Default: (1500)ms]. |
komoritan | 0:14bd24b5a77f | 46 | */ |
komoritan | 0:14bd24b5a77f | 47 | void set_blocking(bool blocking, unsigned int timeout=1500); |
komoritan | 0:14bd24b5a77f | 48 | |
komoritan | 0:14bd24b5a77f | 49 | /** Set socket options |
komoritan | 0:14bd24b5a77f | 50 | @param level stack level (see: lwip/sockets.h) |
komoritan | 0:14bd24b5a77f | 51 | @param optname option ID |
komoritan | 0:14bd24b5a77f | 52 | @param optval option value |
komoritan | 0:14bd24b5a77f | 53 | @param socklen_t length of the option value |
komoritan | 0:14bd24b5a77f | 54 | @return 0 on success, -1 on failure |
komoritan | 0:14bd24b5a77f | 55 | */ |
komoritan | 0:14bd24b5a77f | 56 | int set_option(int level, int optname, const void *optval, socklen_t optlen); |
komoritan | 0:14bd24b5a77f | 57 | |
komoritan | 0:14bd24b5a77f | 58 | /** Get socket options |
komoritan | 0:14bd24b5a77f | 59 | @param level stack level (see: lwip/sockets.h) |
komoritan | 0:14bd24b5a77f | 60 | @param optname option ID |
komoritan | 0:14bd24b5a77f | 61 | \param optval buffer pointer where to write the option value |
komoritan | 0:14bd24b5a77f | 62 | \param socklen_t length of the option value |
komoritan | 0:14bd24b5a77f | 63 | \return 0 on success, -1 on failure |
komoritan | 0:14bd24b5a77f | 64 | */ |
komoritan | 0:14bd24b5a77f | 65 | int get_option(int level, int optname, void *optval, socklen_t *optlen); |
komoritan | 0:14bd24b5a77f | 66 | |
komoritan | 0:14bd24b5a77f | 67 | /** Close the socket |
komoritan | 0:14bd24b5a77f | 68 | \param shutdown free the left-over data in message queues |
komoritan | 0:14bd24b5a77f | 69 | */ |
komoritan | 0:14bd24b5a77f | 70 | int close(bool shutdown=true); |
komoritan | 0:14bd24b5a77f | 71 | |
komoritan | 0:14bd24b5a77f | 72 | virtual ~Socket(); |
komoritan | 0:14bd24b5a77f | 73 | |
komoritan | 0:14bd24b5a77f | 74 | int createSocket( unsigned char bind = 0, unsigned int local_addr = 0, unsigned short port = 0 ); |
komoritan | 0:14bd24b5a77f | 75 | |
komoritan | 0:14bd24b5a77f | 76 | protected: |
komoritan | 0:14bd24b5a77f | 77 | int resolveHostName( const char *host_p ); |
komoritan | 0:14bd24b5a77f | 78 | |
komoritan | 0:14bd24b5a77f | 79 | protected: |
komoritan | 0:14bd24b5a77f | 80 | int mSocketID; |
komoritan | 0:14bd24b5a77f | 81 | bool _blocking; |
komoritan | 0:14bd24b5a77f | 82 | int _timeout; |
komoritan | 0:14bd24b5a77f | 83 | char *getSocketSendBuf(); |
komoritan | 0:14bd24b5a77f | 84 | |
komoritan | 0:14bd24b5a77f | 85 | private: |
komoritan | 0:14bd24b5a77f | 86 | |
komoritan | 0:14bd24b5a77f | 87 | // int select(struct timeval *timeout, bool read, bool write); |
komoritan | 0:14bd24b5a77f | 88 | }; |
komoritan | 0:14bd24b5a77f | 89 | |
komoritan | 0:14bd24b5a77f | 90 | #endif /* SOCKET_H_ */ |