Skip to content

Commit bf8a025

Browse files
committed
chore: update some tests and add package.json fields
1 parent 29e59e4 commit bf8a025

File tree

8 files changed

+13
-18
lines changed

8 files changed

+13
-18
lines changed

__test__/dgram.spec.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
// TODO add tests for worker_threads
12
import * as path from 'path';
23
import * as fs from 'fs';
34
import * as os from 'os';
45
import { DgramSocket } from '../js/index';
5-
import { kTmp, silently, createDefer } from './util';
6+
import { kTmp, silently, createDefer, kServerPath } from './util';
67

7-
const kServerPath = path.resolve(kTmp, './server.sock');
88
const kClientPath = path.resolve(kTmp, './client.sock');
99
const kInvalidPath = path.resolve(kTmp, './A_PATH_THAT_DOESNT_EXIST');
1010

@@ -20,10 +20,7 @@ describe('DgramSocket', () => {
2020
});
2121

2222
it('should work', async () => {
23-
let resolve: any;
24-
const readCb = new Promise((r) => {
25-
resolve = r;
26-
});
23+
const { p: readCb, resolve } = createDefer();
2724
const msg = 'hello';
2825
const mockFn = jest.fn((buf, filepath) => {
2926
try {

__test__/seqpacket.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// TODO add tests for worker_threads
12
import * as path from 'path';
23
import * as fs from 'fs';
34
import { SeqpacketSocket, SeqpacketServer } from '../js/seqpacket';

__test__/util.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ export const kIsDarwin = os.platform() === 'darwin'
55

66
export const kTmp = path.resolve(__dirname, './.tmp')
77

8+
export const kServerPath = path.resolve(kTmp, './server.sock');
9+
810
export function wait(t: number) {
911
return new Promise<void>((resolve, reject) => {
1012
setTimeout(() => {

js/addon.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,5 @@ export function dgramSetRecvBufferSize(ee: object, size: number): void
2525
export function dgramGetSendBufferSize(ee: object): number
2626
export function dgramSetSendBufferSize(ee: object, size: number): void
2727
export function dgramSendTo(ee: object, buf: Buffer, offset: number, length: number, path: string, cb?: (...args: any[]) => any | undefined | null): void
28-
export function startRecv(ee: object): void
2928
export function socketNewSoReuseportFd(domain: string, port: number, ip: string): number
3029
export function socketClose(fd: number): void

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
"version": "0.1.0",
44
"main": "js/index.js",
55
"types": "js/index.d.ts",
6-
"description": "TODO",
6+
"author": {
7+
"email": "oyydoibh@gmail.com",
8+
"name": "Ouyang Yadong"
9+
},
10+
"description": "nix-socket allows you to use SO_REUSEPORT, SOCK_SEQPACKET, SOCK_DGRAM in Node.js.",
711
"scripts": {
812
"artifacts": "napi artifacts",
913
"build": "napi build --platform --js false --dts js/addon.d.ts && npm run build:ts",

src/dgram.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,6 @@ pub fn dgram_send_to(
100100
wrap.send_to(env, buf, offset, length, path, cb)
101101
}
102102

103-
#[allow(dead_code)]
104-
#[napi]
105-
pub fn start_recv(env: Env, ee: JsObject) -> Result<()> {
106-
let wrap = unwrap(&env, &ee)?;
107-
wrap.start_recv(env)
108-
}
109-
110103
#[allow(dead_code)]
111104
fn string_from_i8_slice(slice: &[i8]) -> Result<String> {
112105
let trans = i8_slice_into_u8_slice(slice);
@@ -124,7 +117,6 @@ struct MsgItem {
124117

125118
pub struct DgramSocketWrap {
126119
fd: i32,
127-
// TODO test in worker_threads
128120
env: Env,
129121
handle: *mut sys::uv_poll_t,
130122
msg_queue: LinkedList<MsgItem>,

src/seqpacket.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ struct MsgItem {
3030

3131
struct SeqpacketSocketWrap {
3232
fd: i32,
33-
// TODO worker_threads
3433
env: Env,
3534
handle: *mut sys::uv_poll_t,
3635
msg_queue: LinkedList<MsgItem>,

src/util.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ pub(crate) fn i8_slice_into_u8_slice<'a>(slice: &'a [i8]) -> &'a [u8] {
1313
}
1414

1515
pub(crate) fn addr_to_string(addr: &sockaddr_un) -> String {
16-
// sockaddr_un.sun_path/c_char has varied types in different types so that we transmute() it
16+
// sockaddr_un.sun_path/c_char has varied types in different operating systems
17+
// so that we directly transmute() it
1718
let path_ref: &[i8] = unsafe { transmute(&addr.sun_path as &[c_char]) };
1819
let sockname = i8_slice_into_u8_slice(path_ref);
1920
let sockname = unsafe { str_from_u8_nul_utf8_unchecked(sockname) };

0 commit comments

Comments
 (0)