deno.land / std@0.166.0 / node / _tools / test / parallel / test-dgram-createSocket-type.js

test-dgram-createSocket-type.js
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// deno-fmt-ignore-file// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.// Taken from Node 18.12.0// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';const common = require('../common');const assert = require('assert');const dgram = require('dgram');const invalidTypes = [ 'test', ['udp4'], new String('udp4'), 1, {}, true, false, null, undefined,];const validTypes = [ 'udp4', 'udp6', { type: 'udp4' }, { type: 'udp6' },];const errMessage = /^Bad socket type specified\. Valid types are: udp4, udp6$/;
// Error must be thrown with invalid typesinvalidTypes.forEach((invalidType) => { assert.throws(() => { dgram.createSocket(invalidType); }, { code: 'ERR_SOCKET_BAD_TYPE', name: 'TypeError', message: errMessage });});
// Error must not be thrown with valid typesvalidTypes.forEach((validType) => { const socket = dgram.createSocket(validType); socket.close();});
// Ensure buffer sizes can be set{ const socket = dgram.createSocket({ type: 'udp4', recvBufferSize: 10000, sendBufferSize: 15000 });
socket.bind(common.mustCall(() => { // note: linux will double the buffer size assert.ok(socket.getRecvBufferSize() === 10000 || socket.getRecvBufferSize() === 20000, 'SO_RCVBUF not 10000 or 20000, ' + `was ${socket.getRecvBufferSize()}`); assert.ok(socket.getSendBufferSize() === 15000 || socket.getSendBufferSize() === 30000, 'SO_SNDBUF not 15000 or 30000, ' + `was ${socket.getRecvBufferSize()}`); socket.close(); }));}
std

Version Info

Tagged at
a year ago