wip
Dependents: EthernetInterface_vz
Fork of Socket by
TCPSocketConnection.h@13:084c7fa00503, 2012-08-04 (annotated)
- Committer:
- emilmont
- Date:
- Sat Aug 04 08:24:54 2012 +0000
- Revision:
- 13:084c7fa00503
- Parent:
- 12:8867c9da3b08
- Child:
- 14:c159ce890a45
Try "\brief" Doxygen directive in documentation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 3:e6474399e057 | 1 | /* Copyright (C) 2012 mbed.org, MIT License |
emilmont | 3:e6474399e057 | 2 | * |
emilmont | 3:e6474399e057 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
emilmont | 3:e6474399e057 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
emilmont | 3:e6474399e057 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
emilmont | 3:e6474399e057 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
emilmont | 3:e6474399e057 | 7 | * furnished to do so, subject to the following conditions: |
emilmont | 3:e6474399e057 | 8 | * |
emilmont | 3:e6474399e057 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
emilmont | 3:e6474399e057 | 10 | * substantial portions of the Software. |
emilmont | 3:e6474399e057 | 11 | * |
emilmont | 3:e6474399e057 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
emilmont | 3:e6474399e057 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
emilmont | 3:e6474399e057 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
emilmont | 3:e6474399e057 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
emilmont | 3:e6474399e057 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
emilmont | 3:e6474399e057 | 17 | */ |
emilmont | 3:e6474399e057 | 18 | |
emilmont | 3:e6474399e057 | 19 | #ifndef TCPSOCKET_H |
emilmont | 3:e6474399e057 | 20 | #define TCPSOCKET_H |
emilmont | 3:e6474399e057 | 21 | |
emilmont | 3:e6474399e057 | 22 | #include "Socket/Socket.h" |
emilmont | 5:300e7ad2dc1d | 23 | #include "Socket/Endpoint.h" |
emilmont | 3:e6474399e057 | 24 | |
emilmont | 3:e6474399e057 | 25 | /** |
emilmont | 8:9cf9c2d45264 | 26 | TCP socket connection |
emilmont | 3:e6474399e057 | 27 | */ |
emilmont | 7:ac5f77f4497a | 28 | class TCPSocketConnection : public Socket, public Endpoint { |
emilmont | 3:e6474399e057 | 29 | friend class TCPSocketServer; |
emilmont | 3:e6474399e057 | 30 | |
emilmont | 3:e6474399e057 | 31 | public: |
emilmont | 8:9cf9c2d45264 | 32 | /** TCP socket connection |
emilmont | 3:e6474399e057 | 33 | */ |
emilmont | 3:e6474399e057 | 34 | TCPSocketConnection(); |
emilmont | 3:e6474399e057 | 35 | |
emilmont | 8:9cf9c2d45264 | 36 | /** Connects this TCP socket to the server |
emilmont | 3:e6474399e057 | 37 | \param host The host to connect to. It can either be an IP Address or a hostname that will be resolved with DNS. |
emilmont | 3:e6474399e057 | 38 | \param port The host's port to connect to. |
emilmont | 3:e6474399e057 | 39 | \return 0 on success, -1 on failure. |
emilmont | 3:e6474399e057 | 40 | */ |
emilmont | 4:75988d748e4d | 41 | int connect(const char* host, const int port); |
emilmont | 3:e6474399e057 | 42 | |
emilmont | 11:3d83c348fb8b | 43 | /** Check if the socket is connected |
emilmont | 11:3d83c348fb8b | 44 | \return true if connected, false otherwise. |
emilmont | 11:3d83c348fb8b | 45 | */ |
emilmont | 11:3d83c348fb8b | 46 | bool is_connected(void); |
emilmont | 11:3d83c348fb8b | 47 | |
emilmont | 13:084c7fa00503 | 48 | /* \brief Send data to the remote host. Applications are responsible for |
emilmont | 13:084c7fa00503 | 49 | * checking that all data has been sent; if only some of the data was |
emilmont | 13:084c7fa00503 | 50 | * transmitted, the application needs to attempt delivery of the |
emilmont | 13:084c7fa00503 | 51 | * remaining data. |
emilmont | 13:084c7fa00503 | 52 | * \param data The buffer to send to the host. |
emilmont | 13:084c7fa00503 | 53 | * \param length The length of the buffer to send. |
emilmont | 13:084c7fa00503 | 54 | * \return the number of written bytes on success (>=0) or -1 on failure |
emilmont | 3:e6474399e057 | 55 | */ |
emilmont | 10:d24738f4ef99 | 56 | int send(char* data, int length); |
emilmont | 3:e6474399e057 | 57 | |
emilmont | 13:084c7fa00503 | 58 | /* \brief Send all the data to the remote host. This method continues to send |
emilmont | 13:084c7fa00503 | 59 | * data until either all data has been sent, or an error occurs, or a |
emilmont | 13:084c7fa00503 | 60 | * timeout occurs. |
emilmont | 13:084c7fa00503 | 61 | * \param data The buffer to send to the host. |
emilmont | 13:084c7fa00503 | 62 | * \param length The length of the buffer to send. |
emilmont | 13:084c7fa00503 | 63 | * \return the number of written bytes on success (>=0) or -1 on failure |
emilmont | 13:084c7fa00503 | 64 | */ |
emilmont | 10:d24738f4ef99 | 65 | int send_all(char* data, int length); |
emilmont | 3:e6474399e057 | 66 | |
emilmont | 13:084c7fa00503 | 67 | /* \brief Receive data from the remote host. Return as soon as some data is available. |
emilmont | 13:084c7fa00503 | 68 | * \param data The buffer in which to store the data received from the host. |
emilmont | 13:084c7fa00503 | 69 | * \param length The maximum length of the buffer. |
emilmont | 13:084c7fa00503 | 70 | * \return the number of received bytes on success (>=0) or -1 on failure |
emilmont | 3:e6474399e057 | 71 | */ |
emilmont | 10:d24738f4ef99 | 72 | int receive(char* data, int length); |
emilmont | 3:e6474399e057 | 73 | |
emilmont | 13:084c7fa00503 | 74 | /* \brief Receive all the data from the remote host. This method continues to receive |
emilmont | 13:084c7fa00503 | 75 | * data until either length bytes has been received, or an error occurs, or a |
emilmont | 13:084c7fa00503 | 76 | * timeout occurs. |
emilmont | 13:084c7fa00503 | 77 | * \param data The buffer in which to store the data received from the host. |
emilmont | 13:084c7fa00503 | 78 | * \param length The maximum length of the buffer. |
emilmont | 13:084c7fa00503 | 79 | * \return the number of received bytes on success (>=0) or -1 on failure |
emilmont | 13:084c7fa00503 | 80 | */ |
emilmont | 10:d24738f4ef99 | 81 | int receive_all(char* data, int length); |
emilmont | 5:300e7ad2dc1d | 82 | |
emilmont | 3:e6474399e057 | 83 | private: |
emilmont | 11:3d83c348fb8b | 84 | bool _is_connected; |
emilmont | 3:e6474399e057 | 85 | |
emilmont | 3:e6474399e057 | 86 | }; |
emilmont | 3:e6474399e057 | 87 | |
emilmont | 3:e6474399e057 | 88 | #endif |