Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Socket by
TCPSocketConnection.h
00001 /* Copyright (C) 2012 mbed.org, MIT License 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00004 * and associated documentation files (the "Software"), to deal in the Software without restriction, 00005 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 00006 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 00007 * furnished to do so, subject to the following conditions: 00008 * 00009 * The above copyright notice and this permission notice shall be included in all copies or 00010 * substantial portions of the Software. 00011 * 00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00017 */ 00018 00019 #ifndef TCPSOCKET_H 00020 #define TCPSOCKET_H 00021 00022 #include "Socket/Socket.h" 00023 #include "Socket/Endpoint.h" 00024 00025 /** 00026 This is a C++ abstraction for TCP networking sockets. 00027 */ 00028 class TCPSocketConnection : public Socket, Endpoint { 00029 friend class TCPSocketServer; 00030 00031 public: 00032 /** Instantiate a TCP Socket. 00033 */ 00034 TCPSocketConnection(); 00035 00036 ~TCPSocketConnection(); 00037 00038 /** Connect the TCP Socket to the following host. 00039 \param host The host to connect to. It can either be an IP Address or a hostname that will be resolved with DNS. 00040 \param port The host's port to connect to. 00041 \return 0 on success, -1 on failure. 00042 */ 00043 int connect(const char* host, const int port); 00044 00045 /** Send data to the remote host. 00046 \param data The buffer to send to the host. 00047 \param length The length of the buffer to send. 00048 \param timeout The maximum amount of time in ms to wait while trying to send the buffer. 00049 \return the number of written bytes on success (>=0) or -1 on failure 00050 */ 00051 int send(char* data, int length, int timeout_ms=0); 00052 00053 /** Send data to the remote host. 00054 \param data The buffer to send to the host. 00055 \param length The length of the buffer to send. 00056 \param timeout The maximum amount of time in ms to wait while trying to send the buffer. 00057 \return the number of written bytes on success (>=0) or -1 on failure 00058 */ 00059 int send_all(char* data, int length, int timeout_ms=0); 00060 00061 /** Receive data from the remote host. 00062 \param data The buffer in which to store the data received from the host. 00063 \param length The maximum length of the buffer. 00064 \param timeout The maximum amount of time in ms to wait while trying to receive data. 00065 \return the number of received bytes on success (>=0) or -1 on failure 00066 */ 00067 int receive(char* data, int length, int timeout_ms=0); 00068 00069 /** Receive data from the remote host. 00070 \param data The buffer in which to store the data received from the host. 00071 \param length The maximum length of the buffer. 00072 \param timeout The maximum amount of time in ms to wait while trying to receive data. 00073 \return the number of received bytes on success (>=0) or -1 on failure 00074 */ 00075 int receive_all(char* data, int length, int timeout_ms=0); 00076 00077 private: 00078 bool _closedByRemoteHost; 00079 00080 }; 00081 00082 #endif
Generated on Wed Jul 27 2022 19:46:00 by
