MCPcopy Create free account
hub / github.com/nodejs/node / main

Function main

benchmark/net/tcp-raw-pipe.js:20–146  ·  view source on GitHub ↗
({ dur, len, type })

Source from the content-addressed store, hash-verified

18});
19
20function main({ dur, len, type }) {
21 const {
22 TCP,
23 TCPConnectWrap,
24 constants: TCPConstants,
25 } = common.binding('tcp_wrap');
26 const { WriteWrap } = common.binding('stream_wrap');
27 const PORT = common.PORT;
28
29 function fail(err, syscall) {
30 throw util._errnoException(err, syscall);
31 }
32
33 // Server
34 const serverHandle = new TCP(TCPConstants.SERVER);
35 let err = serverHandle.bind('127.0.0.1', PORT);
36 if (err)
37 fail(err, 'bind');
38
39 err = serverHandle.listen(511);
40 if (err)
41 fail(err, 'listen');
42
43 serverHandle.onconnection = function(err, clientHandle) {
44 if (err)
45 fail(err, 'connect');
46
47 clientHandle.onread = function(buffer) {
48 // We're not expecting to ever get an EOF from the client.
49 // Just lots of data forever.
50 if (!buffer)
51 fail('read');
52
53 const writeReq = new WriteWrap();
54 writeReq.async = false;
55 err = clientHandle.writeBuffer(writeReq, Buffer.from(buffer));
56
57 if (err)
58 fail(err, 'write');
59
60 writeReq.oncomplete = function(status, handle, err) {
61 if (err)
62 fail(err, 'write');
63 };
64 };
65
66 clientHandle.readStart();
67 };
68
69 // Client
70 let chunk;
71 switch (type) {
72 case 'buf':
73 chunk = Buffer.alloc(len, 'x');
74 break;
75 case 'utf':
76 chunk = 'ü'.repeat(len / 2);
77 break;

Callers

nothing calls this directly

Calls 12

listenMethod · 0.80
allocMethod · 0.80
failFunction · 0.70
writeFunction · 0.70
connectMethod · 0.65
setTimeoutFunction · 0.50
bindMethod · 0.45
fromMethod · 0.45
readStartMethod · 0.45
startMethod · 0.45
endMethod · 0.45
exitMethod · 0.45

Tested by

no test coverage detected