NetworkSocketAPI
Dependents: HelloWizFi250Interface
Fork of NetworkSocketAPI by
Socket.h@88:6cfd38609828, 2016-04-06 (annotated)
- Committer:
- geky
- Date:
- Wed Apr 06 13:50:19 2016 +0000
- Revision:
- 88:6cfd38609828
- Parent:
- 87:94e2cf3a06be
- Child:
- 89:b1d417383c0d
Refactored WiFi enum
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Christopher Haster |
78:0914f9b9b24b | 1 | /* Socket |
Christopher Haster |
78:0914f9b9b24b | 2 | * Copyright (c) 2015 ARM Limited |
Christopher Haster |
72:6a8b52ee83ed | 3 | * |
Christopher Haster |
78:0914f9b9b24b | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Christopher Haster |
78:0914f9b9b24b | 5 | * you may not use this file except in compliance with the License. |
Christopher Haster |
78:0914f9b9b24b | 6 | * You may obtain a copy of the License at |
Christopher Haster |
72:6a8b52ee83ed | 7 | * |
Christopher Haster |
78:0914f9b9b24b | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Christopher Haster |
72:6a8b52ee83ed | 9 | * |
Christopher Haster |
78:0914f9b9b24b | 10 | * Unless required by applicable law or agreed to in writing, software |
Christopher Haster |
78:0914f9b9b24b | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Christopher Haster |
78:0914f9b9b24b | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Christopher Haster |
78:0914f9b9b24b | 13 | * See the License for the specific language governing permissions and |
Christopher Haster |
78:0914f9b9b24b | 14 | * limitations under the License. |
Christopher Haster |
72:6a8b52ee83ed | 15 | */ |
Christopher Haster |
78:0914f9b9b24b | 16 | |
Christopher Haster |
72:6a8b52ee83ed | 17 | #ifndef SOCKET_H |
Christopher Haster |
72:6a8b52ee83ed | 18 | #define SOCKET_H |
Christopher Haster |
72:6a8b52ee83ed | 19 | |
Christopher Haster |
79:43a7e8c0d6cc | 20 | #include "SocketAddress.h" |
Christopher Haster |
79:43a7e8c0d6cc | 21 | #include "NetworkInterface.h" |
Christopher Haster |
74:ef2470ca328b | 22 | |
Christopher Haster |
72:6a8b52ee83ed | 23 | /** Abstract socket class |
Christopher Haster |
74:ef2470ca328b | 24 | */ |
Christopher Haster |
72:6a8b52ee83ed | 25 | class Socket { |
Christopher Haster |
72:6a8b52ee83ed | 26 | public: |
Christopher Haster |
72:6a8b52ee83ed | 27 | /** Socket lifetime |
Christopher Haster |
72:6a8b52ee83ed | 28 | */ |
Christopher Haster |
81:1600369a29dd | 29 | virtual ~Socket(); |
Christopher Haster |
72:6a8b52ee83ed | 30 | |
Christopher Haster |
72:6a8b52ee83ed | 31 | /** Set blocking or non-blocking mode of the socket |
Christopher Haster |
72:6a8b52ee83ed | 32 | \param blocking true for blocking mode, false for non-blocking mode. |
Christopher Haster |
72:6a8b52ee83ed | 33 | */ |
Christopher Haster |
72:6a8b52ee83ed | 34 | void set_blocking(bool blocking); |
Christopher Haster |
72:6a8b52ee83ed | 35 | |
Christopher Haster |
74:ef2470ca328b | 36 | /** Set timeout on a socket operation if blocking behaviour is enabled |
Christopher Haster |
72:6a8b52ee83ed | 37 | \param timeout timeout in ms |
Christopher Haster |
72:6a8b52ee83ed | 38 | */ |
Christopher Haster |
72:6a8b52ee83ed | 39 | void set_timeout(unsigned int timeout); |
Christopher Haster |
72:6a8b52ee83ed | 40 | |
Christopher Haster |
72:6a8b52ee83ed | 41 | /** Set socket options |
Christopher Haster |
76:bbe51641f405 | 42 | \param optname Option ID |
Christopher Haster |
76:bbe51641f405 | 43 | \param optval Option value |
Christopher Haster |
76:bbe51641f405 | 44 | \param optlen Length of the option value |
Christopher Haster |
76:bbe51641f405 | 45 | \return 0 on success, negative on failure |
Christopher Haster |
72:6a8b52ee83ed | 46 | */ |
geky | 86:7ca9776b9cc0 | 47 | int set_option(int optname, const void *optval, unsigned optlen); |
Christopher Haster |
72:6a8b52ee83ed | 48 | |
Christopher Haster |
72:6a8b52ee83ed | 49 | /** Get socket options |
Christopher Haster |
76:bbe51641f405 | 50 | \param optname Option ID |
Christopher Haster |
76:bbe51641f405 | 51 | \param optval Buffer pointer where to write the option value |
Christopher Haster |
76:bbe51641f405 | 52 | \param optlen Length of the option value |
Christopher Haster |
76:bbe51641f405 | 53 | \return 0 on success, negative on failure |
Christopher Haster |
72:6a8b52ee83ed | 54 | */ |
geky | 86:7ca9776b9cc0 | 55 | int get_option(int optname, void *optval, unsigned *optlen); |
Christopher Haster |
72:6a8b52ee83ed | 56 | |
Christopher Haster |
72:6a8b52ee83ed | 57 | /** Close the socket |
Christopher Haster |
72:6a8b52ee83ed | 58 | \param shutdown free the left-over data in message queues |
Christopher Haster |
72:6a8b52ee83ed | 59 | */ |
Christopher Haster |
72:6a8b52ee83ed | 60 | int close(bool shutdown=true); |
Christopher Haster |
79:43a7e8c0d6cc | 61 | |
Christopher Haster |
79:43a7e8c0d6cc | 62 | protected: |
geky | 87:94e2cf3a06be | 63 | Socket(NetworkInterface *iface, nsapi_protocol_t proto); |
Christopher Haster |
79:43a7e8c0d6cc | 64 | |
Christopher Haster |
81:1600369a29dd | 65 | static void thunk(void *); |
Christopher Haster |
81:1600369a29dd | 66 | |
Christopher Haster |
79:43a7e8c0d6cc | 67 | NetworkInterface *_iface; |
Christopher Haster |
79:43a7e8c0d6cc | 68 | void *_socket; |
Christopher Haster |
79:43a7e8c0d6cc | 69 | bool _blocking; |
Christopher Haster |
79:43a7e8c0d6cc | 70 | unsigned _timeout; |
Christopher Haster |
72:6a8b52ee83ed | 71 | }; |
Christopher Haster |
72:6a8b52ee83ed | 72 | |
Christopher Haster |
72:6a8b52ee83ed | 73 | #endif |