quickwin 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +17 -22
- package/README.md +1 -3
- package/examples/exec_server.js +133 -29
- package/examples/exec_server_worker.js +1 -1
- package/examples/exec_server_worker.ts +2 -2
- package/examples/pdf_preview2.js +1 -1
- package/examples/pdf_preview2.ts +1 -1
- package/examples/pdf_viewer.js +132 -28
- package/examples/pdf_viewer.tsx +1 -1
- package/examples/test_gallery.js +131 -27
- package/examples/test_react_lazy.js +131 -27
- package/examples/test_react_listbox.js +131 -27
- package/examples/test_root_window.js +131 -27
- package/examples/test_tab.js +131 -27
- package/lib/certs.js +13 -8
- package/lib/certs.ts +13 -8
- package/lib/fetch.js +51 -3
- package/lib/fetch.ts +38 -3
- package/lib/ffi/bind.js +94 -5
- package/lib/ffi/bind.ts +107 -10
- package/lib/ffi/ctype.js +33 -7
- package/lib/ffi/ctype.ts +48 -10
- package/lib/ffi/struct.js +92 -14
- package/lib/ffi/struct.ts +108 -19
- package/lib/react-qw/components/ListView.js +1 -0
- package/lib/react-qw/components/PathPicker.js +2 -2
- package/lib/react-qw/index.js +1 -1
- package/lib/react-qw/index.ts +4 -1
- package/lib/text-measure.js +3 -1
- package/lib/text-measure.ts +4 -3
- package/lib/websocket.js +32 -2
- package/lib/websocket.ts +25 -2
- package/lib/windows/advapi32.js +53 -0
- package/lib/windows/advapi32.ts +64 -0
- package/lib/windows/comctl32.js +15 -15
- package/lib/windows/comctl32.ts +15 -16
- package/lib/windows/comdlg32.js +3 -2
- package/lib/windows/comdlg32.ts +3 -2
- package/lib/windows/gdi32.js +328 -26
- package/lib/windows/gdi32.ts +349 -26
- package/lib/windows/kernel32.js +206 -10
- package/lib/windows/kernel32.ts +225 -10
- package/lib/windows/msimg32.js +38 -0
- package/lib/windows/msimg32.ts +45 -0
- package/lib/windows/ntdll.js +3 -2
- package/lib/windows/ntdll.ts +3 -2
- package/lib/windows/ole32.js +1 -1
- package/lib/windows/ole32.ts +1 -1
- package/lib/windows/psapi.js +32 -0
- package/lib/windows/psapi.ts +37 -0
- package/lib/windows/shell32.js +5 -3
- package/lib/windows/shell32.ts +5 -3
- package/lib/windows/structs.js +135 -0
- package/lib/windows/structs.ts +144 -0
- package/lib/windows/user32.js +202 -99
- package/lib/windows/user32.ts +204 -99
- package/lib/windows/version.js +29 -0
- package/lib/windows/version.ts +35 -0
- package/lib/windows/winspool.js +71 -0
- package/lib/windows/winspool.ts +80 -0
- package/package.json +1 -1
- package/quickwin.d.ts +11 -5
- package/quickwin_const.d.ts +136 -0
- package/qwin-nowasm-x86.exe +0 -0
- package/qwin-nowasm.exe +0 -0
- package/qwin-x86.exe +0 -0
- package/qwin.exe +0 -0
- package/test/run.js +7 -0
- package/test/run.ts +7 -0
- package/test/test_basic_fetch.js +21 -0
- package/test/test_basic_fetch.ts +17 -0
- package/test/test_ffi.js +6 -6
- package/test/test_ffi.ts +6 -6
- package/test/test_ffi_abi.js +55 -0
- package/test/test_ffi_abi.ts +56 -0
- package/test/test_ffi_array.js +116 -0
- package/test/test_ffi_array.ts +141 -0
- package/test/test_ffi_bind.js +82 -0
- package/test/test_ffi_bind.ts +71 -0
- package/test/test_files.js +102 -0
- package/test/test_files.ts +121 -0
- package/test/test_gdi_draw.js +681 -0
- package/test/test_gdi_draw.ts +725 -0
- package/test/test_net_fetch.js +4 -3
- package/test/test_net_fetch.ts +4 -3
- package/test/test_printer.js +137 -0
- package/test/test_printer.ts +148 -0
- package/test/test_proc.js +141 -0
- package/test/test_proc.ts +163 -0
- package/test/test_react_complex.js +131 -27
- package/test/test_react_counter.js +131 -27
- package/test/test_react_flex.js +131 -27
- package/test/test_react_hidden.js +131 -27
- package/test/test_react_listview_link.js +131 -27
- package/test/test_react_notify.js +131 -27
- package/test/test_react_render.js +131 -27
- package/test/test_registry.js +74 -0
- package/test/test_registry.ts +95 -0
- package/test/test_sysinfo.js +122 -0
- package/test/test_sysinfo.ts +141 -0
- package/test/test_wolfssl_read.js +45 -44
- package/test/test_wolfssl_read.ts +42 -42
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import * as ffi from 'ffi'
|
|
2
|
+
import * as os from 'os'
|
|
3
|
+
import { WCHAR } from '../lib/ffi/bind.js'
|
|
4
|
+
import { NULL, PtrArrayBuffer, type Ptr } from '../lib/ffi/ctype.js'
|
|
5
|
+
import {
|
|
6
|
+
FormatMessage, GetCommandLineW, GetComputerName, GetEnvironmentVariable,
|
|
7
|
+
GetLocalTime, GetModuleFileName, GetSystemDirectory, GetSystemTimeAsFileTime,
|
|
8
|
+
GlobalAlloc, GlobalLock, GlobalUnlock, QueryPerformanceCounter,
|
|
9
|
+
QueryPerformanceFrequency, RtlMoveMemory, Sleep,
|
|
10
|
+
} from '../lib/windows/kernel32.js'
|
|
11
|
+
import {
|
|
12
|
+
CloseClipboard, EmptyClipboard, GetClipboardData, OpenClipboard,
|
|
13
|
+
RegisterClipboardFormat, SetClipboardData,
|
|
14
|
+
} from '../lib/windows/user32.js'
|
|
15
|
+
import {
|
|
16
|
+
GetFileVersionInfoSize, GetFileVersionInfo, VerQueryValue,
|
|
17
|
+
} from '../lib/windows/version.js'
|
|
18
|
+
import { SYSTEMTIME } from '../lib/windows/structs.js'
|
|
19
|
+
import { Tester } from './test_helper.js'
|
|
20
|
+
|
|
21
|
+
// 进程内存跟进读:ffi 只有 readByte(无 DataView/写通道),u32 小端拼值 / 指针随位宽
|
|
22
|
+
// (| 是有符号 32 位运算,>>> 0 归一无符号——0xFEEF04BD 类高位值否则读成负数)
|
|
23
|
+
function readU32At(addr: number): number {
|
|
24
|
+
return (ffi.readByte(addr) | (ffi.readByte(addr + 1) << 8) |
|
|
25
|
+
(ffi.readByte(addr + 2) << 16) | (ffi.readByte(addr + 3) << 24)) >>> 0
|
|
26
|
+
}
|
|
27
|
+
function readPtr(dv: DataView, offset: number): number {
|
|
28
|
+
if (os.arch === 'ia32') return dv.getUint32(offset, true)
|
|
29
|
+
return dv.getUint32(offset, true) + dv.getUint32(offset + 4, true) * 4294967296
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const suite = {
|
|
33
|
+
name: 'sysinfo',
|
|
34
|
+
run: (t: Tester) => {
|
|
35
|
+
t.section('QueryPerformanceCounter: frequency + monotonic')
|
|
36
|
+
const freqB = new PtrArrayBuffer(8)
|
|
37
|
+
t.checkTrue('QueryPerformanceFrequency ok', QueryPerformanceFrequency(freqB) !== 0)
|
|
38
|
+
const freq = new DataView(freqB).getBigInt64(0, true)
|
|
39
|
+
t.checkTrue(`frequency sane (${freq})`, freq > 0n)
|
|
40
|
+
const c1 = new PtrArrayBuffer(8)
|
|
41
|
+
const c2 = new PtrArrayBuffer(8)
|
|
42
|
+
QueryPerformanceCounter(c1)
|
|
43
|
+
QueryPerformanceCounter(c2)
|
|
44
|
+
const v1 = new DataView(c1).getBigInt64(0, true)
|
|
45
|
+
const v2 = new DataView(c2).getBigInt64(0, true)
|
|
46
|
+
t.checkTrue(`counter monotonic (${v1} <= ${v2})`, v1 <= v2)
|
|
47
|
+
|
|
48
|
+
t.section('Sleep: QPC-measured elapsed lands in interval')
|
|
49
|
+
QueryPerformanceCounter(c1)
|
|
50
|
+
Sleep(50)
|
|
51
|
+
QueryPerformanceCounter(c2)
|
|
52
|
+
const elapsedMs = Number((new DataView(c2).getBigInt64(0, true) -
|
|
53
|
+
new DataView(c1).getBigInt64(0, true)) * 1000n / freq)
|
|
54
|
+
t.checkTrue(`Sleep(50) -> ${elapsedMs}ms in [30, 3000)`, elapsedMs >= 30 && elapsedMs < 3000)
|
|
55
|
+
|
|
56
|
+
t.section('GetLocalTime / GetSystemTimeAsFileTime')
|
|
57
|
+
const st = SYSTEMTIME.alloc()
|
|
58
|
+
GetLocalTime(st.ptr)
|
|
59
|
+
const got = SYSTEMTIME.decode(st)
|
|
60
|
+
t.checkTrue(`year sane (${got.wYear})`, got.wYear >= 2024 && got.wYear <= 2100)
|
|
61
|
+
t.checkTrue(`month sane (${got.wMonth})`, got.wMonth >= 1 && got.wMonth <= 12)
|
|
62
|
+
const ftB = new PtrArrayBuffer(8)
|
|
63
|
+
GetSystemTimeAsFileTime(ftB)
|
|
64
|
+
const ft = new DataView(ftB).getBigUint64(0, true)
|
|
65
|
+
t.checkTrue(`FILETIME > 0 (${ft})`, ft > 0n)
|
|
66
|
+
|
|
67
|
+
t.section('env / computer name / module path')
|
|
68
|
+
const pathW = WCHAR.alloc(4096)
|
|
69
|
+
const pathLen = GetEnvironmentVariable('PATH', pathW, 4096)
|
|
70
|
+
t.checkTrue(`PATH non-empty (${pathLen} chars)`, pathLen > 0)
|
|
71
|
+
const nameW = WCHAR.alloc(260)
|
|
72
|
+
const nameLenB = new PtrArrayBuffer(4)
|
|
73
|
+
new Uint32Array(nameLenB)[0] = 260
|
|
74
|
+
t.checkTrue('GetComputerName ok', GetComputerName(nameW, nameLenB) !== 0)
|
|
75
|
+
const compName = WCHAR.decode(nameW)
|
|
76
|
+
t.checkTrue(`computer name non-empty (${compName})`, compName.length > 0)
|
|
77
|
+
const modW = WCHAR.alloc(520)
|
|
78
|
+
const modLen = GetModuleFileName(NULL, modW, 520)
|
|
79
|
+
const modPath = WCHAR.decode(modW)
|
|
80
|
+
t.checkTrue(`exe path has qwin (${modLen > 0})`, /qwin/i.test(modPath))
|
|
81
|
+
// 生产绑定的返回位 `<WCHAR>ptr!`:内建 WCHAR 自动解码 + `!` 非空担保(直接 string)
|
|
82
|
+
const cmdLine = GetCommandLineW()
|
|
83
|
+
t.checkTrue(`GetCommandLineW decodes to non-empty string (${cmdLine.length} chars)`,
|
|
84
|
+
typeof cmdLine === 'string' && cmdLine.length > 0)
|
|
85
|
+
|
|
86
|
+
t.section('FormatMessage: error 2 -> readable text')
|
|
87
|
+
const msgW = WCHAR.alloc(512)
|
|
88
|
+
const msgLen = FormatMessage(0x1200 /* FROM_SYSTEM | IGNORE_INSERTS */,
|
|
89
|
+
NULL, 2 /* ERROR_FILE_NOT_FOUND */, 0, msgW, 512, NULL)
|
|
90
|
+
// 语言无关断言(VM 中/英文系统都可过):错误 2 的系统文字必然 > 4 字符
|
|
91
|
+
t.checkTrue(`error 2 message non-empty (${msgLen} chars)`, msgLen > 4)
|
|
92
|
+
|
|
93
|
+
t.section('clipboard roundtrip: CF_UNICODETEXT (GlobalAlloc/RtlMoveMemory)')
|
|
94
|
+
t.checkTrue('OpenClipboard', OpenClipboard(NULL) !== 0)
|
|
95
|
+
t.checkTrue('EmptyClipboard', EmptyClipboard() !== 0)
|
|
96
|
+
const clipText = 'QuickWin clip roundtrip 你好'
|
|
97
|
+
const clipSrc = WCHAR.encode(clipText) // 自带 NUL 终止
|
|
98
|
+
const hMem = GlobalAlloc(0x2 /* GMEM_MOVEABLE */, clipSrc.byteLength)
|
|
99
|
+
t.checkTrue(`GlobalAlloc valid (${hMem})`, hMem !== 0)
|
|
100
|
+
const clipDst = GlobalLock(hMem)
|
|
101
|
+
t.checkTrue(`GlobalLock address (${clipDst})`, clipDst !== 0)
|
|
102
|
+
RtlMoveMemory(clipDst, clipSrc, clipSrc.byteLength)
|
|
103
|
+
GlobalUnlock(hMem)
|
|
104
|
+
const setR = SetClipboardData(13 /* CF_UNICODETEXT */, hMem)
|
|
105
|
+
t.checkTrue('SetClipboardData (ownership -> system)', setR !== 0)
|
|
106
|
+
CloseClipboard()
|
|
107
|
+
t.checkTrue('OpenClipboard (read back)', OpenClipboard(NULL) !== 0)
|
|
108
|
+
const hRead = GetClipboardData(13)
|
|
109
|
+
t.checkTrue('GetClipboardData handle', hRead !== 0)
|
|
110
|
+
const pRead = hRead ? GlobalLock(hRead) : 0
|
|
111
|
+
const back = pRead ? WCHAR.decode(pRead as Ptr<'WCHAR'>) : ''
|
|
112
|
+
if (pRead) GlobalUnlock(hRead)
|
|
113
|
+
CloseClipboard()
|
|
114
|
+
t.check('clip text roundtrip', clipText, back)
|
|
115
|
+
t.checkTrue('RegisterClipboardFormat', RegisterClipboardFormat('QuickWinClipFmt') !== 0)
|
|
116
|
+
|
|
117
|
+
t.section('version resource of kernel32.dll')
|
|
118
|
+
const sysW = WCHAR.alloc(300)
|
|
119
|
+
GetSystemDirectory(sysW, 300) // 尾不带反斜杠
|
|
120
|
+
const k32Path = `${WCHAR.decode(sysW)}\\kernel32.dll`
|
|
121
|
+
const hB = new PtrArrayBuffer(4)
|
|
122
|
+
const vSize = GetFileVersionInfoSize(k32Path, hB)
|
|
123
|
+
t.checkTrue(`version size > 0 (${vSize})`, vSize > 0)
|
|
124
|
+
if (vSize > 0) {
|
|
125
|
+
const vHandle = new Uint32Array(hB)[0]!
|
|
126
|
+
const vBuf = new PtrArrayBuffer(vSize)
|
|
127
|
+
t.checkTrue('GetFileVersionInfo', GetFileVersionInfo(k32Path, vHandle, vSize, vBuf) !== 0)
|
|
128
|
+
const pBuf = new PtrArrayBuffer(8)
|
|
129
|
+
const pLen = new PtrArrayBuffer(4)
|
|
130
|
+
t.checkTrue('VerQueryValue root block', VerQueryValue(vBuf, '\\', pBuf, pLen) !== 0)
|
|
131
|
+
const rootAddr = readPtr(new DataView(pBuf), 0)
|
|
132
|
+
const rootLen = new Uint32Array(pLen)[0]
|
|
133
|
+
t.checkTrue(`VS_FIXEDFILEINFO len >= 52 (${rootLen})`, rootLen! >= 52)
|
|
134
|
+
t.check('VS_FIXEDFILEINFO signature', 0xfeef04bd, readU32At(rootAddr))
|
|
135
|
+
const fms = readU32At(rootAddr + 8)
|
|
136
|
+
const fls = readU32At(rootAddr + 12)
|
|
137
|
+
const ver = `${fms >>> 16}.${fms & 0xffff}.${fls >>> 16}.${fls & 0xffff}`
|
|
138
|
+
t.checkTrue(`file version sane (${ver})`, fms !== 0 || fls !== 0)
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
}
|
|
@@ -19,7 +19,8 @@ export const suite = {
|
|
|
19
19
|
std.printf(' FAIL: %s\n', name);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
// ── wolfSSL_read return contract:
|
|
22
|
+
// ── wolfSSL_read return contract: raw int, data lands in the
|
|
23
|
+
// caller-owned buffer (thin wrapper — errors stay numbers) ──
|
|
23
24
|
t.section('wolfSSL_read contract (HTTPS /large/65536)');
|
|
24
25
|
await new Promise((resolve) => {
|
|
25
26
|
const s = sock.socket();
|
|
@@ -35,10 +36,9 @@ export const suite = {
|
|
|
35
36
|
let sentRequest = false;
|
|
36
37
|
let total = 0;
|
|
37
38
|
const EXPECTED = 65536;
|
|
38
|
-
let
|
|
39
|
-
let
|
|
40
|
-
let
|
|
41
|
-
let nullErrOk = true;
|
|
39
|
+
let sawNonNumber = false;
|
|
40
|
+
let sawEof = false;
|
|
41
|
+
let errOk = true;
|
|
42
42
|
let done = false;
|
|
43
43
|
const finish = () => {
|
|
44
44
|
if (done)
|
|
@@ -48,10 +48,10 @@ export const suite = {
|
|
|
48
48
|
assert('connected', connected);
|
|
49
49
|
assert('handshake ok', handshakeDone);
|
|
50
50
|
assert('request sent', sentRequest);
|
|
51
|
-
assert('received
|
|
52
|
-
assert('wolfSSL_read
|
|
53
|
-
assert('
|
|
54
|
-
assert('
|
|
51
|
+
assert('received full body', total >= EXPECTED);
|
|
52
|
+
assert('wolfSSL_read always returned number', !sawNonNumber);
|
|
53
|
+
assert('no-data/EOF observed via int (0 or ZERO_RETURN)', sawEof);
|
|
54
|
+
assert('n<=0 get_error in {WANT_READ,WANT_WRITE,ZERO_RETURN}', errOk);
|
|
55
55
|
if (ssl) {
|
|
56
56
|
wolfssl.wolfSSL_free(ssl);
|
|
57
57
|
ssl = null;
|
|
@@ -77,39 +77,39 @@ export const suite = {
|
|
|
77
77
|
sentRequest = true;
|
|
78
78
|
};
|
|
79
79
|
const onReadable = () => {
|
|
80
|
-
// Drain until
|
|
80
|
+
// Drain until EOF (n===0 / ZERO_RETURN) or WANT_* hands back
|
|
81
|
+
// to the event loop.
|
|
81
82
|
for (let guard = 0; guard < 10000; guard++) {
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
nullErrOk = false;
|
|
88
|
-
std.printf(' null get_error=%d\n', err);
|
|
89
|
-
}
|
|
90
|
-
if (err === ZERO_RETURN || err === 1 || err === 5) {
|
|
91
|
-
// EOF / fatal — done draining
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
// WANT_*: wait for next FD_READ/WRITE
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
if (typeof d === 'number') {
|
|
98
|
-
// Pre-fix C API returns number 0/-1 — record and stop
|
|
99
|
-
sawNumber = true;
|
|
100
|
-
std.printf(' FAIL got number %d (want ArrayBuffer|null)\n', d);
|
|
83
|
+
const buf = new ArrayBuffer(8192);
|
|
84
|
+
const n = wolfssl.wolfSSL_read(ssl, buf);
|
|
85
|
+
if (typeof n !== 'number') {
|
|
86
|
+
sawNonNumber = true;
|
|
87
|
+
std.printf(' FAIL got non-number %s (want int)\n', String(n));
|
|
101
88
|
finish();
|
|
102
89
|
return;
|
|
103
90
|
}
|
|
104
|
-
if (
|
|
105
|
-
|
|
106
|
-
total += d.byteLength;
|
|
91
|
+
if (n > 0) {
|
|
92
|
+
total += n;
|
|
107
93
|
// Keep draining after the body is complete: the point of
|
|
108
94
|
// this suite is the no-data/EOF contract, so a full body
|
|
109
|
-
// must not short-circuit the read that would observe
|
|
95
|
+
// must not short-circuit the read that would observe it.
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
const err = wolfssl.wolfSSL_get_error(ssl, n);
|
|
99
|
+
if (err !== WANT_READ && err !== WANT_WRITE && err !== ZERO_RETURN) {
|
|
100
|
+
errOk = false;
|
|
101
|
+
std.printf(' n=%d get_error=%d outside {WANT_READ,WANT_WRITE,ZERO_RETURN}\n', n, err);
|
|
102
|
+
finish();
|
|
103
|
+
return;
|
|
110
104
|
}
|
|
105
|
+
if (n === 0 || err === ZERO_RETURN) {
|
|
106
|
+
sawEof = true;
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
// WANT_*: wait for next FD_READ/WRITE
|
|
110
|
+
return;
|
|
111
111
|
}
|
|
112
|
-
if (
|
|
112
|
+
if (sawEof)
|
|
113
113
|
finish();
|
|
114
114
|
};
|
|
115
115
|
sock.set_on_event(s, (event) => {
|
|
@@ -178,21 +178,22 @@ export const suite = {
|
|
|
178
178
|
}
|
|
179
179
|
if (event.lNetworkEvents & 32 /* sock.FdEvent.FD_CLOSE */) {
|
|
180
180
|
// drain remaining then finish
|
|
181
|
-
if (ssl && sentRequest && !
|
|
181
|
+
if (ssl && sentRequest && !sawNonNumber) {
|
|
182
182
|
onReadable();
|
|
183
183
|
}
|
|
184
|
-
if (!
|
|
185
|
-
//
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
184
|
+
if (!sawNonNumber) {
|
|
185
|
+
// Server close without an observed EOF read is an edge —
|
|
186
|
+
// don't fail if the body already completed.
|
|
187
|
+
if (!sawEof && total < EXPECTED && total > 0) {
|
|
188
|
+
sawEof = true;
|
|
189
189
|
}
|
|
190
|
-
if (total >= EXPECTED ||
|
|
190
|
+
if (total >= EXPECTED || sawEof)
|
|
191
191
|
finish();
|
|
192
|
-
else
|
|
192
|
+
else {
|
|
193
193
|
assert('data before close', false);
|
|
194
|
-
|
|
195
|
-
|
|
194
|
+
if (!done)
|
|
195
|
+
finish();
|
|
196
|
+
}
|
|
196
197
|
}
|
|
197
198
|
}
|
|
198
199
|
});
|
|
@@ -17,7 +17,8 @@ export const suite = {
|
|
|
17
17
|
else { t.fail++; std.printf(' FAIL: %s\n', name) }
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
// ── wolfSSL_read return contract:
|
|
20
|
+
// ── wolfSSL_read return contract: raw int, data lands in the
|
|
21
|
+
// caller-owned buffer (thin wrapper — errors stay numbers) ──
|
|
21
22
|
t.section('wolfSSL_read contract (HTTPS /large/65536)')
|
|
22
23
|
await new Promise<void>((resolve) => {
|
|
23
24
|
const s = sock.socket()
|
|
@@ -34,10 +35,9 @@ export const suite = {
|
|
|
34
35
|
let sentRequest = false
|
|
35
36
|
let total = 0
|
|
36
37
|
const EXPECTED = 65536
|
|
37
|
-
let
|
|
38
|
-
let
|
|
39
|
-
let
|
|
40
|
-
let nullErrOk = true
|
|
38
|
+
let sawNonNumber = false
|
|
39
|
+
let sawEof = false
|
|
40
|
+
let errOk = true
|
|
41
41
|
let done = false
|
|
42
42
|
|
|
43
43
|
const finish = () => {
|
|
@@ -47,10 +47,10 @@ export const suite = {
|
|
|
47
47
|
assert('connected', connected)
|
|
48
48
|
assert('handshake ok', handshakeDone)
|
|
49
49
|
assert('request sent', sentRequest)
|
|
50
|
-
assert('received
|
|
51
|
-
assert('wolfSSL_read
|
|
52
|
-
assert('
|
|
53
|
-
assert('
|
|
50
|
+
assert('received full body', total >= EXPECTED)
|
|
51
|
+
assert('wolfSSL_read always returned number', !sawNonNumber)
|
|
52
|
+
assert('no-data/EOF observed via int (0 or ZERO_RETURN)', sawEof)
|
|
53
|
+
assert('n<=0 get_error in {WANT_READ,WANT_WRITE,ZERO_RETURN}', errOk)
|
|
54
54
|
if (ssl) { wolfssl.wolfSSL_free(ssl); ssl = null }
|
|
55
55
|
if (ctx) { wolfssl.wolfSSL_CTX_free(ctx); ctx = null }
|
|
56
56
|
sock.closesocket(s)
|
|
@@ -72,39 +72,39 @@ export const suite = {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
const onReadable = () => {
|
|
75
|
-
// Drain until
|
|
75
|
+
// Drain until EOF (n===0 / ZERO_RETURN) or WANT_* hands back
|
|
76
|
+
// to the event loop.
|
|
76
77
|
for (let guard = 0; guard < 10000; guard++) {
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
nullErrOk = false
|
|
83
|
-
std.printf(' null get_error=%d\n', err)
|
|
84
|
-
}
|
|
85
|
-
if (err === ZERO_RETURN || err === 1 || err === 5) {
|
|
86
|
-
// EOF / fatal — done draining
|
|
87
|
-
break
|
|
88
|
-
}
|
|
89
|
-
// WANT_*: wait for next FD_READ/WRITE
|
|
90
|
-
return
|
|
91
|
-
}
|
|
92
|
-
if (typeof d === 'number') {
|
|
93
|
-
// Pre-fix C API returns number 0/-1 — record and stop
|
|
94
|
-
sawNumber = true
|
|
95
|
-
std.printf(' FAIL got number %d (want ArrayBuffer|null)\n', d)
|
|
78
|
+
const buf = new ArrayBuffer(8192)
|
|
79
|
+
const n = wolfssl.wolfSSL_read(ssl!, buf)
|
|
80
|
+
if (typeof n !== 'number') {
|
|
81
|
+
sawNonNumber = true
|
|
82
|
+
std.printf(' FAIL got non-number %s (want int)\n', String(n))
|
|
96
83
|
finish()
|
|
97
84
|
return
|
|
98
85
|
}
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
total += d.byteLength
|
|
86
|
+
if (n > 0) {
|
|
87
|
+
total += n
|
|
102
88
|
// Keep draining after the body is complete: the point of
|
|
103
89
|
// this suite is the no-data/EOF contract, so a full body
|
|
104
|
-
// must not short-circuit the read that would observe
|
|
90
|
+
// must not short-circuit the read that would observe it.
|
|
91
|
+
continue
|
|
92
|
+
}
|
|
93
|
+
const err = wolfssl.wolfSSL_get_error(ssl!, n)
|
|
94
|
+
if (err !== WANT_READ && err !== WANT_WRITE && err !== ZERO_RETURN) {
|
|
95
|
+
errOk = false
|
|
96
|
+
std.printf(' n=%d get_error=%d outside {WANT_READ,WANT_WRITE,ZERO_RETURN}\n', n, err)
|
|
97
|
+
finish()
|
|
98
|
+
return
|
|
99
|
+
}
|
|
100
|
+
if (n === 0 || err === ZERO_RETURN) {
|
|
101
|
+
sawEof = true
|
|
102
|
+
break
|
|
105
103
|
}
|
|
104
|
+
// WANT_*: wait for next FD_READ/WRITE
|
|
105
|
+
return
|
|
106
106
|
}
|
|
107
|
-
if (
|
|
107
|
+
if (sawEof) finish()
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
sock.set_on_event(s, (event: { lNetworkEvents: number; iErrorCode: number[] }) => {
|
|
@@ -163,17 +163,17 @@ export const suite = {
|
|
|
163
163
|
|
|
164
164
|
if (event.lNetworkEvents & sock.FdEvent.FD_CLOSE) {
|
|
165
165
|
// drain remaining then finish
|
|
166
|
-
if (ssl && sentRequest && !
|
|
166
|
+
if (ssl && sentRequest && !sawNonNumber) {
|
|
167
167
|
onReadable()
|
|
168
168
|
}
|
|
169
|
-
if (!
|
|
170
|
-
//
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
169
|
+
if (!sawNonNumber) {
|
|
170
|
+
// Server close without an observed EOF read is an edge —
|
|
171
|
+
// don't fail if the body already completed.
|
|
172
|
+
if (!sawEof && total < EXPECTED && total > 0) {
|
|
173
|
+
sawEof = true
|
|
174
174
|
}
|
|
175
|
-
if (total >= EXPECTED ||
|
|
176
|
-
else assert('data before close', false); if (!done) finish()
|
|
175
|
+
if (total >= EXPECTED || sawEof) finish()
|
|
176
|
+
else { assert('data before close', false); if (!done) finish() }
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
})
|