npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tarantool-transport

v0.2.7

Published

Low-level Tarantool driver for node.js

Downloads

5

Readme

#Transport - low-level Tarantool driver

Transport incapsulates socket, manages callbacks, composes request headers, parses response headers, and composes response from several data packets.

Use Connector as a high-level driver or create your own.

NPM

npm install tarantool-transport

API and usage

Call Transport.connect port, host, callback or new Transport socket to instantiate transport. First way is common and preferrable while second allows to prepare socket, mock it or hack it.

Call transport.request type, body, callback to send request.

  • type must be Number, any valid request type: 0x0D, 0x11, 0x13, 0x15, 0x16 or 0xFF00.
  • body must be Buffer (preferrable) or String (empty string is usable, see example below).
  • callback will receive response body as Buffer, maybe empty, never null or undefined.

All arguments are obligatory.

Example

Transport = require 'tarantool-transport'

PING = 0xFF00 # ping request type

transport = Transport.connect port, host, -> # on connection
    transport.request PING, '', -> # on response
        console.log 'got ping response'
    
    console.log 'sent ping request'

# the other way, if you want to prepare socket somehow
# net = require 'net'
# socket = net.connect port, host, ->
#     # on connection
# transport = new Transport socket

Hacking

Implementation notes

Before reading source please note that:

  • In Tarantool, request and response headers are sequences of unsigned little-endian 32-bit integers.
  • Tarantool allows to set request_id. Server will just white this value into response, it won't check or compare it with anything. In transport we call this field callback_id — we pass callbacks and one response calls means one callback here.

Interaction with Socket

Constructed transport sets up socket in this way:

  • socket.unref() to let node.js exit if we're not awaiting responses
  • socket.setNoDelay() to reduce latency (added in 0.2.3)
  • socket.on('data', cb) to parse and process responses

transport does socket.ref() on request and socket.unref() on last awaited response. Thus, socket prevents node.js from shutting down until it receives all responses.

This is the most common use case, but you can play with socket in any way, at your own risk.

Inner variables

For those who want to hack Transport — list of inner variables:

  • socketnet socket or Object you passed to constructor
  • remainder — Buffer, will prepend next data chunk in order to compose responses from several data packets
  • callbacks — Hash (Object), keys are numeric response ids, values are passed callbacks
  • nextCallbackId — non-negative Number, incremented on request, when reaches 4294967296 overflows to 0, you can use it to describe request frequency
  • responsesAwaiting — non-negative Number, incremented on request, decremented on response, stored to know when ref() and unref() the socket

Bugs and issues

Bug reports and pull requests are welcome.

LICENSE

Tarantool Transport for node.js is published under MIT license.