FAQ
Hello,

I have a C shared library. I am writing a node module for this library. I
wrote a process function which can be accessed from JS and it calls my
shared library function. In JS, it looks like,

myLibrary.process(args, function(output) {
});

I am wondering, is this a non-blocking call or blocking one? Since I am not
doing anything special to make it non-blocking, I assume this will be a
blocking call. Or is Node doing something to make it non-blocking?

If the above code is blocking, how do I make a non-blocking wrapper for
this shared library? Should I use work queues from libuv?

Any help would be great!

Thanks
Navaneeth

--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Search Discussions

  • Shripad K at Aug 20, 2012 at 12:08 pm
    Hello Navaneeth,

    One cannot ascertain from the JS code whether the call is going to block
    the event loop or not. In libev, you would register a ev_io watcher and
    listen for EV_READ, EV_WRITE (or both) events (ev_io_init() +
    ev_io_start()) whenever the FD becomes readable/writable. I think the
    equivalent of it is uv_poll_init() + uv_poll_start() in libuv.

    Here is an example of the implementation in zeromq.node:
    https://github.com/JustinTulloss/zeromq.node/blob/master/binding.cc#L312

    Can you shed more light on what C shared library are you trying to bridge??

    Shripad K.
    On Sun, Aug 19, 2012 at 11:58 AM, Navaneeth KN wrote:

    Hello,

    I have a C shared library. I am writing a node module for this library. I
    wrote a process function which can be accessed from JS and it calls my
    shared library function. In JS, it looks like,

    myLibrary.process(args, function(output) {
    });

    I am wondering, is this a non-blocking call or blocking one? Since I am
    not doing anything special to make it non-blocking, I assume this will be a
    blocking call. Or is Node doing something to make it non-blocking?

    If the above code is blocking, how do I make a non-blocking wrapper for
    this shared library? Should I use work queues from libuv?

    Any help would be great!

    Thanks
    Navaneeth

    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Navaneeth KN at Aug 20, 2012 at 1:53 pm
    Hello,

    Thanks for responding.
    On Monday, 20 August 2012 17:37:55 UTC+5:30, Shripad K wrote:

    Hello Navaneeth,

    One cannot ascertain from the JS code whether the call is going to block
    the event loop or not. In libev, you would register a ev_io watcher and
    listen for EV_READ, EV_WRITE (or both) events (ev_io_init() +
    ev_io_start()) whenever the FD becomes readable/writable. I think the
    equivalent of it is uv_poll_init() + uv_poll_start() in libuv.
    I was not talking about will it block the event loop or not. Because I am
    not using event loop at all explicitly. All I am doing is directly calling
    the C function in my module. I was wondering should I implement using Work
    queue (http://nikhilm.github.com/uvbook/threads.html#libuv-work-queue).

    The C Library which I am trying to wrap is available here -
    https://github.com/navaneeth/libvarnam
    Node code is available here -
    https://github.com/jijeshmohan/varnam-addon/blob/master/varnam.cc

    Here is an example of the implementation in zeromq.node:
    https://github.com/JustinTulloss/zeromq.node/blob/master/binding.cc#L312
    Thank you. I will take a look at it.

    Thanks
    Navaneeth

    >

    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Shripad K at Aug 20, 2012 at 3:16 pm

    On Mon, Aug 20, 2012 at 7:23 PM, Navaneeth KN wrote:

    Hello,

    Thanks for responding.
    On Monday, 20 August 2012 17:37:55 UTC+5:30, Shripad K wrote:

    Hello Navaneeth,

    One cannot ascertain from the JS code whether the call is going to block
    the event loop or not. In libev, you would register a ev_io watcher and
    listen for EV_READ, EV_WRITE (or both) events (ev_io_init() +
    ev_io_start()) whenever the FD becomes readable/writable. I think the
    equivalent of it is uv_poll_init() + uv_poll_start() in libuv.
    I was not talking about will it block the event loop or not. Because I am
    not using event loop at all explicitly. All I am doing is directly calling
    the C function in my module. I was wondering should I implement using Work
    queue (http://nikhilm.github.com/uvbook/threads.html#libuv-work-queue).
    When you say whether it is "blocking call" it can only mean that the event
    loop is blocked, resulting in the process being blocked. The corresponding
    C++/C code which the JS function calls might still block the event loop.

    The C Library which I am trying to wrap is available here -
    https://github.com/navaneeth/libvarnam
    Node code is available here -
    https://github.com/jijeshmohan/varnam-addon/blob/master/varnam.cc
    I can see that varnam_init might be a blocking call because it calls
    sqlite3_open which I assume is blocking call as well? If you can get hold
    of the underlying FD then you can use uv_poll watcher. If you can't get a
    reference to the underlying descriptor then you can use a work queue
    (uv_queue_work) which will execute the blocking call in another thread.

    Here is an example of the implementation in zeromq.node: https://github.**
    com/JustinTulloss/zeromq.node/**blob/master/binding.cc#L312<https://github.com/JustinTulloss/zeromq.node/blob/master/binding.cc#L312>
    Thank you. I will take a look at it.

    Thanks
    Navaneeth
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Nikhil Marathe at Aug 20, 2012 at 3:55 pm

    On Mon, Aug 20, 2012 at 7:23 PM, Navaneeth KN wrote:
    I was not talking about will it block the event loop or not. Because I am
    not using event loop at all explicitly. All I am doing is directly calling
    the C function in my module. I was wondering should I implement using Work
    queue (http://nikhilm.github.com/uvbook/threads.html#libuv-work-queue).
    Hi Navaneeth,

    If your underlying functions belonging to libvarnam are blocking, then
    YES, you'll have
    to use uv_queue_work() if you want the node addon itself to not block
    the event loop.

    Nikhil

    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupnodejs @
categoriesnodejs
postedAug 20, '12 at 8:57a
activeAug 20, '12 at 3:55p
posts5
users3
websitenodejs.org
irc#node.js

People

Translate

site design / logo © 2022 Grokbase