Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
on_error callback
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Dhruv Matani  
View profile  
 More options Nov 8 2012, 7:44 pm
From: Dhruv Matani <dhruvb...@gmail.com>
Date: Thu, 8 Nov 2012 16:44:40 -0800 (PST)
Local: Thurs, Nov 8 2012 7:44 pm
Subject: on_error callback

Hello,

I've just started using libuv, and was wondering if there exists an
on_error() or global on_close() callback which is fired when a socket
closes or is disconnected, etc...
The only thing I could figure is to call uv_close() and unless that is
called, it seems that the socket is NOT reclaimed/close(2)ed by the system,
and counts toward the open FD count.
I'm looking for something similar to the exfds FDSET when used with
select(2).

Regards,
-Dhruv.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ben Noordhuis  
View profile  
 More options Nov 8 2012, 8:02 pm
From: Ben Noordhuis <i...@bnoordhuis.nl>
Date: Fri, 9 Nov 2012 02:02:04 +0100
Local: Thurs, Nov 8 2012 8:02 pm
Subject: Re: [libuv] on_error callback

On Fri, Nov 9, 2012 at 1:44 AM, Dhruv Matani <dhruvb...@gmail.com> wrote:
> Hello,

> I've just started using libuv, and was wondering if there exists an
> on_error() or global on_close() callback which is fired when a socket closes
> or is disconnected, etc...
> The only thing I could figure is to call uv_close() and unless that is
> called, it seems that the socket is NOT reclaimed/close(2)ed by the system,
> and counts toward the open FD count.
> I'm looking for something similar to the exfds FDSET when used with
> select(2).

> Regards,
> -Dhruv.

There is no global close or error hook in libuv.  It's the
responsibility of the libuv user to always uv_close() a handle.

With TCP sockets, you check the status argument in your read_cb and
write_cb.  If there is an error, you close the handle.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dhruv Matani  
View profile  
 More options Nov 8 2012, 10:41 pm
From: Dhruv Matani <dhruvb...@gmail.com>
Date: Thu, 8 Nov 2012 19:41:39 -0800 (PST)
Local: Thurs, Nov 8 2012 10:41 pm
Subject: Re: [libuv] on_error callback

So, in case that the user systematically closes the connection after
sending in a valid stream of bytes (all of which have been read), I have
seen the connection go into a state of being "there" (I mean in memory),
with the FD open, but nothing happening - i.e. no more read events are
being fired on it. How do you think this situation should be handled? Since
the process quickly runs out of open FDs.

The client process in question is a node.js script and I am making http
requests one after another, so I am guessing that node will close the
connection if there are no pending http requests in the queue.

Here is the link to the code (just to make sure that I have understood how
the http client behaves).
https://github.com/duckduckgo/cpp-libface/blob/libuv-httpserver/tests...

This is the read callback, which is never called when the socket
terminates:
https://github.com/duckduckgo/cpp-libface/blob/libuv-httpserver/src/h...

And I am having to maintain an LRU list of open sockets here:
https://github.com/duckduckgo/cpp-libface/blob/libuv-httpserver/src/h...

I am pretty sure that this is the wrong way to go about this problem, so am
looking to see if you have a better way I should be doing this.

Regards,
-Dhruv.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ben Noordhuis  
View profile  
 More options Nov 8 2012, 11:04 pm
From: Ben Noordhuis <i...@bnoordhuis.nl>
Date: Fri, 9 Nov 2012 05:04:23 +0100
Local: Thurs, Nov 8 2012 11:04 pm
Subject: Re: [libuv] on_error callback

On Fri, Nov 9, 2012 at 4:41 AM, Dhruv Matani <dhruvb...@gmail.com> wrote:
> So, in case that the user systematically closes the connection after sending
> in a valid stream of bytes (all of which have been read), I have seen the
> connection go into a state of being "there" (I mean in memory), with the FD
> open, but nothing happening - i.e. no more read events are being fired on
> it. How do you think this situation should be handled? Since the process
> quickly runs out of open FDs.

> The client process in question is a node.js script and I am making http
> requests one after another, so I am guessing that node will close the
> connection if there are no pending http requests in the queue.

Yes, that's correct.

> Here is the link to the code (just to make sure that I have understood how
> the http client behaves).
> https://github.com/duckduckgo/cpp-libface/blob/libuv-httpserver/tests...

> This is the read callback, which is never called when the socket terminates:
> https://github.com/duckduckgo/cpp-libface/blob/libuv-httpserver/src/h...

Remember the "always close" rule.  I'll reproduce your code here for
posterity's sake:

    } else if (nread < 0) {
        uv_err_t err = uv_last_error(uv_loop);
        if (err.code != UV_EOF) {
            UVERR(err, "read");
            close_connection(client);
        }
    }

You close the connection when it's not an EOF.  That's a bug, you
should *always* close it when nread == -1.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dhruv Matani  
View profile  
 More options Nov 8 2012, 11:22 pm
From: Dhruv Matani <dhruvb...@gmail.com>
Date: Thu, 8 Nov 2012 20:22:26 -0800 (PST)
Local: Thurs, Nov 8 2012 11:22 pm
Subject: Re: [libuv] on_error callback

Ah! Thanks for the quick clarification Ben!

I had picked up the code from Ryan's demo http server, hoping it would be
bullet proof :-p


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »