diff --git a/src/factory/WFTask.inl b/src/factory/WFTask.inl index f06fdfea2a..d62a5ba439 100644 --- a/src/factory/WFTask.inl +++ b/src/factory/WFTask.inl @@ -47,7 +47,7 @@ class WFClientTask : public WFNetworkTask protected: virtual CommMessageOut *message_out() { - /* By using prepare function, users can modify the request after + /* By setting 'prepare' function, users can modify the request after * the connection is established. */ if (this->prepare) this->prepare(this); @@ -108,7 +108,7 @@ class WFServerTask : public WFNetworkTask protected: virtual CommMessageOut *message_out() { - /* By using prepare function, users can modify the response before + /* By setting 'prepare' function, users can modify the response before * replying to the client. */ if (this->prepare) this->prepare(this); @@ -120,16 +120,12 @@ protected: virtual void handle(int state, int error); protected: - /* CommSession::get_connection() is supposed to be called only in the - * implementations of it's virtual functions. As a server task, to call - * this function after process() and before callback() is very dangerous - * and should be blocked. */ virtual WFConnection *get_connection() const { - if (this->processor.task) + if (this->processor.task == this) return (WFConnection *)this->CommSession::get_connection(); - errno = EPERM; + errno = this->processor.task ? ENOTCONN : EPERM; return NULL; } @@ -138,18 +134,17 @@ protected: { if (this->state == WFT_STATE_TOREPLY) { - /* Enable get_connection() again if the reply() call is success. */ this->processor.task = this; if (this->scheduler->reply(this) >= 0) return; this->state = WFT_STATE_SYS_ERROR; this->error = errno; - this->processor.task = NULL; } else this->scheduler->shutdown(this); + this->processor.task = (WFServerTask *)-1; this->subtask_done(); } @@ -166,7 +161,7 @@ protected: if (this->callback) this->callback(this); - /* Defer deleting the task. */ + this->processor.task = NULL; return series->pop(); } @@ -174,7 +169,7 @@ protected: class Processor : public SubTask { public: - Processor(WFServerTask *task, + Processor(WFServerTask *task, std::function *)>& proc) : process(proc) { @@ -184,7 +179,7 @@ protected: virtual void dispatch() { this->process(this->task); - this->task = NULL; /* As a flag. get_conneciton() disabled. */ + this->task = NULL; /* As a flag, disable getting connection. */ this->subtask_done(); } @@ -194,13 +189,13 @@ protected: } std::function *)>& process; - WFServerTask *task; + WFServerTask *task; } processor; class Series : public SeriesWork { public: - Series(WFServerTask *task) : + Series(WFServerTask *task) : SeriesWork(&task->processor, nullptr) { this->set_last_task(task); @@ -212,7 +207,7 @@ protected: delete this->task; } - WFServerTask *task; + WFServerTask *task; }; public: