Customized
Dependents: MurataTypeYD_RPC_Sample
Fork of SNICInterface_mod by
Socket/TCPSocketConnection.h@41:1c1b5ad4d491, 2014-07-15 (annotated)
- Committer:
- kishino
- Date:
- Tue Jul 15 10:13:53 2014 +0000
- Revision:
- 41:1c1b5ad4d491
- Parent:
- 39:a1233ca02edf
- Child:
- 44:c50e7332afcc
Modified the module name of Copyright.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kishino | 20:dd736d328de6 | 1 | /* Copyright (C) 2012 mbed.org, MIT License |
kishino | 20:dd736d328de6 | 2 | * |
kishino | 20:dd736d328de6 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
kishino | 20:dd736d328de6 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
kishino | 20:dd736d328de6 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
kishino | 20:dd736d328de6 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
kishino | 20:dd736d328de6 | 7 | * furnished to do so, subject to the following conditions: |
kishino | 20:dd736d328de6 | 8 | * |
kishino | 20:dd736d328de6 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
kishino | 20:dd736d328de6 | 10 | * substantial portions of the Software. |
kishino | 20:dd736d328de6 | 11 | * |
kishino | 20:dd736d328de6 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
kishino | 20:dd736d328de6 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
kishino | 20:dd736d328de6 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
kishino | 20:dd736d328de6 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
kishino | 20:dd736d328de6 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
kishino | 20:dd736d328de6 | 17 | */ |
kishino | 39:a1233ca02edf | 18 | /* Copyright (C) 2014 Murata Manufacturing Co.,Ltd., MIT License |
kishino | 41:1c1b5ad4d491 | 19 | * port to the muRata, SWITCH SCIENCE Wi-FI module TypeYD SNIC-UART. |
kishino | 39:a1233ca02edf | 20 | */ |
kishino | 20:dd736d328de6 | 21 | #ifndef TCPSOCKET_H |
kishino | 20:dd736d328de6 | 22 | #define TCPSOCKET_H |
kishino | 20:dd736d328de6 | 23 | |
kishino | 20:dd736d328de6 | 24 | #include "Socket.h" |
kishino | 20:dd736d328de6 | 25 | #include "Endpoint.h" |
kishino | 20:dd736d328de6 | 26 | |
kishino | 20:dd736d328de6 | 27 | /** |
kishino | 23:4ff2231ff9ba | 28 | Interface class for TCP socket of using SNIC UART. |
kishino | 20:dd736d328de6 | 29 | */ |
kishino | 20:dd736d328de6 | 30 | class TCPSocketConnection : public Socket, public Endpoint { |
kishino | 20:dd736d328de6 | 31 | |
kishino | 20:dd736d328de6 | 32 | public: |
kishino | 20:dd736d328de6 | 33 | /** TCP socket connection |
kishino | 20:dd736d328de6 | 34 | */ |
kishino | 20:dd736d328de6 | 35 | TCPSocketConnection(); |
kishino | 26:f2e1030964e4 | 36 | virtual ~TCPSocketConnection(); |
kishino | 20:dd736d328de6 | 37 | |
kishino | 20:dd736d328de6 | 38 | /** Connects this TCP socket to the server |
kishino | 27:dcc4f34448f0 | 39 | @param host The strings of ip address. |
kishino | 20:dd736d328de6 | 40 | @param port The host's port to connect to. |
kishino | 20:dd736d328de6 | 41 | @return 0 on success, -1 on failure. |
kishino | 20:dd736d328de6 | 42 | @note This function is blocked until a returns. |
kishino | 20:dd736d328de6 | 43 | When you use it by UI thread, be careful. |
kishino | 20:dd736d328de6 | 44 | */ |
kishino | 27:dcc4f34448f0 | 45 | int connect( const char *ip_addr_p, unsigned short port ); |
kishino | 20:dd736d328de6 | 46 | |
kishino | 20:dd736d328de6 | 47 | /** Check if the socket is connected |
kishino | 20:dd736d328de6 | 48 | @return true if connected, false otherwise. |
kishino | 20:dd736d328de6 | 49 | */ |
kishino | 20:dd736d328de6 | 50 | bool is_connected(void); |
kishino | 20:dd736d328de6 | 51 | |
kishino | 20:dd736d328de6 | 52 | /** Send data to the remote host. |
kishino | 20:dd736d328de6 | 53 | @param data The buffer to send to the host. |
kishino | 20:dd736d328de6 | 54 | @param length The length of the buffer to send. |
kishino | 20:dd736d328de6 | 55 | @return the number of written bytes on success (>=0) or -1 on failure |
kishino | 20:dd736d328de6 | 56 | */ |
kishino | 29:6a0ba999597d | 57 | int send(char *data_p, int length); |
kishino | 29:6a0ba999597d | 58 | |
kishino | 29:6a0ba999597d | 59 | /** Send data to the remote host. |
kishino | 29:6a0ba999597d | 60 | @param data The buffer to send to the host. |
kishino | 29:6a0ba999597d | 61 | @param length The length of the buffer to send. |
kishino | 29:6a0ba999597d | 62 | @return the number of written bytes on success (>=0) or -1 on failure |
kishino | 29:6a0ba999597d | 63 | */ |
kishino | 29:6a0ba999597d | 64 | int send_all(char *data_p, int length); |
kishino | 20:dd736d328de6 | 65 | |
kishino | 20:dd736d328de6 | 66 | /** Receive data from the remote host. |
kishino | 20:dd736d328de6 | 67 | @param data The buffer in which to store the data received from the host. |
kishino | 20:dd736d328de6 | 68 | @param length The maximum length of the buffer. |
kishino | 20:dd736d328de6 | 69 | @return the number of received bytes on success (>=0) or -1 on failure |
kishino | 20:dd736d328de6 | 70 | */ |
kishino | 29:6a0ba999597d | 71 | int receive(char *data_p, int length); |
kishino | 20:dd736d328de6 | 72 | |
kishino | 32:ae95309643aa | 73 | void setAcceptSocket( int socket_id ); |
kishino | 20:dd736d328de6 | 74 | private: |
kishino | 20:dd736d328de6 | 75 | |
kishino | 20:dd736d328de6 | 76 | }; |
kishino | 20:dd736d328de6 | 77 | #endif |