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.
Dependencies: DnsQuery
Dependents: WizFi310_TCP_Echo_Server_Example
Fork of NetworkSocketAPI by
SocketInterface.h@63:531f4c27f360, 2016-03-09 (annotated)
- Committer:
- sam_grove
- Date:
- Wed Mar 09 05:51:38 2016 +0000
- Revision:
- 63:531f4c27f360
- Parent:
- 58:1caa187fa5af
- Child:
- 66:c84a4c76cb94
update formatting and add comments for documentation
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| sam_grove | 0:d35446f60233 | 1 | /* SocketInterface Base Class | 
| sam_grove | 0:d35446f60233 | 2 | * Copyright (c) 2015 ARM Limited | 
| sam_grove | 0:d35446f60233 | 3 | * | 
| sam_grove | 0:d35446f60233 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
| sam_grove | 0:d35446f60233 | 5 | * you may not use this file except in compliance with the License. | 
| sam_grove | 0:d35446f60233 | 6 | * You may obtain a copy of the License at | 
| sam_grove | 0:d35446f60233 | 7 | * | 
| sam_grove | 0:d35446f60233 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 | 
| sam_grove | 0:d35446f60233 | 9 | * | 
| sam_grove | 0:d35446f60233 | 10 | * Unless required by applicable law or agreed to in writing, software | 
| sam_grove | 0:d35446f60233 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
| sam_grove | 0:d35446f60233 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
| sam_grove | 0:d35446f60233 | 13 | * See the License for the specific language governing permissions and | 
| sam_grove | 0:d35446f60233 | 14 | * limitations under the License. | 
| sam_grove | 0:d35446f60233 | 15 | */ | 
| sam_grove | 8:4b7f97a5597b | 16 | |
| Christopher Haster | 21:35ed15069189 | 17 | #ifndef SOCKET_INTERFACE_H | 
| Christopher Haster | 21:35ed15069189 | 18 | #define SOCKET_INTERFACE_H | 
| bridadan | 2:ce08986b18b5 | 19 | |
| sam_grove | 8:4b7f97a5597b | 20 | #include "stdint.h" | 
| sam_grove | 8:4b7f97a5597b | 21 | |
| sam_grove | 8:4b7f97a5597b | 22 | |
| sam_grove | 63:531f4c27f360 | 23 | /** | 
| sam_grove | 63:531f4c27f360 | 24 | * @enum ns_protocol_t | 
| sam_grove | 63:531f4c27f360 | 25 | * @brief enum of socket protocols | 
| sam_grove | 8:4b7f97a5597b | 26 | */ | 
| Christopher Haster | 57:3c873fab4207 | 27 | enum ns_protocol_t { | 
| sam_grove | 63:531f4c27f360 | 28 | NS_TCP, /*!< Socket is of TCP type */ | 
| sam_grove | 63:531f4c27f360 | 29 | NS_UDP, /*!< Socket is of UDP type */ | 
| Christopher Haster | 42:49893d13c432 | 30 | }; | 
| sam_grove | 8:4b7f97a5597b | 31 | |
| Christopher Haster | 21:35ed15069189 | 32 | |
| Christopher Haster | 21:35ed15069189 | 33 | /** SocketInterface class | 
| Christopher Haster | 21:35ed15069189 | 34 | * Common interface for implementation specific sockets created through | 
| Christopher Haster | 21:35ed15069189 | 35 | * network interfaces. This class is used internally by the | 
| Christopher Haster | 21:35ed15069189 | 36 | * TCPSocket and UDPSocket classes | 
| sam_grove | 8:4b7f97a5597b | 37 | */ | 
| Christopher Haster | 21:35ed15069189 | 38 | class SocketInterface | 
| sam_grove | 8:4b7f97a5597b | 39 | { | 
| sam_grove | 8:4b7f97a5597b | 40 | public: | 
| sam_grove | 63:531f4c27f360 | 41 | |
| Christopher Haster | 53:26b5f1c69822 | 42 | virtual ~SocketInterface() {} | 
| Christopher Haster | 53:26b5f1c69822 | 43 | |
| Christopher Haster | 21:35ed15069189 | 44 | /** Open a connection to the underlying address | 
| Christopher Haster | 36:eab792dfb0d8 | 45 | * @param ip IP address to connect to | 
| Christopher Haster | 36:eab792dfb0d8 | 46 | * @param port Port to connect to | 
| Christopher Haster | 21:35ed15069189 | 47 | * @return 0 on success | 
| sam_grove | 8:4b7f97a5597b | 48 | */ | 
| Christopher Haster | 36:eab792dfb0d8 | 49 | virtual int32_t open(const char *ip, uint16_t port) = 0; | 
| Christopher Haster | 21:35ed15069189 | 50 | |
| Christopher Haster | 21:35ed15069189 | 51 | /** Close an open connection | 
| Christopher Haster | 21:35ed15069189 | 52 | * @return 0 on success | 
| Christopher Haster | 21:35ed15069189 | 53 | */ | 
| Christopher Haster | 21:35ed15069189 | 54 | virtual int32_t close() = 0; | 
| sam_grove | 8:4b7f97a5597b | 55 | |
| Christopher Haster | 21:35ed15069189 | 56 | /** Send data | 
| Christopher Haster | 21:35ed15069189 | 57 | * @param data Buffer of data to send | 
| Christopher Haster | 48:b3bbe28a7963 | 58 | * @param size Size of data to send | 
| Christopher Haster | 21:35ed15069189 | 59 | * @return 0 on success | 
| sam_grove | 8:4b7f97a5597b | 60 | */ | 
| Christopher Haster | 48:b3bbe28a7963 | 61 | virtual int32_t send(const void *data, uint32_t size) = 0; | 
| sam_grove | 8:4b7f97a5597b | 62 | |
| Christopher Haster | 48:b3bbe28a7963 | 63 | /** Receive data | 
| Christopher Haster | 48:b3bbe28a7963 | 64 | * @note | 
| sam_grove | 63:531f4c27f360 | 65 | * This call should return immediately with a value of 0 | 
| Christopher Haster | 48:b3bbe28a7963 | 66 | * if no data is available. | 
| Christopher Haster | 48:b3bbe28a7963 | 67 | * | 
| Christopher Haster | 48:b3bbe28a7963 | 68 | * @param data A buffer to store the data in | 
| Christopher Haster | 48:b3bbe28a7963 | 69 | * @param size Size of buffer | 
| Christopher Haster | 48:b3bbe28a7963 | 70 | * @return Number of bytes received or a negative value on failure | 
| sam_grove | 8:4b7f97a5597b | 71 | */ | 
| Christopher Haster | 48:b3bbe28a7963 | 72 | virtual int32_t recv(void *data, uint32_t size) = 0; | 
| Christopher Haster | 58:1caa187fa5af | 73 | |
| Christopher Haster | 58:1caa187fa5af | 74 | /** Status of the socket | 
| Christopher Haster | 58:1caa187fa5af | 75 | * @return True if connected | 
| Christopher Haster | 58:1caa187fa5af | 76 | */ | 
| sam_grove | 63:531f4c27f360 | 77 | virtual bool isConnected() { | 
| Christopher Haster | 58:1caa187fa5af | 78 | // By default return true if socket was created successfully | 
| Christopher Haster | 58:1caa187fa5af | 79 | return true; | 
| Christopher Haster | 58:1caa187fa5af | 80 | } | 
| sam_grove | 8:4b7f97a5597b | 81 | }; | 
| sam_grove | 8:4b7f97a5597b | 82 | |
| bridadan | 1:291a9d61e58a | 83 | #endif | 
