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.
Dependents: HelloWizFi250Interface
Fork of NetworkSocketAPI by
TCPServer.h@75:dea0cdb42241, 2016-04-05 (annotated)
- Committer:
- Christopher Haster
- Date:
- Tue Apr 05 06:56:22 2016 -0500
- Revision:
- 75:dea0cdb42241
- Parent:
- 73:968f7b32278f
- Child:
- 77:b66a6984ed2d
Introduced SocketAddress class for efficient handling of netork addresses
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Christopher Haster |
72:6a8b52ee83ed | 1 | /* Copyright (C) 2012 mbed.org, MIT License |
| Christopher Haster |
72:6a8b52ee83ed | 2 | * |
| Christopher Haster |
72:6a8b52ee83ed | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
| Christopher Haster |
72:6a8b52ee83ed | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
| Christopher Haster |
72:6a8b52ee83ed | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
| Christopher Haster |
72:6a8b52ee83ed | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
| Christopher Haster |
72:6a8b52ee83ed | 7 | * furnished to do so, subject to the following conditions: |
| Christopher Haster |
72:6a8b52ee83ed | 8 | * |
| Christopher Haster |
72:6a8b52ee83ed | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
| Christopher Haster |
72:6a8b52ee83ed | 10 | * substantial portions of the Software. |
| Christopher Haster |
72:6a8b52ee83ed | 11 | * |
| Christopher Haster |
72:6a8b52ee83ed | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
| Christopher Haster |
72:6a8b52ee83ed | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| Christopher Haster |
72:6a8b52ee83ed | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| Christopher Haster |
72:6a8b52ee83ed | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| Christopher Haster |
72:6a8b52ee83ed | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| Christopher Haster |
72:6a8b52ee83ed | 17 | */ |
| Christopher Haster |
72:6a8b52ee83ed | 18 | #ifndef TCPSERVER_H |
| Christopher Haster |
72:6a8b52ee83ed | 19 | #define TCPSERVER_H |
| Christopher Haster |
72:6a8b52ee83ed | 20 | |
| Christopher Haster |
72:6a8b52ee83ed | 21 | #include "Socket.h" |
| Christopher Haster |
72:6a8b52ee83ed | 22 | #include "TCPSocket.h" |
| Christopher Haster |
72:6a8b52ee83ed | 23 | |
| Christopher Haster |
72:6a8b52ee83ed | 24 | /** TCP Server. |
| Christopher Haster |
72:6a8b52ee83ed | 25 | */ |
| Christopher Haster |
72:6a8b52ee83ed | 26 | class TCPServer : public Socket { |
| Christopher Haster |
72:6a8b52ee83ed | 27 | public: |
| Christopher Haster |
72:6a8b52ee83ed | 28 | /** TCP Server lifetime |
| Christopher Haster |
72:6a8b52ee83ed | 29 | */ |
| Christopher Haster |
72:6a8b52ee83ed | 30 | TCPServer(); |
| Christopher Haster |
72:6a8b52ee83ed | 31 | ~TCPServer(); |
| Christopher Haster |
72:6a8b52ee83ed | 32 | |
| Christopher Haster |
72:6a8b52ee83ed | 33 | /** Bind a socket to a specific port |
| Christopher Haster |
72:6a8b52ee83ed | 34 | \param port The port to listen for incoming connections on |
| Christopher Haster |
72:6a8b52ee83ed | 35 | \return 0 on success, negative on failure |
| Christopher Haster |
72:6a8b52ee83ed | 36 | */ |
| Christopher Haster |
72:6a8b52ee83ed | 37 | int bind(int port); |
| Christopher Haster |
72:6a8b52ee83ed | 38 | |
| Christopher Haster |
72:6a8b52ee83ed | 39 | /** Start listening for incoming connections |
| Christopher Haster |
72:6a8b52ee83ed | 40 | \param backlog Number of pending connections that can be queued up at any |
| Christopher Haster |
72:6a8b52ee83ed | 41 | one time [Default: 1] |
| Christopher Haster |
72:6a8b52ee83ed | 42 | \return 0 on success, negative on failure |
| Christopher Haster |
72:6a8b52ee83ed | 43 | */ |
| Christopher Haster |
72:6a8b52ee83ed | 44 | int listen(int backlog=1); |
| Christopher Haster |
72:6a8b52ee83ed | 45 | |
| Christopher Haster |
72:6a8b52ee83ed | 46 | /** Accept a new connection. |
| Christopher Haster |
72:6a8b52ee83ed | 47 | \param socket A TCPSocket instance that will handle the incoming connection. |
| Christopher Haster |
72:6a8b52ee83ed | 48 | \return 0 on success, negative on failure. |
| Christopher Haster |
72:6a8b52ee83ed | 49 | */ |
| Christopher Haster |
75:dea0cdb42241 | 50 | int accept(TCPSocket *connection); |
| Christopher Haster |
73:968f7b32278f | 51 | |
| Christopher Haster |
73:968f7b32278f | 52 | /** Register a callback on when a new connection is ready |
| Christopher Haster |
73:968f7b32278f | 53 | \param callback Function to call when accept will succeed, may be called in |
| Christopher Haster |
73:968f7b32278f | 54 | interrupt context. |
| Christopher Haster |
73:968f7b32278f | 55 | */ |
| Christopher Haster |
73:968f7b32278f | 56 | void attach_accept(FuncPtr<void()> callback); |
| Christopher Haster |
72:6a8b52ee83ed | 57 | }; |
| Christopher Haster |
72:6a8b52ee83ed | 58 | |
| Christopher Haster |
72:6a8b52ee83ed | 59 | #endif |
