Skip to content

Commit

Permalink
Fix end not emitting when only server writes
Browse files Browse the repository at this point in the history
Closes #10
  • Loading branch information
kasperisager committed Oct 3, 2024
1 parent feb6cd7 commit c421d7f
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 7 deletions.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
83 changes: 77 additions & 6 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c421d7f

Please sign in to comment.