| 211 | #endif |
| 212 | |
| 213 | bool mbedtls_io::open(ACL_VSTREAM* s) |
| 214 | { |
| 215 | if (s == NULL) { |
| 216 | logger_error("s null"); |
| 217 | return false; |
| 218 | } |
| 219 | |
| 220 | #ifdef HAS_MBEDTLS |
| 221 | // ��ֹ�ظ����� open ���� |
| 222 | if (ssl_ != NULL) { |
| 223 | // �����ͬһ�������� true |
| 224 | if (this->stream_ == s) { |
| 225 | return true; |
| 226 | } else if (ACL_VSTREAM_SOCK(stream_) == ACL_VSTREAM_SOCK(s)) { |
| 227 | long long n = ++(*refers_); |
| 228 | logger_warn("used by multiple stream, refers=%lld", n); |
| 229 | return true; |
| 230 | } |
| 231 | |
| 232 | // ����ֹͬһ�� SSL IO �����ڲ�ͬ���������� |
| 233 | logger_error("open again, stream_ changed!"); |
| 234 | return false; |
| 235 | } |
| 236 | |
| 237 | char host[128]; |
| 238 | host[0] = 0; |
| 239 | |
| 240 | const char* peer = ACL_VSTREAM_PEER(s); |
| 241 | if (peer && *peer) { |
| 242 | safe_snprintf(host, sizeof(host), "%s", peer); |
| 243 | } else if (acl_getpeername(ACL_VSTREAM_SOCK(s), host, sizeof(host))) { |
| 244 | logger_error("can't acl_getpeername error=%s", last_serror()); |
| 245 | return false; |
| 246 | } |
| 247 | |
| 248 | char* ptr = strrchr(host, '|'); |
| 249 | if (ptr == NULL) { |
| 250 | ptr = strrchr(host, ':'); |
| 251 | } |
| 252 | if (ptr) { |
| 253 | *ptr = 0; |
| 254 | } |
| 255 | |
| 256 | this->stream_ = s; |
| 257 | ++(*refers_); |
| 258 | |
| 259 | ssl_ = acl_mycalloc(1, sizeof(mbedtls_ssl_context)); |
| 260 | |
| 261 | // ��ʼ�� SSL ���� |
| 262 | __ssl_init((mbedtls_ssl_context*) ssl_); |
| 263 | |
| 264 | if (!sni_host_.empty()) { |
| 265 | __ssl_set_hostname((mbedtls_ssl_context*) ssl_, sni_host_.c_str()); |
| 266 | } else if (host[0]) { |
| 267 | __ssl_set_hostname((mbedtls_ssl_context*) ssl_, host); |
| 268 | } |
| 269 | |
| 270 | // ����ȫ�ֲ���������֤�顢˽Կ�� |
nothing calls this directly
no test coverage detected