MCPcopy Index your code
hub / github.com/nodejs/node / onSocket

Function onSocket

test/parallel/test-net-pingpong.js:38–81  ·  view source on GitHub ↗
(socket)

Source from the content-addressed store, hash-verified

36 );
37
38 function onSocket(socket) {
39 assert.strictEqual(socket.server, server);
40 assert.strictEqual(
41 server,
42 server.getConnections(common.mustSucceed((connections) => {
43 assert.strictEqual(connections, 1);
44 }))
45 );
46
47 socket.setNoDelay();
48 socket.timeout = 0;
49
50 socket.setEncoding('utf8');
51 socket.on('data', common.mustCall(function(data) {
52 // Since we never queue data (we're always waiting for the PING
53 // before sending a pong) the writeQueueSize should always be less
54 // than one message.
55 assert.ok(socket.bufferSize >= 0 && socket.bufferSize <= 4);
56
57 assert.strictEqual(socket.writable, true);
58 assert.strictEqual(socket.readable, true);
59 assert.ok(count <= N);
60 assert.strictEqual(data, 'PING');
61
62 socket.write('PONG', common.mustCall(function() {
63 sentPongs++;
64 }));
65 }, N + 1));
66
67 socket.on('end', common.mustCall(function() {
68 assert.strictEqual(socket.allowHalfOpen, true);
69 assert.strictEqual(socket.writable, true); // Because allowHalfOpen
70 assert.strictEqual(socket.readable, false);
71 socket.end();
72 }));
73
74 socket.on('error', common.mustNotCall());
75
76 socket.on('close', common.mustCall(function() {
77 assert.strictEqual(socket.writable, false);
78 assert.strictEqual(socket.readable, false);
79 socket.server.close();
80 }));
81 }
82
83
84 server.listen(port, host, common.mustCall(function() {

Callers

nothing calls this directly

Calls 7

getConnectionsMethod · 0.80
closeMethod · 0.65
setEncodingMethod · 0.45
onMethod · 0.45
okMethod · 0.45
writeMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…