WORKS
Dependencies: MAX44000 PWM_Tone_Library nexpaq_mdk
Fork of LED_Demo by
TCPServer.h
00001 /* TCPServer 00002 * Copyright (c) 2015 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef TCPSERVER_H 00018 #define TCPSERVER_H 00019 00020 #include "network-socket/Socket.h" 00021 #include "network-socket/TCPSocket.h" 00022 #include "network-socket/NetworkStack.h" 00023 #include "network-socket/NetworkInterface.h" 00024 #include "rtos/Semaphore.h" 00025 00026 00027 /** TCP socket server 00028 */ 00029 class TCPServer : public Socket { 00030 public: 00031 /** Create an uninitialized socket 00032 * 00033 * Must call open to initialize the socket on a network stack. 00034 */ 00035 TCPServer(); 00036 00037 /** Create a socket on a network interface 00038 * 00039 * Creates and opens a socket on the network stack of the given 00040 * network interface. 00041 * 00042 * @param stack Network stack as target for socket 00043 */ 00044 template <typename S> 00045 TCPServer(S *stack) 00046 : _pending(0), _accept_sem(0) 00047 { 00048 open(stack); 00049 } 00050 00051 /** Destroy a socket 00052 * 00053 * Closes socket if the socket is still open 00054 */ 00055 virtual ~TCPServer(); 00056 00057 /** Listen for connections on a TCP socket 00058 * 00059 * Marks the socket as a passive socket that can be used to accept 00060 * incoming connections. 00061 * 00062 * @param backlog Number of pending connections that can be queued 00063 * simultaneously, defaults to 1 00064 * @return 0 on success, negative error code on failure 00065 */ 00066 int listen(int backlog = 1); 00067 00068 /** Accepts a connection on a TCP socket 00069 * 00070 * The server socket must be bound and set to listen for connections. 00071 * On a new connection, creates a network socket using the specified 00072 * socket instance. 00073 * 00074 * By default, accept blocks until data is sent. If socket is set to 00075 * non-blocking or times out, NSAPI_ERROR_WOULD_BLOCK is returned 00076 * immediately. 00077 * 00078 * @param socket TCPSocket instance that will handle the incoming connection. 00079 * @param address Destination for the remote address or NULL 00080 * @return 0 on success, negative error code on failure 00081 */ 00082 int accept(TCPSocket *connection, SocketAddress *address = NULL); 00083 00084 protected: 00085 virtual nsapi_protocol_t get_proto(); 00086 virtual void event(); 00087 00088 volatile unsigned _pending; 00089 rtos::Semaphore _accept_sem; 00090 }; 00091 00092 00093 #endif
Generated on Tue Jul 12 2022 12:28:52 by
1.7.2
