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