Ryo Iizuka / NySNICInterface

Dependents:   MurataTypeYD_Ping

Fork of NySNICInterface by Ryo Iizuka

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Socket.h Source File

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 typedef unsigned long socklen_t;
00028 
00029 /** Socket file descriptor and select wrapper
00030   */
00031 class Socket {
00032 public:
00033     /** Socket
00034      */
00035     Socket();
00036     
00037     /** Set blocking or non-blocking mode of the socket and a timeout on
00038         blocking socket operations
00039     \param blocking  true for blocking mode, false for non-blocking mode.
00040     \param timeout   timeout in ms [Default: (1500)ms].
00041     */
00042     void set_blocking(bool blocking, unsigned int timeout=1500);
00043 
00044     /** Set socket options
00045         @param level     stack level (see: lwip/sockets.h)
00046         @param optname   option ID
00047         @param optval    option value
00048         @param socklen_t length of the option value
00049         @return 0 on success, -1 on failure
00050     */
00051     int set_option(int level, int optname, const void *optval, socklen_t optlen);
00052     
00053     /** Get socket options
00054         @param level     stack level (see: lwip/sockets.h)
00055         @param optname   option ID
00056         \param optval    buffer pointer where to write the option value
00057         \param socklen_t length of the option value
00058         \return 0 on success, -1 on failure
00059      */
00060     int get_option(int level, int optname, void *optval, socklen_t *optlen);
00061     
00062     /** Close the socket
00063         \param shutdown   free the left-over data in message queues
00064      */
00065     int close(bool shutdown=true);
00066     
00067     virtual ~Socket();
00068     
00069     int createSocket( unsigned char bind = 0, unsigned int local_addr = 0, unsigned short port = 0 );
00070 
00071 protected:
00072     int resolveHostName( const char *host_p );
00073 
00074 protected:
00075     int  mSocketID;
00076     bool _blocking;
00077     int _timeout;
00078     char *getSocketSendBuf();
00079 
00080 private:
00081 
00082 //    int select(struct timeval *timeout, bool read, bool write);
00083 };
00084 
00085 #endif /* SOCKET_H_ */