Implementation of the WifiPlusClick hardware module.

Dependents:   WifiPlusKlickExample

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Socket.h Source File

Socket.h

00001 /* Copyright (c) 2013 Henry Leinen (henry[dot]leinen [at] online [dot] de)
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 #ifndef __SOCKET_H__
00019 #define __SOCKET_H__
00020 
00021 
00022 #include "Wifi.h"
00023 
00024 /** Class socket is the base class implementation for TCP and UDP sockets. As the socket class does not provide a full implementation of any kind, it is not recommended to use it.
00025   * Class socket is required to implement the base functionality for UDP and TCP sockets in the WifiPlusClick library implementation.
00026   * @note Please note that in this implementation the set_option function is not working as the WifiPlusClick module does not support this functionality.
00027   */
00028 class Socket
00029 {
00030 public:
00031     /** Constructor of socket object.
00032       */
00033     Socket();
00034     
00035     /** Function set_blocking sets the socket into a blocking or non-blocking status. In case of a blocking socket a timeout can be specified.
00036       * @param blocking : set to true if time consuming socket operations shall block execution until they are finished or until a timeout occurs. If set to false, socket operations will terminated immediately.
00037       * @param timeout  : a timeout value in milliseconds for use in blocking operations.
00038       */
00039     void set_blocking(bool blocking, unsigned int timeout = 1500);
00040     
00041     /** Function set_option is not working as expected, because there this functionality is not supported by the WifiPlusClick module. 
00042       * @note This functionality is just kept for compatibility reasons. */
00043     int set_option(int level, int optname, const void* optval, int socklen);
00044     
00045     /** Function close will close the socket.
00046       * @param shutdown : This parameter will actually be ignored by the implementation.
00047       * @returns :
00048       *     -1 if not successfull
00049       *     >=0 if successfull
00050       */
00051     int close( bool shutdown = true );
00052     
00053     ~Socket();
00054     
00055 protected:
00056     bool _blocking;
00057     unsigned int _timeout;
00058 
00059 protected:
00060     SOCKET_HANDLE_t     _socket;
00061 };
00062 
00063 
00064 #endif // __SOCKET_H__