Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Socket.h
00001 /* Copyright (C) 2012 mbed.org, MIT License 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00004 * and associated documentation files (the "Software"), to deal in the Software without restriction, 00005 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 00006 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 00007 * furnished to do so, subject to the following conditions: 00008 * 00009 * The above copyright notice and this permission notice shall be included in all copies or 00010 * substantial portions of the Software. 00011 * 00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00017 */ 00018 /* Copyright (C) 2014 Murata Manufacturing Co.,Ltd., MIT License 00019 * port to the muRata, SWITCH SCIENCE Wi-FI module TypeYD SNIC-UART. 00020 */ 00021 #ifndef SOCKET_H_ 00022 #define SOCKET_H_ 00023 00024 #include "SNIC_Core.h" 00025 #include "SNIC_UartMsgUtil.h" 00026 00027 #define htons(x) __REV16(x) 00028 #define ntohs(x) __REV16(x) 00029 #define htonl(x) __REV(x) 00030 #define ntohl(x) __REV(x) 00031 00032 typedef unsigned long socklen_t; 00033 00034 /** Socket file descriptor and select wrapper 00035 */ 00036 class Socket { 00037 public: 00038 /** Socket 00039 */ 00040 Socket(); 00041 00042 /** Set blocking or non-blocking mode of the socket and a timeout on 00043 blocking socket operations 00044 \param blocking true for blocking mode, false for non-blocking mode. 00045 \param timeout timeout in ms [Default: (1500)ms]. 00046 */ 00047 void set_blocking(bool blocking, unsigned int timeout=1500); 00048 00049 /** Set socket options 00050 @param level stack level (see: lwip/sockets.h) 00051 @param optname option ID 00052 @param optval option value 00053 @param socklen_t length of the option value 00054 @return 0 on success, -1 on failure 00055 */ 00056 int set_option(int level, int optname, const void *optval, socklen_t optlen); 00057 00058 /** Get socket options 00059 @param level stack level (see: lwip/sockets.h) 00060 @param optname option ID 00061 \param optval buffer pointer where to write the option value 00062 \param socklen_t length of the option value 00063 \return 0 on success, -1 on failure 00064 */ 00065 int get_option(int level, int optname, void *optval, socklen_t *optlen); 00066 00067 /** Close the socket 00068 \param shutdown free the left-over data in message queues 00069 */ 00070 int close(bool shutdown=true); 00071 00072 virtual ~Socket(); 00073 00074 int createSocket( unsigned char bind = 0, unsigned int local_addr = 0, unsigned short port = 0 ); 00075 00076 protected: 00077 int resolveHostName( const char *host_p ); 00078 00079 protected: 00080 int mSocketID; 00081 bool _blocking; 00082 int _timeout; 00083 char *getSocketSendBuf(); 00084 00085 private: 00086 00087 // int select(struct timeval *timeout, bool read, bool write); 00088 }; 00089 00090 #endif /* SOCKET_H_ */
Generated on Thu Jul 14 2022 20:28:29 by
1.7.2