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