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