File tree Expand file tree Collapse file tree 6 files changed +37
-13
lines changed Expand file tree Collapse file tree 6 files changed +37
-13
lines changed Original file line number Diff line number Diff line change 25
25
26
26
nsapi_error_t DTLSSocket::connect (const char *host, uint16_t port)
27
27
{
28
- if (!_remote_address) {
29
- nsapi_error_t err = _stack->gethostbyname (host, &_remote_address);
28
+ SocketAddress addr;
29
+ nsapi_error_t ret;
30
+
31
+ ret = _udp_socket.getpeername (&addr);
32
+ if (ret != NSAPI_ERROR_NO_CONNECTION) {
33
+ return ret;
34
+ }
35
+
36
+ if (!addr || ret == NSAPI_ERROR_NO_CONNECTION) {
37
+ nsapi_error_t err = _udp_socket._stack ->gethostbyname (host, &addr);
30
38
if (err) {
31
39
return NSAPI_ERROR_DNS_FAILURE;
32
40
}
33
41
34
- _remote_address .set_port (port);
42
+ addr .set_port (port);
35
43
36
44
set_hostname (host);
37
- _udp_socket.connect (_remote_address ); // UDPSocket::connect() cannot fail
45
+ _udp_socket.connect (addr ); // UDPSocket::connect() cannot fail
38
46
}
39
47
40
- return connect (_remote_address );
48
+ return connect (addr );
41
49
}
42
50
43
51
DTLSSocket::~DTLSSocket ()
@@ -48,4 +56,4 @@ DTLSSocket::~DTLSSocket()
48
56
close ();
49
57
}
50
58
51
- #endif // MBEDTLS_SSL_CLI_C
59
+ #endif // MBEDTLS_SSL_CLI_C
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2018 ARM Limited
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
1
18
#ifndef DTLSSOCKET_H
2
19
#define DTLSSOCKET_H
3
20
@@ -46,7 +63,6 @@ class DTLSSocket : public DTLSSocketWrapper {
46
63
* @return 0 on success, negative error code on failure
47
64
*/
48
65
virtual nsapi_error_t open (NetworkStack *stack) {
49
- _stack = stack;
50
66
return _udp_socket.open (stack);
51
67
}
52
68
@@ -70,9 +86,7 @@ class DTLSSocket : public DTLSSocketWrapper {
70
86
71
87
private:
72
88
UDPSocket _udp_socket;
73
- NetworkStack *_stack;
74
- SocketAddress _remote_address;
75
89
};
76
90
77
91
#endif
78
- #endif
92
+ #endif
Original file line number Diff line number Diff line change @@ -52,4 +52,4 @@ void DTLSSocketWrapper::timer_event(void)
52
52
event ();
53
53
}
54
54
55
- #endif /* MBEDTLS_SSL_CLI_C */
55
+ #endif /* MBEDTLS_SSL_CLI_C */
Original file line number Diff line number Diff line change @@ -18,4 +18,4 @@ class DTLSSocketWrapper : public TLSSocketWrapper {
18
18
};
19
19
20
20
#endif
21
- #endif
21
+ #endif
Original file line number Diff line number Diff line change @@ -175,6 +175,8 @@ class InternetSocket : public Socket {
175
175
static const int WRITE_FLAG = 0x2u ;
176
176
static const int FINISHED_FLAG = 0x3u ;
177
177
178
+ friend class DTLSSocket ; // Allow DTLSSocket::connect() to do name resolution on the _stack
179
+
178
180
#endif // !defined(DOXYGEN_ONLY)
179
181
};
180
182
Original file line number Diff line number Diff line change @@ -47,4 +47,4 @@ TLSSocket::~TLSSocket()
47
47
close ();
48
48
}
49
49
50
- #endif // MBEDTLS_SSL_CLI_C
50
+ #endif // MBEDTLS_SSL_CLI_C
You can’t perform that action at this time.
0 commit comments