*/
gboolean rspamd_session_pending (struct rspamd_async_session *session);
+/**
+ * Returns number of events pending
+ * @param session
+ * @return
+ */
+guint rspamd_session_events_pending (struct rspamd_async_session *session);
+
/**
* Start watching for events in the session, so the specified watcher will be added
* to all subsequent events until `rspamd_session_watch_stop` is called
else {
rspamd_lua_call_pre_filters (task);
/* We want fin_task after pre filters are processed */
- task->state = WAIT_PRE_FILTER;
+ if (rspamd_session_events_pending (task->s) != 0) {
+ task->state = WAIT_PRE_FILTER;
+ }
}
- rspamd_session_pending (task->s);
-
return TRUE;
}
ctx = task->worker->ctx;
+ task->state = WRITE_REPLY;
+
if (!rspamd_protocol_handle_request (task, msg)) {
- task->state = WRITE_REPLY;
return 0;
}
if (task->cmd == CMD_PING) {
- task->state = WRITE_REPLY;
return 0;
}
msg_err ("got zero length body, cannot continue");
task->last_error = "message's body is empty";
task->error_code = RSPAMD_LENGTH_ERROR;
- task->state = WRITE_REPLY;
+
return 0;
}
-
- if (!rspamd_task_process (task, msg, chunk, len, TRUE)) {
- task->state = WRITE_REPLY;
- }
+ rspamd_task_process (task, msg, chunk, len, TRUE);
return 0;
}
{
struct rspamd_task *task = (struct rspamd_task *) conn->ud;
- if (task->state == CLOSING_CONNECTION) {
+ if (task->state == CLOSING_CONNECTION || task->state == WRITING_REPLY) {
/* We are done here */
msg_debug ("normally closing connection from: %s",
rspamd_inet_address_to_string (task->client_addr));
*/
msg_debug ("want write message to the wire: %s",
rspamd_inet_address_to_string (task->client_addr));
- rspamd_protocol_write_reply (task);
- /* Forcefully set the state */
- task->state = CLOSING_CONNECTION;
- }
- else if (task->state == WRITING_REPLY) {
- msg_debug ("still writing reply to: %s",
- rspamd_inet_address_to_string (task->client_addr));
- task->state = CLOSING_CONNECTION;
- }
- else {
/*
* If all filters have finished their tasks, this function will trigger
* writing a reply.