Deprecated fork of old network stack source from github. Please use official library instead: https://mbed.org/users/mbed_official/code/EthernetInterface/

Committer:
AdamGreen
Date:
Sat Oct 26 08:51:36 2013 +0000
Revision:
1:eadc868c2acf
Parent:
0:3b00827bb0b7
Fix TCP checksum bug and stranded large TCP segments.

Who changed what in which revision?

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