Just flip some codes.

This commit is contained in:
Xie Han
2023-05-04 20:50:49 +08:00
parent e32170e15b
commit 1601c8b352

View File

@@ -924,69 +924,6 @@ struct CommConnEntry *Communicator::accept_conn(CommServiceTarget *target,
return NULL;
}
void Communicator::handle_listen_result(struct poller_result *res)
{
CommService *service = (CommService *)res->data.context;
struct CommConnEntry *entry;
CommServiceTarget *target;
int timeout;
switch (res->state)
{
case PR_ST_SUCCESS:
target = (CommServiceTarget *)res->data.result;
entry = this->accept_conn(target, service);
if (entry)
{
if (service->ssl_ctx)
{
if (__create_ssl(service->ssl_ctx, entry) >= 0 &&
service->init_ssl(entry->ssl) >= 0)
{
res->data.operation = PD_OP_SSL_ACCEPT;
timeout = service->ssl_accept_timeout;
}
}
else
{
res->data.operation = PD_OP_READ;
res->data.create_message = Communicator::create_request;
res->data.message = NULL;
timeout = target->response_timeout;
}
if (res->data.operation != PD_OP_LISTEN)
{
res->data.fd = entry->sockfd;
res->data.ssl = entry->ssl;
res->data.context = entry;
if (mpoller_add(&res->data, timeout, this->mpoller) >= 0)
{
if (this->stop_flag)
mpoller_del(res->data.fd, this->mpoller);
break;
}
}
this->release_conn(entry);
}
else
close(target->sockfd);
target->decref();
break;
case PR_ST_DELETED:
this->shutdown_service(service);
break;
case PR_ST_ERROR:
case PR_ST_STOPPED:
service->handle_stop(res->error);
break;
}
}
void Communicator::handle_connect_result(struct poller_result *res)
{
struct CommConnEntry *entry = (struct CommConnEntry *)res->data.context;
@@ -1061,6 +998,69 @@ void Communicator::handle_connect_result(struct poller_result *res)
}
}
void Communicator::handle_listen_result(struct poller_result *res)
{
CommService *service = (CommService *)res->data.context;
struct CommConnEntry *entry;
CommServiceTarget *target;
int timeout;
switch (res->state)
{
case PR_ST_SUCCESS:
target = (CommServiceTarget *)res->data.result;
entry = this->accept_conn(target, service);
if (entry)
{
if (service->ssl_ctx)
{
if (__create_ssl(service->ssl_ctx, entry) >= 0 &&
service->init_ssl(entry->ssl) >= 0)
{
res->data.operation = PD_OP_SSL_ACCEPT;
timeout = service->ssl_accept_timeout;
}
}
else
{
res->data.operation = PD_OP_READ;
res->data.create_message = Communicator::create_request;
res->data.message = NULL;
timeout = target->response_timeout;
}
if (res->data.operation != PD_OP_LISTEN)
{
res->data.fd = entry->sockfd;
res->data.ssl = entry->ssl;
res->data.context = entry;
if (mpoller_add(&res->data, timeout, this->mpoller) >= 0)
{
if (this->stop_flag)
mpoller_del(res->data.fd, this->mpoller);
break;
}
}
this->release_conn(entry);
}
else
close(target->sockfd);
target->decref();
break;
case PR_ST_DELETED:
this->shutdown_service(service);
break;
case PR_ST_ERROR:
case PR_ST_STOPPED:
service->handle_stop(res->error);
break;
}
}
void Communicator::handle_ssl_accept_result(struct poller_result *res)
{
struct CommConnEntry *entry = (struct CommConnEntry *)res->data.context;
@@ -1155,6 +1155,9 @@ void Communicator::handler_thread_routine(void *context)
switch (res->data.operation)
{
case PD_OP_TIMER:
comm->handle_sleep_result(res);
break;
case PD_OP_READ:
comm->handle_read_result(res);
break;
@@ -1175,9 +1178,6 @@ void Communicator::handler_thread_routine(void *context)
case PD_OP_NOTIFY:
comm->handle_aio_result(res);
break;
case PD_OP_TIMER:
comm->handle_sleep_result(res);
break;
}
free(res);