mbed-os

Fork of mbed-os by erkin yucel

Committer:
elessair
Date:
Sun Oct 23 15:10:02 2016 +0000
Revision:
0:f269e3021894
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elessair 0:f269e3021894 1 /* Copyright (C) 2012 mbed.org, MIT License
elessair 0:f269e3021894 2 *
elessair 0:f269e3021894 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
elessair 0:f269e3021894 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
elessair 0:f269e3021894 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
elessair 0:f269e3021894 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
elessair 0:f269e3021894 7 * furnished to do so, subject to the following conditions:
elessair 0:f269e3021894 8 *
elessair 0:f269e3021894 9 * The above copyright notice and this permission notice shall be included in all copies or
elessair 0:f269e3021894 10 * substantial portions of the Software.
elessair 0:f269e3021894 11 *
elessair 0:f269e3021894 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
elessair 0:f269e3021894 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
elessair 0:f269e3021894 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
elessair 0:f269e3021894 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
elessair 0:f269e3021894 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
elessair 0:f269e3021894 17 */
elessair 0:f269e3021894 18
elessair 0:f269e3021894 19 #ifndef TCPSOCKET_H
elessair 0:f269e3021894 20 #define TCPSOCKET_H
elessair 0:f269e3021894 21
elessair 0:f269e3021894 22 #include "Socket/Socket.h"
elessair 0:f269e3021894 23 #include "Socket/Endpoint.h"
elessair 0:f269e3021894 24
elessair 0:f269e3021894 25 /**
elessair 0:f269e3021894 26 TCP socket connection
elessair 0:f269e3021894 27 */
elessair 0:f269e3021894 28 class TCPSocketConnection : public Socket, public Endpoint {
elessair 0:f269e3021894 29 friend class TCPSocketServer;
elessair 0:f269e3021894 30
elessair 0:f269e3021894 31 public:
elessair 0:f269e3021894 32 /** TCP socket connection
elessair 0:f269e3021894 33 */
elessair 0:f269e3021894 34 TCPSocketConnection();
elessair 0:f269e3021894 35
elessair 0:f269e3021894 36 /** Connects this TCP socket to the server
elessair 0:f269e3021894 37 \param host The host to connect to. It can either be an IP Address or a hostname that will be resolved with DNS.
elessair 0:f269e3021894 38 \param port The host's port to connect to.
elessair 0:f269e3021894 39 \return 0 on success, -1 on failure.
elessair 0:f269e3021894 40 */
elessair 0:f269e3021894 41 int connect(const char* host, const int port);
elessair 0:f269e3021894 42
elessair 0:f269e3021894 43 /** Check if the socket is connected
elessair 0:f269e3021894 44 \return true if connected, false otherwise.
elessair 0:f269e3021894 45 */
elessair 0:f269e3021894 46 bool is_connected(void);
elessair 0:f269e3021894 47
elessair 0:f269e3021894 48 /** Send data to the remote host.
elessair 0:f269e3021894 49 \param data The buffer to send to the host.
elessair 0:f269e3021894 50 \param length The length of the buffer to send.
elessair 0:f269e3021894 51 \return the number of written bytes on success (>=0) or -1 on failure
elessair 0:f269e3021894 52 */
elessair 0:f269e3021894 53 int send(char* data, int length);
elessair 0:f269e3021894 54
elessair 0:f269e3021894 55 /** Send all the data to the remote host.
elessair 0:f269e3021894 56 \param data The buffer to send to the host.
elessair 0:f269e3021894 57 \param length The length of the buffer to send.
elessair 0:f269e3021894 58 \return the number of written bytes on success (>=0) or -1 on failure
elessair 0:f269e3021894 59 */
elessair 0:f269e3021894 60 int send_all(char* data, int length);
elessair 0:f269e3021894 61
elessair 0:f269e3021894 62 /** Receive data from the remote host.
elessair 0:f269e3021894 63 \param data The buffer in which to store the data received from the host.
elessair 0:f269e3021894 64 \param length The maximum length of the buffer.
elessair 0:f269e3021894 65 \return the number of received bytes on success (>=0) or -1 on failure
elessair 0:f269e3021894 66 */
elessair 0:f269e3021894 67 int receive(char* data, int length);
elessair 0:f269e3021894 68
elessair 0:f269e3021894 69 /** Receive all the data from the remote host.
elessair 0:f269e3021894 70 \param data The buffer in which to store the data received from the host.
elessair 0:f269e3021894 71 \param length The maximum length of the buffer.
elessair 0:f269e3021894 72 \return the number of received bytes on success (>=0) or -1 on failure
elessair 0:f269e3021894 73 */
elessair 0:f269e3021894 74 int receive_all(char* data, int length);
elessair 0:f269e3021894 75
elessair 0:f269e3021894 76 private:
elessair 0:f269e3021894 77 bool _is_connected;
elessair 0:f269e3021894 78
elessair 0:f269e3021894 79 };
elessair 0:f269e3021894 80
elessair 0:f269e3021894 81 #endif