Henry Leinen / WifiPlusClick

Dependents:   WifiPlusKlickExample

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TCPSocketConnection.h Source File

TCPSocketConnection.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 __TCPSOCKETCONNECTION_H__
00019 #define __TCPSOCKETCONNECTION_H__
00020 
00021 #include "Socket.h"
00022 #include "Endpoint.h"
00023 
00024 /** Class TCPSocketConnection inherits from Socket and Endpoint. Implements the client TCP socket functionality.
00025   */
00026 class TCPSocketConnection : public Socket, public Endpoint
00027 {
00028     friend class TCPSocketServer;
00029 public:
00030     /** Public constructor to instantiate an object of class TCPSocketConnection */
00031     TCPSocketConnection();
00032     
00033     /** Function connect allows to create an unused socket object to a remote host on a remote port.
00034       * @param host : remote host to which to initiate a TCP connection.
00035       * @param port : remote port to which to initiate a TCP connection.
00036       * @returns : 0 if successfull or -1 on failure.
00037       */
00038     int connect(const char *host, const int port);
00039     
00040     /** Function to query wheather the socket is already connected with a remote instance.
00041       * @returns : true if already connected or false otherwise.
00042       */
00043     bool is_connected(void);
00044     
00045     /** Function send allows to send data to an already connected TCP socket.
00046       * @param data : pointer to a valid data buffer.
00047       * @param length : Number of bytes from data buffer to send.
00048       * @returns : number of bytes actually sent or -1 on failure.
00049       */
00050     int send(char *data, int length);
00051     
00052     /** Function send_all allows to send data to an already connected TCP socket. The function will try to send all the data specified by length.
00053       * If a timeout occurs in a blocking configuration the function returns the number of bytes actually sent.
00054       * @param data : pointer to a valid data buffer.
00055       * @param length : Number of bytes from data buffer to send.
00056       * @returns : number of bytes actually send or -1 on failure.
00057       */
00058     int send_all(char *data, int length);
00059     
00060     /** Function recv allows to receive data from an already connected TCP socket. Please note that this function will return once a first bunch
00061       * of data has been received. It will not wait until all the requested data is available.
00062       * @param data : pointer to a valid data buffer which will receive the received data. The buffer must be big enough to hold all the requested data.
00063       * @param length : Maximum numnber of bytes to receive.
00064       * @returns : number of bytes actually received and stored in data buffer or -1 on failure.
00065       */
00066     int recv(char *data, int length);
00067     
00068     /** Function recv_all allows to receive data entirely from an already connected TCP socket. Please note that this function will only return if
00069       * all the requested data was received or a timeout occured.
00070       * @param data : pointer to a valid data buffer which will receive the received data. The buffer must be big enough to hold all the requested data.
00071       * @param length : Number of bytes to receive.
00072       * @returns : number of bytes actually received and stored in data buffer or -1 on failure.
00073       */
00074     int recv_all(char * data, int length);
00075     
00076 private:
00077     bool _is_connected;
00078 };
00079 
00080 #endif // __TCPSOCKETCONNECTION_H__