[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [Libevent-users] Handling the connection close
On Sun, Mar 20, 2016 at 12:11:19PM -0400, 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)?
https://github.com/libevent/libevent/commit/680742e1665b85487f10c0ef3df021e3b8e98634:
http: read server response even after server closed the connection
Otherwise if we will try to write more data than server can accept
(see `evhttp_set_max_body_size()` for libevent server) we will get `EPIPE` and
will not try to read server's response which must contain 400 error for now
(which is not strictly correct though, it must 413).
That said that if connection closed by the remote host but before it closes the
connection it wrote something to the client (like http error code), then client
can read this even if write fails.
Typical example is POST requests, in this case client can send a lot of data,
while server can have limits for user-data (like post_max_size in nginx), so
when server reaches this limit, some servers can send an error and close the
connection, so without EVHTTP_CON_READ_ON_WRITE_ERROR it will fail with
connection-reset while it can read "413 Request Entity Too Large" error and
show it to user.
But this works only on linux (maybe *nix), and doesn't work on win32.
Anyway this is related only to HTTP you don't need this I suppose.
Regards,
Azat.
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users in the body.