Skip to content

Commit ea2fc3b

Browse files
committed
Disable getting connection after server task callback.
1 parent 9c2df32 commit ea2fc3b

1 file changed

Lines changed: 11 additions & 16 deletions

File tree

src/factory/WFTask.inl

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class WFClientTask : public WFNetworkTask<REQ, RESP>
4747
protected:
4848
virtual CommMessageOut *message_out()
4949
{
50-
/* By using prepare function, users can modify the request after
50+
/* By setting 'prepare' function, users can modify the request after
5151
* the connection is established. */
5252
if (this->prepare)
5353
this->prepare(this);
@@ -108,7 +108,7 @@ class WFServerTask : public WFNetworkTask<REQ, RESP>
108108
protected:
109109
virtual CommMessageOut *message_out()
110110
{
111-
/* By using prepare function, users can modify the response before
111+
/* By setting 'prepare' function, users can modify the response before
112112
* replying to the client. */
113113
if (this->prepare)
114114
this->prepare(this);
@@ -120,16 +120,12 @@ protected:
120120
virtual void handle(int state, int error);
121121

122122
protected:
123-
/* CommSession::get_connection() is supposed to be called only in the
124-
* implementations of it's virtual functions. As a server task, to call
125-
* this function after process() and before callback() is very dangerous
126-
* and should be blocked. */
127123
virtual WFConnection *get_connection() const
128124
{
129-
if (this->processor.task)
125+
if (this->processor.task == this)
130126
return (WFConnection *)this->CommSession::get_connection();
131127

132-
errno = EPERM;
128+
errno = this->processor.task ? ENOTCONN : EPERM;
133129
return NULL;
134130
}
135131

@@ -138,16 +134,15 @@ protected:
138134
{
139135
if (this->state == WFT_STATE_TOREPLY)
140136
{
141-
/* Enable get_connection() again if the reply() call is success. */
142137
this->processor.task = this;
143138
if (this->scheduler->reply(this) >= 0)
144139
return;
145140

146141
this->state = WFT_STATE_SYS_ERROR;
147142
this->error = errno;
148-
this->processor.task = NULL;
149143
}
150144

145+
this->processor.task = (WFServerTask *)-1;
151146
this->subtask_done();
152147
}
153148

@@ -164,15 +159,15 @@ protected:
164159
if (this->callback)
165160
this->callback(this);
166161

167-
/* Defer deleting the task. */
162+
this->processor.task = NULL;
168163
return series->pop();
169164
}
170165

171166
protected:
172167
class Processor : public SubTask
173168
{
174169
public:
175-
Processor(WFServerTask<REQ, RESP> *task,
170+
Processor(WFServerTask *task,
176171
std::function<void (WFNetworkTask<REQ, RESP> *)>& proc) :
177172
process(proc)
178173
{
@@ -182,7 +177,7 @@ protected:
182177
virtual void dispatch()
183178
{
184179
this->process(this->task);
185-
this->task = NULL; /* As a flag. get_conneciton() disabled. */
180+
this->task = NULL; /* As a flag, disable getting connection. */
186181
this->subtask_done();
187182
}
188183

@@ -192,13 +187,13 @@ protected:
192187
}
193188

194189
std::function<void (WFNetworkTask<REQ, RESP> *)>& process;
195-
WFServerTask<REQ, RESP> *task;
190+
WFServerTask *task;
196191
} processor;
197192

198193
class Series : public SeriesWork
199194
{
200195
public:
201-
Series(WFServerTask<REQ, RESP> *task) :
196+
Series(WFServerTask *task) :
202197
SeriesWork(&task->processor, nullptr)
203198
{
204199
this->set_last_task(task);
@@ -210,7 +205,7 @@ protected:
210205
delete this->task;
211206
}
212207

213-
WFServerTask<REQ, RESP> *task;
208+
WFServerTask *task;
214209
};
215210

216211
public:

0 commit comments

Comments
 (0)