nkjnm

Dependencies:   MAX44000 nexpaq_mdk

Fork of LED_Demo by Maxim nexpaq

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TCPListener.h Source File

TCPListener.h

00001 /*
00002  * PackageLicenseDeclared: Apache-2.0
00003  * Copyright (c) 2015 ARM Limited
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 #ifndef __MBED_NET_SOCKETS_V0_TCPLISTENER_H__
00018 #define __MBED_NET_SOCKETS_V0_TCPLISTENER_H__
00019 
00020 #include <stddef.h>
00021 #include <stdint.h>
00022 #include "mbed/FunctionPointer.h"
00023 #include "TCPAsynch.h"
00024 #include "TCPStream.h"
00025 
00026 namespace mbed {
00027 namespace Sockets {
00028 namespace v0 {
00029 /** \brief TCPListener: a TCP server socket
00030  *  The TCPListener listens for incoming connections.  Prior to listening, the
00031  *  TCPListener must be bound to a port and, optionally, an address.
00032  */
00033 class TCPListener: public TCPAsynch {
00034 public:
00035     typedef FunctionPointer2<void, TCPListener *, void *>  IncomingHandler_t ;
00036     /**
00037      *  The TCP Listener constructor.
00038      * @param[in] stack the network stack to use
00039      */
00040     TCPListener(const socket_stack_t stack);
00041 
00042     /**
00043      *  The TCP Listener destructor
00044      *  This performs teardown of the listener
00045      */
00046     ~TCPListener();
00047 
00048     /**
00049      *  Begin listening for incoming connections.
00050      *  The supplied listenHandler will be called whenever an incoming connection arrives
00051      *  To reject a connection, the event handler needs to set the reject flag in the event.
00052      * @param[in] listenHandler The event handler to call when an incoming connection arrives
00053      * @param[in] backlog The number of connection requests to keep in the backlog
00054      * @return SOCKET_ERROR_NONE on success, or an error code on failure
00055      */
00056     socket_error_t start_listening(IncomingHandler_t  listenHandler, uint32_t backlog = 0);
00057     /**
00058      * Stop listening for incoming connections
00059      * After this call, the server will reject incoming connections until start_listening is called again
00060      * @return SOCKET_ERROR_NONE on success, or an error code on failure
00061      */
00062     socket_error_t stop_listening();
00063 
00064     /**
00065      * accept is a utility function for constructing a new TCPStream from an incoming connection
00066      * The event passed to the listenHandler contains a pointer to a low level implementation of an
00067      * already connected socket.  This function
00068      * @param new_impl
00069      * @return
00070      */
00071     virtual TCPStream * accept(void *new_impl);
00072     virtual void reject(void *new_impl);
00073 
00074 protected:
00075     /**
00076      * Internal event handler
00077      * @param[in] ev the event to handle
00078      */
00079     void _eventHandler(struct socket_event *ev);
00080 
00081     IncomingHandler_t  _onIncoming;
00082 };
00083 } // namespace v0
00084 } // namespace Sockets
00085 } // namespace mbed
00086 #endif // __MBED_NET_SOCKETS_V0_TCPLISTENER_H__