victor qiu / Mbed OS SimpleNTP

Fork of SimpleNTP by Akinori Hashimoto

Committer:
victorqiu2
Date:
Tue Aug 01 01:22:01 2017 +0000
Revision:
2:68ae27667d82
A

Who changed what in which revision?

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