[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [Libevent-users] Socket stuck in close_wait state
- To: libevent-users@xxxxxxxxxxxxx
- Subject: Re: [Libevent-users] Socket stuck in close_wait state
- From: Azat Khuzhin <a3at.mail@xxxxxxxxx>
- Date: Mon, 18 Jun 2018 04:01:50 +0300
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: libevent-users-outgoing@xxxxxxxx
- Delivered-to: libevent-users@xxxxxxxx
- Delivery-date: Sun, 17 Jun 2018 21:01:57 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=+16oWjZ0+6k6j6TlttUMBh9hKz2CwlZeEukEKa/tyRY=; b=IfpEh7KXpXpfijkt739hC27+CHo0P4R6j6nYVEXO3drSixMC/79bAWwrqY6avepZrC FjwDY61Ua5cLdu1VBWW2fUKaAW3yBj3ZJKFQTJR3X+9O86EybGgc3uEKFi8+D5CjW8qz D69PUv9/LfInNfv6xIcx6k46FJMYnv/7JxNjj6SSNF2KFovSisneZF/0wc7tncDH9YDt ktnl92/dUzbOHIA1cV6dXg/gJ1FYSgCpWfFt9hB80razEiRSGKOBjhArUe5FlihTu91Y UVNkJ09RaGHBS4Pcwi1zYsIVs1UPXi3mQPQrF++LjBx1WoXCyNgUVqvJ8j1X9VFngBlI AeVQ==
- In-reply-to: <trinity-17e6d2b5-4cc7-42f8-8065-33fc4bcb6395-1528423392665@3c-app-mailcom-lxa10>
- References: <trinity-17e6d2b5-4cc7-42f8-8065-33fc4bcb6395-1528423392665@3c-app-mailcom-lxa10>
- Reply-to: libevent-users@xxxxxxxxxxxxx
- Sender: owner-libevent-users@xxxxxxxxxxxxx
- User-agent: NeoMutt/20180512
> Since bufferevent_free() is meant to close the socket I expected the socket to be closed on both sides, but my logic is obviously wrong.
bufferevent_free() and any close() cannot close the fd on the another
side, the code should do this, and this is what you bufferevent_free()
must do.
> void Close( bufferevent *bev, void *arg )
> {
> bufferevent_free( bev );
One may think that bufferevent_free() will call close() directly, but
this is not true for libevent 2.2 since bufferevents uses finalizers too
free the resources and this is the tricky part.
Finalizers will be runned from the loop *or* when freeing event_base.
> event_base_loopbreak( bufferevent_get_base( bev ) );
event_base_loopbreak() is unwanted here, you should be polite and exit
from the loop once it does not have any events.
> void Send()
> {
...
> event_base_dispatch( tcpbase );
*And this is the main problem of this snippet is missing event_base_free() here.*
(not only finalizers will not be runned but also internal event_base fds
will not be closed too, you can use strace/gdb/lsof and other tools to
dig into this or their analogs if you are not in linux).
P.S. and I hope you know about all other problems that this code have
(i.e. the reason why Send() is triggered multiple times after sending
one character with new line to stdin)
Regards,
Azat.
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users in the body.