[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [Libevent-users] Handling the connection close



For example, I can recv these error info when the connection is closed:

EventCb] TRACE: Resource temporarily unavailable
EventCb] TRACE: SUCCESS
EventCb] TRACE: connection is refused

On 03/20/2016 12:11 PM, Michael wrote:


#define EVHTTP_CON_CLOSEDETECT 0x0004 /* detecting if persistent close */
/* set when we want to auto free the connection */
#define EVHTTP_CON_AUTOFREE    EVHTTP_CON_PUBLIC_FLAGS_END
+/* Installed when attempt to read HTTP error after write failed, see
+ * EVHTTP_CON_READ_ON_WRITE_ERROR */
+#define EVHTTP_CON_READING_ERROR   (EVHTTP_CON_AUTOFREE << 1)


I still don't know the relationship between the error code (returned by libevent) and the user defined error (EVHTTP_CON_READING_ERROR).

Normally, we can get the error code in event callback, right? and I suppose there are only two or three error codes, when a connection is closed. So should we record the status of our application? When we got the close, we check the status of the connection (application)?

On 03/20/2016 11:51 AM, Azat Khuzhin wrote:
On Sun, Mar 20, 2016 at 11:31:29AM -0400, Michael wrote:
This is an example in http.c

I wonder how can I get EVHTTP_CON_READING_ERROR?? Since when the connection is closed, I can only get an error code, and this code seems only telling
your send or recv has finished or not.

evhttp_connection_read_on_write_error(struct evhttp_connection *evcon,
     struct evhttp_request *req)
{
     struct evbuffer *buf;

     /** Second time, we can't read anything */
     if (evcon->flags & EVHTTP_CON_READING_ERROR) {
         evcon->flags &= ~EVHTTP_CON_READING_ERROR;
         evhttp_connection_fail_(evcon, EVREQ_HTTP_EOF);
         return;
     }

     req->kind = EVHTTP_RESPONSE;

     buf = bufferevent_get_output(evcon->bufev);
     evbuffer_unfreeze(buf, 1);
     evbuffer_drain(buf, evbuffer_get_length(buf));
     evbuffer_freeze(buf, 1);

     evhttp_start_read_(evcon);
     evcon->flags |= EVHTTP_CON_READING_ERROR;
}
Oh, this is kind of interesting:

Can you take a look at:
https://github.com/libevent/libevent/commit/2ff164abac40d827fd35e0b4436d22137c1cc0b4

(plus a referenced commit too).
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.

***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.

***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.