| 164 | } |
| 165 | |
| 166 | bool http_aclient::handle_connect(const ACL_ASTREAM_CTX *ctx) |
| 167 | { |
| 168 | const ACL_SOCKADDR *ns_addr = acl_astream_get_ns_addr(ctx); |
| 169 | if (ns_addr) { |
| 170 | memcpy(&ns_addr_, &ns_addr->ss, sizeof(ns_addr_)); |
| 171 | } |
| 172 | const ACL_SOCKADDR* serv_addr = acl_astream_get_serv_addr(ctx); |
| 173 | if (serv_addr) { |
| 174 | memcpy(&serv_addr_, &serv_addr->ss, sizeof(serv_addr_)); |
| 175 | } |
| 176 | |
| 177 | ACL_ASTREAM* astream = acl_astream_get_conn(ctx); |
| 178 | if (astream == NULL) { |
| 179 | int status = acl_astream_get_status(ctx); |
| 180 | switch (status) { |
| 181 | case ACL_ASTREAM_STATUS_NS_ERROR: |
| 182 | this->on_ns_failed(); |
| 183 | this->destroy(); |
| 184 | break; |
| 185 | case ACL_ASTREAM_STATUS_CONNECT_TIMEOUT: |
| 186 | this->on_connect_timeout(); |
| 187 | this->destroy(); |
| 188 | break; |
| 189 | default: |
| 190 | this->on_connect_failed(); |
| 191 | this->destroy(); |
| 192 | break; |
| 193 | } |
| 194 | return false; |
| 195 | } |
| 196 | |
| 197 | // ���ӳɹ������� C++ AIO ���Ӷ��� |
| 198 | conn_ = NEW aio_socket_stream(&handle_, astream, true); |
| 199 | |
| 200 | // ע�����ӹرջص��������� |
| 201 | conn_->add_close_callback(this); |
| 202 | |
| 203 | // ע�� IO ��ʱ�ص��������� |
| 204 | conn_->add_timeout_callback(this); |
| 205 | |
| 206 | if (!ssl_conf_ || !ssl_enable_) { |
| 207 | return this->on_connect(); |
| 208 | } |
| 209 | |
| 210 | // ��Ϊ������ SSL ͨ�ŷ�ʽ��������Ҫ���� SSL IO ���̣���ʼ SSL ���� |
| 211 | sslbase_io* ssl_io = ssl_conf_->create(true); |
| 212 | |
| 213 | const char* host; |
| 214 | if (sni_host_.empty()) { |
| 215 | host = header_->get_host(); |
| 216 | } else { |
| 217 | host = sni_host_.c_str(); |
| 218 | } |
| 219 | if (host && *host) { |
| 220 | ssl_io->set_sni_host(host, |
| 221 | sni_prefix_.empty() ? NULL : sni_prefix_.c_str(), |
| 222 | sni_suffix_.empty() ? NULL : sni_suffix_.c_str()); |
| 223 | } |
no test coverage detected