diff --git a/index.js b/index.js index f13c117..47c79cf 100644 --- a/index.js +++ b/index.js @@ -442,7 +442,8 @@ const Server = exports.Server = class PipeServer extends EventEmitter { try { binding.accept(this._handle, pipe._handle) - pipe._state |= constants.state.CONNECTED + pipe._state |= constants.state.CONNECTED | constants.state.READABLE | constants.state.WRITABLE + pipe._path = this._path this._connections.add(pipe) diff --git a/test.js b/test.js index 02c6144..98e909d 100644 --- a/test.js +++ b/test.js @@ -5,27 +5,98 @@ const Pipe = require('.') const isWindows = Bare.platform === 'win32' test('server + client', async (t) => { - t.plan(3) + t.plan(2) const n = name() const lc = t.test('lifecycle') - lc.plan(1) + lc.plan(6) const server = Pipe.createServer() server .on('close', () => t.pass('server closed')) .on('connection', (pipe) => { pipe - .on('data', (data) => lc.alike(data, Buffer.from('hello pipe'))) - .end() + .on('close', () => lc.pass('server socket closed')) + .on('data', (data) => lc.alike(data, Buffer.from('hello server'))) + .on('end', () => lc.pass('server ended')) + .end('hello client') }) .listen(n) const client = new Pipe(n) client - .on('close', () => t.pass('client closed')) - .end('hello pipe') + .on('close', () => lc.pass('client socket closed')) + .on('data', (data) => lc.alike(data, Buffer.from('hello client'))) + .on('end', () => lc.pass('client ended')) + .end('hello server') + + await lc + + server.close() +}) + +test('server + client, only server writes', async (t) => { + t.plan(2) + + const n = name() + + const lc = t.test('lifecycle') + lc.plan(5) + + const server = Pipe.createServer() + server + .on('close', () => t.pass('server closed')) + .on('connection', (pipe) => { + pipe + .on('close', () => lc.pass('server socket closed')) + .on('data', (data) => lc.alike(data, Buffer.from('hello server'))) + .on('end', () => lc.pass('server ended')) + .end('hello client') + }) + .listen(n) + + const client = new Pipe(n) + client + .on('close', () => lc.pass('client socket closed')) + .on('data', (data) => lc.alike(data, Buffer.from('hello client'))) + .on('end', () => { + lc.pass('client ended') + client.end() + }) + + await lc + + server.close() +}) + +test('server + client, only client writes', async (t) => { + t.plan(2) + + const n = name() + + const lc = t.test('lifecycle') + lc.plan(5) + + const server = Pipe.createServer() + server + .on('close', () => t.pass('server closed')) + .on('connection', (pipe) => { + pipe + .on('close', () => lc.pass('server socket closed')) + .on('data', (data) => lc.alike(data, Buffer.from('hello server'))) + .on('end', () => { + lc.pass('server ended') + pipe.end() + }) + }) + .listen(n) + + const client = new Pipe(n) + client + .on('close', () => lc.pass('client socket closed')) + .on('end', () => lc.pass('client ended')) + .end('hello server') await lc