peakzhang 发表于 2008-7-13 22:45:54

ACE_Asynch_Connector应用的问题

ACE的DEMO程序有些问题:
如下:
int AIO_CLD_Connector::validate_connection
(const ACE_Asynch_Connect::Result& result,
   const ACE_INET_Addr &remote, const ACE_INET_Addr&) {
remote_addr_ = remote;
if (!result.success ()) {
    ACE_Time_Value delay (retry_delay_);
    retry_delay_ *= 2;
    if (retry_delay_ > MAX_RETRY_DELAY)
      retry_delay_ = MAX_RETRY_DELAY;
    proactor ()->schedule_timer (*this, 0, delay);
    return -1;
}
retry_delay_ = INITIAL_RETRY_DELAY;
if (ssl_ctx_ == 0) {
    OpenSSL_add_ssl_algorithms ();
    ssl_ctx_ = SSL_CTX_new (SSLv3_client_method ());
    if (ssl_ctx_ == 0) return -1;
    if (SSL_CTX_use_certificate_file (ssl_ctx_,
                                    CLD_CERTIFICATE_FILENAME,
                                    SSL_FILETYPE_PEM) <= 0
       || SSL_CTX_use_PrivateKey_file (ssl_ctx_,
                                       CLD_KEY_FILENAME,
                                       SSL_FILETYPE_PEM) <= 0
       || !SSL_CTX_check_private_key (ssl_ctx_)) {
      SSL_CTX_free (ssl_ctx_);
      ssl_ctx_ = 0;
      return -1;
    }
    ssl_ = SSL_new (ssl_ctx_);
    if (ssl_ == 0) {
      SSL_CTX_free (ssl_ctx_); ssl_ctx_ = 0;
      return -1;
    }
}
SSL_clear (ssl_);
#if defined (ACE_WIN32)
// ACE_WIN32 is the only platform where ACE_HANDLE is not an int.
// See ace/config-lite.h for the typedefs.
SSL_set_fd (ssl_, reinterpret_cast<int> (result.connect_handle ()));
#else
SSL_set_fd (ssl_, result.connect_handle ());
#endif /* ACE_WIN32 */
SSL_set_verify (ssl_, SSL_VERIFY_PEER, 0);
if (SSL_connect (ssl_) == -1
      || SSL_shutdown (ssl_) == -1) return -1;
return 0;
}
void AIO_CLD_Connector::handle_time_out
(const ACE_Time_Value&, const void *) {
connect (remote_addr_);
}

这段程序的本意,是在socket建立连接成功后,进行SSL的验证,如果连接失败,调用定时器重新连接。
但问题在红色标注的部分,如果第一次连接失败了,则这个地址是不确定的(文档说明),实际我测试,是0.0.0.0:0。
这样以来,其实是陷入了死循环,永无止境了。

peakzhang 发表于 2008-7-13 22:46:27

按照文档来看


resultResult of the connection acceptance. Use result.success() to determine
success or failure of the connection attempt.

remotePeer's address. If the connection failed, this object is undefined.

localLocal address connection was completed from. If the connection failed, this
object is undefined.

似乎没错,这个例子有问题
页: [1]
查看完整版本: ACE_Asynch_Connector应用的问题