NetworkSocketAPI
Dependents: HelloWizFi250Interface
Fork of NetworkSocketAPI by
TCPServer.h@103:37decbcb1108, 2016-04-19 (annotated)
- Committer:
- Christopher Haster
- Date:
- Tue Apr 19 18:26:12 2016 -0500
- Revision:
- 103:37decbcb1108
- Parent:
- 98:0f614f1d0398
- Child:
- 104:d28d8b508e7c
Revisited documentation for Socket API
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Christopher Haster |
89:b1d417383c0d | 1 | /* Socket |
Christopher Haster |
89:b1d417383c0d | 2 | * Copyright (c) 2015 ARM Limited |
Christopher Haster |
89:b1d417383c0d | 3 | * |
Christopher Haster |
89:b1d417383c0d | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Christopher Haster |
89:b1d417383c0d | 5 | * you may not use this file except in compliance with the License. |
Christopher Haster |
89:b1d417383c0d | 6 | * You may obtain a copy of the License at |
Christopher Haster |
89:b1d417383c0d | 7 | * |
Christopher Haster |
89:b1d417383c0d | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Christopher Haster |
89:b1d417383c0d | 9 | * |
Christopher Haster |
89:b1d417383c0d | 10 | * Unless required by applicable law or agreed to in writing, software |
Christopher Haster |
89:b1d417383c0d | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Christopher Haster |
89:b1d417383c0d | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Christopher Haster |
89:b1d417383c0d | 13 | * See the License for the specific language governing permissions and |
Christopher Haster |
89:b1d417383c0d | 14 | * limitations under the License. |
Christopher Haster |
89:b1d417383c0d | 15 | */ |
Christopher Haster |
89:b1d417383c0d | 16 | |
Christopher Haster |
89:b1d417383c0d | 17 | #ifndef TCPSERVER_H |
Christopher Haster |
89:b1d417383c0d | 18 | #define TCPSERVER_H |
Christopher Haster |
89:b1d417383c0d | 19 | |
Christopher Haster |
89:b1d417383c0d | 20 | #include "Socket.h" |
Christopher Haster |
89:b1d417383c0d | 21 | #include "TCPSocket.h" |
Christopher Haster |
89:b1d417383c0d | 22 | #include "NetworkInterface.h" |
Christopher Haster |
89:b1d417383c0d | 23 | |
Christopher Haster |
103:37decbcb1108 | 24 | /** TCP socket server |
Christopher Haster |
89:b1d417383c0d | 25 | */ |
Christopher Haster |
89:b1d417383c0d | 26 | class TCPServer : public Socket { |
Christopher Haster |
89:b1d417383c0d | 27 | public: |
Christopher Haster |
103:37decbcb1108 | 28 | /** Create an uninitialized socket |
Christopher Haster |
103:37decbcb1108 | 29 | * |
Christopher Haster |
103:37decbcb1108 | 30 | * Must call open to initialize the socket on a network stack. |
Christopher Haster |
89:b1d417383c0d | 31 | */ |
Christopher Haster |
90:0a988e4abb72 | 32 | TCPServer(); |
Christopher Haster |
90:0a988e4abb72 | 33 | |
Christopher Haster |
103:37decbcb1108 | 34 | /** Create a socket on a network stack |
Christopher Haster |
103:37decbcb1108 | 35 | * |
Christopher Haster |
103:37decbcb1108 | 36 | * Creates and opens a socket on the specified network stack. |
Christopher Haster |
103:37decbcb1108 | 37 | * |
Christopher Haster |
103:37decbcb1108 | 38 | * @param iface Network stack as target for socket |
Christopher Haster |
103:37decbcb1108 | 39 | */ |
Christopher Haster |
103:37decbcb1108 | 40 | TCPServer(NetworkInterface *iface); |
Christopher Haster |
103:37decbcb1108 | 41 | |
Christopher Haster |
103:37decbcb1108 | 42 | /** Opens a socket |
Christopher Haster |
103:37decbcb1108 | 43 | * |
Christopher Haster |
103:37decbcb1108 | 44 | * Creates a network socket on the specified network stack. |
Christopher Haster |
103:37decbcb1108 | 45 | * Not needed if stack is passed to the socket's constructor. |
Christopher Haster |
103:37decbcb1108 | 46 | * |
Christopher Haster |
103:37decbcb1108 | 47 | * @param iface Network stack as target for socket |
Christopher Haster |
103:37decbcb1108 | 48 | * @return 0 on success, negative error code on failure |
Christopher Haster |
90:0a988e4abb72 | 49 | */ |
Christopher Haster |
90:0a988e4abb72 | 50 | virtual int open(NetworkInterface *iface); |
Christopher Haster |
89:b1d417383c0d | 51 | |
Christopher Haster |
103:37decbcb1108 | 52 | /** Listen for connections on a TCP socket |
Christopher Haster |
103:37decbcb1108 | 53 | * |
Christopher Haster |
103:37decbcb1108 | 54 | * Marks the socket as a passive socket that can be used to accept |
Christopher Haster |
103:37decbcb1108 | 55 | * incoming connections. |
Christopher Haster |
103:37decbcb1108 | 56 | * |
Christopher Haster |
103:37decbcb1108 | 57 | * @param backlog Number of pending connections that can be queued |
Christopher Haster |
103:37decbcb1108 | 58 | * simultaneously, defaults to 1 |
Christopher Haster |
103:37decbcb1108 | 59 | * @return 0 on success, negative error code on failure |
Christopher Haster |
89:b1d417383c0d | 60 | */ |
Christopher Haster |
103:37decbcb1108 | 61 | int listen(int backlog = 1); |
Christopher Haster |
89:b1d417383c0d | 62 | |
Christopher Haster |
103:37decbcb1108 | 63 | /** Accepts a connection on a TCP socket |
Christopher Haster |
103:37decbcb1108 | 64 | * |
Christopher Haster |
103:37decbcb1108 | 65 | * The server socket must be bound and set to listen for connections. |
Christopher Haster |
103:37decbcb1108 | 66 | * On a new connection, creates a network socket using the specified |
Christopher Haster |
103:37decbcb1108 | 67 | * socket instance. |
Christopher Haster |
103:37decbcb1108 | 68 | * |
Christopher Haster |
103:37decbcb1108 | 69 | * By default, accept blocks until data is sent. If socket is set to |
Christopher Haster |
103:37decbcb1108 | 70 | * non-blocking or times out, NSAPI_ERROR_WOULD_BLOCK is returned |
Christopher Haster |
103:37decbcb1108 | 71 | * immediately. |
Christopher Haster |
103:37decbcb1108 | 72 | * |
Christopher Haster |
103:37decbcb1108 | 73 | * @param socket TCPSocket instance that will handle the incoming connection. |
Christopher Haster |
103:37decbcb1108 | 74 | * @return 0 on success, negative error code on failure |
Christopher Haster |
89:b1d417383c0d | 75 | */ |
Christopher Haster |
89:b1d417383c0d | 76 | int accept(TCPSocket *connection); |
Christopher Haster |
89:b1d417383c0d | 77 | }; |
Christopher Haster |
89:b1d417383c0d | 78 | |
Christopher Haster |
89:b1d417383c0d | 79 | #endif |