Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Implement abstract-socket based on ffi-rs without node-gyp

NotificationsYou must be signed in to change notification settings

zhangyuang/abstract-socket-rs

Repository files navigation

The ffi implemention ofabstract-socket based onffi-rs

Features

  • No need to use node-gyp 😊
  • Pure javascript project ✨
  • Pre build all platform output 🤯

Support platforms

  • linux-x64-gnu
  • linux-x64-musl
  • linux-arm64-gnu
  • linux-arm64-musl

How to use

The api interface is the same asabstract-socket.

Examples

Server:

// abstract echo serverconstabs=require('abstract-socket-rs');constserver=abs.createServer(function(c){//'connection' listenerconsole.log('client connected');c.on('end',function(){console.log('client disconnected');});c.write('hello\r\n');c.pipe(c);});server.listen('\0foo');

Client:

constabs=require('abstract-socket-rs');varclient=abs.connect('\0foo',function(){//'connect' listenerconsole.log('client connected');});client.on('data',function(data){console.log(data.toString());});process.stdin.setEncoding('utf8');process.stdin.on('readable',function(){constchunk=process.stdin.read();if(chunk!==null)client.write(chunk);});

API

abs.createServer(connectionListener)

Returns a newAbstractSocketServer object.listen can be called onit passing the name of the abstract socket to bind to and listen, it followsthe API used for normal Unix domain sockets. NOTE: you must prepend the path withthe NULL byte ('\0') to indicate it's an abstract socket.

Emits an error if thesocket(2) system call fails.

AbstractSocketServer.listen(name, [callback]

Binds the server to the specified abstract socket name.

Emits an error if thebind(2) system call fails, or the givennameis invalid.

This function is asynchronous. When the server has been bound, 'listening' eventwill be emitted. the last parameter callback will be added as an listener for the'listening' event.

abs.connect(name, connectListener)

Creates a connection to the givenpath in the abstract domain. NOTE: you mustprepend the path with the NULL byte ('\0') to indicate it's an abstractsocket.

Returns a new net.Socket object.

Emits an error if thesocket(2) orconnect(2) system calls fail,or the givenname is invalid.

About

Implement abstract-socket based on ffi-rs without node-gyp

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp