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.cpp
00001 /* 00002 * Copyright (c) 2018 ARM Limited 00003 * SPDX-License-Identifier: Apache-2.0 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 00018 #include "DTLSSocket.h" 00019 00020 #define TRACE_GROUP "TLSS" 00021 #include "mbed-trace/mbed_trace.h" 00022 00023 // This class requires Mbed TLS SSL/TLS client code 00024 #if defined(MBEDTLS_SSL_CLI_C) 00025 00026 nsapi_error_t DTLSSocket::connect(const char *host, uint16_t port) 00027 { 00028 SocketAddress addr; 00029 nsapi_error_t ret; 00030 00031 ret = _udp_socket.getpeername (&addr); 00032 if (ret != NSAPI_ERROR_NO_CONNECTION ) { 00033 return ret; 00034 } 00035 00036 if (!addr || ret == NSAPI_ERROR_NO_CONNECTION ) { 00037 nsapi_error_t err = _udp_socket._stack->gethostbyname(host, &addr); 00038 if (err) { 00039 return NSAPI_ERROR_DNS_FAILURE ; 00040 } 00041 00042 addr.set_port(port); 00043 00044 set_hostname(host); 00045 _udp_socket.connect(addr); // UDPSocket::connect() cannot fail 00046 } 00047 00048 return connect(addr); 00049 } 00050 00051 DTLSSocket::~DTLSSocket() 00052 { 00053 // Make sure that DTLSSocketWrapper::close() is called before the transport is 00054 // destroyed. 00055 close(); 00056 } 00057 00058 #endif // MBEDTLS_SSL_CLI_C
Generated on Tue Jul 12 2022 13:54:17 by
