Christopher Haster / NetworkSocketAPI

Dependencies:   DnsQuery

Committer:
Christopher Haster
Date:
Tue Apr 05 05:40:43 2016 -0500
Revision:
0:6a8b52ee83ed
Child:
1:968f7b32278f
Added initial design for user-facing API

Who changed what in which revision?

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