mirror of
https://github.com/sogou/workflow.git
synced 2026-10-26 17:59:30 +08:00
Add Communicator::shutdown() for server task to close connection.
This commit is contained in:
@@ -144,6 +144,11 @@ public:
|
||||
return this->comm.reply(session);
|
||||
}
|
||||
|
||||
int shutdown(CommSession *session)
|
||||
{
|
||||
return this->comm.shutdown(session);
|
||||
}
|
||||
|
||||
int push(const void *buf, size_t size, CommSession *session)
|
||||
{
|
||||
return this->comm.push(buf, size, session);
|
||||
|
||||
@@ -1799,6 +1799,35 @@ int Communicator::push(const void *buf, size_t size, CommSession *session)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int Communicator::shutdown(CommSession *session)
|
||||
{
|
||||
CommTarget *target = session->target;
|
||||
struct CommConnEntry *entry;
|
||||
int ret;
|
||||
|
||||
if (session->passive != 1)
|
||||
{
|
||||
errno = session->passive ? ENOENT : EPERM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
session->passive = 2;
|
||||
pthread_mutex_lock(&target->mutex);
|
||||
if (!list_empty(&target->idle_list))
|
||||
{
|
||||
entry = list_entry(target->idle_list.next, struct CommConnEntry, list);
|
||||
ret = mpoller_del(entry->sockfd, entry->mpoller);
|
||||
}
|
||||
else
|
||||
{
|
||||
errno = ENOENT;
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&target->mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int Communicator::sleep(SleepSession *session)
|
||||
{
|
||||
struct timespec value;
|
||||
|
||||
@@ -268,6 +268,8 @@ public:
|
||||
|
||||
int push(const void *buf, size_t size, CommSession *session);
|
||||
|
||||
int shutdown(CommSession *session);
|
||||
|
||||
int bind(CommService *service);
|
||||
void unbind(CommService *service);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user