WORKS
Dependencies: MAX44000 PWM_Tone_Library nexpaq_mdk
Fork of LED_Demo by
TCPStream.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_TCPSTREAM_H__ 00018 #define __MBED_NET_SOCKETS_V0_TCPSTREAM_H__ 00019 #include <stddef.h> 00020 #include <stdint.h> 00021 #include "Ticker.h" 00022 #include "TCPAsynch.h" 00023 00024 namespace mbed { 00025 namespace Sockets { 00026 namespace v0 { 00027 00028 class TCPStream: public TCPAsynch { 00029 public: 00030 typedef FunctionPointer1<void, TCPStream *> ConnectHandler_t; 00031 typedef FunctionPointer1<void, TCPStream *> DisconnectHandler_t; 00032 /** 00033 * TCP socket constructor. 00034 * Does not allocate an underlying TCP Socket instance. 00035 * @param[in] stack The network stack to use for this socket. 00036 */ 00037 TCPStream(const socket_stack_t stack); 00038 /** 00039 * TCP socket constructor. 00040 * Does not allocate an underlying TCP Socket instance. This version is for use with 00041 * TCPListener::accept(). The struct socket instance passed into this constructor should 00042 * be a fully initialized socket, with an initialized impl field. TCPStream will copy 00043 * the stack, API, protocol family, and impl pointer from sock. 00044 * @param[in] sock The TCP socket instance to use for this TCP socket. 00045 */ 00046 TCPStream(const struct socket * sock); 00047 /** 00048 * TCP socket destructor 00049 */ 00050 ~TCPStream(); 00051 /** 00052 * Connect to a remote host. 00053 * Initates the TCP Connection process. onConnect is called when the connection 00054 * is acknowledged. 00055 * @param[in] address The remote host to connect to 00056 * @param[in] port The remote port to connect to 00057 * @param[in] onConnect 00058 * @return SOCKET_ERROR_NONE on success, or an error code on failure 00059 */ 00060 virtual socket_error_t connect(const SocketAddr &address, const uint16_t port, 00061 const ConnectHandler_t &onConnect); 00062 /** 00063 * Set a disconnect handler 00064 * This handler only needs to be configured once onConnect has been called 00065 * @param[in] h the handler to call when a connection is disconnected 00066 */ 00067 virtual void setOnDisconnect(const DisconnectHandler_t &h) { _onDisconnect = h; } 00068 00069 protected: 00070 /** 00071 * Internal event handler 00072 * @param[in] ev the event to handle 00073 */ 00074 void _eventHandler(struct socket_event *ev); 00075 00076 protected: 00077 ConnectHandler_t _onConnect; 00078 DisconnectHandler_t _onDisconnect; 00079 }; 00080 } // namespace v0 00081 } // namespace Sockets 00082 } // namespace mbed 00083 #endif // __MBED_NET_SOCKETS_V0_TCPSTREAM_H__
Generated on Tue Jul 12 2022 12:28:52 by
1.7.2
