diff --git a/src/kernel/CommScheduler.h b/src/kernel/CommScheduler.h index f2c8f484..fa707eb4 100644 --- a/src/kernel/CommScheduler.h +++ b/src/kernel/CommScheduler.h @@ -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); diff --git a/src/kernel/Communicator.cc b/src/kernel/Communicator.cc index 86aa165d..97fdd5ad 100644 --- a/src/kernel/Communicator.cc +++ b/src/kernel/Communicator.cc @@ -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; diff --git a/src/kernel/Communicator.h b/src/kernel/Communicator.h index a405c363..01903675 100644 --- a/src/kernel/Communicator.h +++ b/src/kernel/Communicator.h @@ -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);