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: TYBLE16_simple_data_logger TYBLE16_MP3_Air
DTLSSocket.h
00001 /** @file DTLSSocket.h DTLSSocket */ 00002 /* 00003 * Copyright (c) 2018 ARM Limited 00004 * SPDX-License-Identifier: Apache-2.0 00005 * 00006 * Licensed under the Apache License, Version 2.0 (the "License"); 00007 * you may not use this file except in compliance with the License. 00008 * You may obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 */ 00018 /** @addtogroup netsocket 00019 * @{ 00020 */ 00021 00022 #ifndef DTLSSOCKET_H 00023 #define DTLSSOCKET_H 00024 00025 #include "DTLSSocketWrapper.h" 00026 #include "SocketAddress.h" 00027 #include "UDPSocket.h" 00028 00029 // This class requires Mbed TLS SSL/TLS client code 00030 #if defined(MBEDTLS_SSL_CLI_C) || defined(DOXYGEN_ONLY) 00031 00032 /** 00033 * \brief DTLSSocket implement DTLS stream over UDP Socket. 00034 * 00035 * This is a helper class that uses DTLSSocketWrapper with 00036 * internal UDPSocket. 00037 */ 00038 00039 class DTLSSocket : public DTLSSocketWrapper { 00040 public: 00041 /** Create an uninitialized DTLS socket. 00042 * 00043 * Must call open to initialize the socket on a network stack. 00044 */ 00045 DTLSSocket() : DTLSSocketWrapper(&_udp_socket) {} 00046 00047 /** Destroy the DTLSSocket and closes the transport. 00048 */ 00049 virtual ~DTLSSocket(); 00050 00051 /** Create a socket on a network interface. 00052 * 00053 * Creates and opens a socket on the network stack of the given 00054 * network interface. 00055 * If hostname is also given, user is not required to call set_hostname() later. 00056 * 00057 * @param stack Network stack as target for socket. 00058 * @param hostname Hostname used for certificate verification. 00059 */ 00060 template <typename S> 00061 DTLSSocket(S *stack, const char *hostname = NULL) : DTLSSocketWrapper(&_udp_socket, hostname) 00062 { 00063 nsapi_error_t ret = _udp_socket.open(stack); 00064 MBED_ASSERT(ret == NSAPI_ERROR_OK ); 00065 } 00066 00067 /** Opens a socket. 00068 * 00069 * Creates a network socket on the network stack of the given 00070 * network interface. Not needed if stack is passed to the 00071 * socket's constructor. 00072 * 00073 * @param stack Network stack as target for socket. 00074 * @return NSAPI_ERROR_OK on success, negative error code on failure. 00075 * See @ref UDPSocket::open. 00076 */ 00077 virtual nsapi_error_t open(NetworkStack *stack) 00078 { 00079 return _udp_socket.open(stack); 00080 } 00081 00082 template <typename S> 00083 nsapi_error_t open(S *stack) 00084 { 00085 return open(nsapi_create_stack(stack)); 00086 } 00087 00088 using DTLSSocketWrapper::connect; 00089 00090 /** Connects TCP socket to a remote host. 00091 * 00092 * Initiates a connection to a remote server specified by either 00093 * a domain name or an IP address and a port. 00094 * 00095 * @param host Hostname of the remote host. 00096 * @param port Port of the remote host. 00097 * @return NSAPI_ERROR_OK on success, negative error code on failure. 00098 * See @ref TLSSocketWrapper::connect. 00099 */ 00100 MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") 00101 nsapi_error_t connect(const char *host, uint16_t port); 00102 00103 private: 00104 UDPSocket _udp_socket; 00105 }; 00106 00107 #endif 00108 #endif 00109 /** @} */
Generated on Tue Jul 12 2022 13:54:17 by
