myde-unix-socket 0.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/Cargo.lock +203 -0
- package/Cargo.toml +16 -0
- package/LICENSE +176 -0
- package/README.md +262 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +67 -0
- package/dist/socket.test.d.ts +2 -0
- package/dist/socket.test.d.ts.map +1 -0
- package/myde-unix-socket-0.1.0.tgz +0 -0
- package/package.json +41 -0
- package/src/index.ts +166 -0
- package/src/lib.rs +1 -0
- package/src/socket.rs +334 -0
- package/src/socket.test.ts +557 -0
- package/tsconfig.json +24 -0
- package/vite.config.ts +29 -0
package/Cargo.lock
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
|
2
|
+
# It is not intended for manual editing.
|
|
3
|
+
version = 4
|
|
4
|
+
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "autocfg"
|
|
7
|
+
version = "1.5.0"
|
|
8
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
9
|
+
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
|
|
10
|
+
|
|
11
|
+
[[package]]
|
|
12
|
+
name = "bitflags"
|
|
13
|
+
version = "2.11.0"
|
|
14
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
15
|
+
checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af"
|
|
16
|
+
|
|
17
|
+
[[package]]
|
|
18
|
+
name = "cfg-if"
|
|
19
|
+
version = "1.0.4"
|
|
20
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
21
|
+
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
|
22
|
+
|
|
23
|
+
[[package]]
|
|
24
|
+
name = "either"
|
|
25
|
+
version = "1.15.0"
|
|
26
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
27
|
+
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
|
|
28
|
+
|
|
29
|
+
[[package]]
|
|
30
|
+
name = "getrandom"
|
|
31
|
+
version = "0.2.17"
|
|
32
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
33
|
+
checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0"
|
|
34
|
+
dependencies = [
|
|
35
|
+
"cfg-if",
|
|
36
|
+
"libc",
|
|
37
|
+
"wasi",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
[[package]]
|
|
41
|
+
name = "libc"
|
|
42
|
+
version = "0.2.183"
|
|
43
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
44
|
+
checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d"
|
|
45
|
+
|
|
46
|
+
[[package]]
|
|
47
|
+
name = "libloading"
|
|
48
|
+
version = "0.8.9"
|
|
49
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
50
|
+
checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55"
|
|
51
|
+
dependencies = [
|
|
52
|
+
"cfg-if",
|
|
53
|
+
"windows-link",
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
[[package]]
|
|
57
|
+
name = "linkme"
|
|
58
|
+
version = "0.3.35"
|
|
59
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
60
|
+
checksum = "5e3283ed2d0e50c06dd8602e0ab319bb048b6325d0bba739db64ed8205179898"
|
|
61
|
+
dependencies = [
|
|
62
|
+
"linkme-impl",
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
[[package]]
|
|
66
|
+
name = "linkme-impl"
|
|
67
|
+
version = "0.3.35"
|
|
68
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
69
|
+
checksum = "e5cec0ec4228b4853bb129c84dbf093a27e6c7a20526da046defc334a1b017f7"
|
|
70
|
+
dependencies = [
|
|
71
|
+
"proc-macro2",
|
|
72
|
+
"quote",
|
|
73
|
+
"syn",
|
|
74
|
+
]
|
|
75
|
+
|
|
76
|
+
[[package]]
|
|
77
|
+
name = "memoffset"
|
|
78
|
+
version = "0.9.1"
|
|
79
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
80
|
+
checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a"
|
|
81
|
+
dependencies = [
|
|
82
|
+
"autocfg",
|
|
83
|
+
]
|
|
84
|
+
|
|
85
|
+
[[package]]
|
|
86
|
+
name = "myde-unix-socket"
|
|
87
|
+
version = "0.1.0"
|
|
88
|
+
dependencies = [
|
|
89
|
+
"libc",
|
|
90
|
+
"neon",
|
|
91
|
+
"nix",
|
|
92
|
+
]
|
|
93
|
+
|
|
94
|
+
[[package]]
|
|
95
|
+
name = "neon"
|
|
96
|
+
version = "1.1.1"
|
|
97
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
98
|
+
checksum = "74c1d298c79e60a3f5a1e638ace1f9c1229d2a97bd3a9e40a63b67c8efa0f1e1"
|
|
99
|
+
dependencies = [
|
|
100
|
+
"either",
|
|
101
|
+
"getrandom",
|
|
102
|
+
"libloading",
|
|
103
|
+
"linkme",
|
|
104
|
+
"neon-macros",
|
|
105
|
+
"once_cell",
|
|
106
|
+
"semver",
|
|
107
|
+
"send_wrapper",
|
|
108
|
+
"smallvec",
|
|
109
|
+
]
|
|
110
|
+
|
|
111
|
+
[[package]]
|
|
112
|
+
name = "neon-macros"
|
|
113
|
+
version = "1.1.1"
|
|
114
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
115
|
+
checksum = "c39e43767817fc963f90f400600967a2b2403602c6440685d09a6bc4e02b70b1"
|
|
116
|
+
dependencies = [
|
|
117
|
+
"proc-macro2",
|
|
118
|
+
"quote",
|
|
119
|
+
"syn",
|
|
120
|
+
]
|
|
121
|
+
|
|
122
|
+
[[package]]
|
|
123
|
+
name = "nix"
|
|
124
|
+
version = "0.27.1"
|
|
125
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
126
|
+
checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053"
|
|
127
|
+
dependencies = [
|
|
128
|
+
"bitflags",
|
|
129
|
+
"cfg-if",
|
|
130
|
+
"libc",
|
|
131
|
+
"memoffset",
|
|
132
|
+
]
|
|
133
|
+
|
|
134
|
+
[[package]]
|
|
135
|
+
name = "once_cell"
|
|
136
|
+
version = "1.21.4"
|
|
137
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
138
|
+
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
|
139
|
+
|
|
140
|
+
[[package]]
|
|
141
|
+
name = "proc-macro2"
|
|
142
|
+
version = "1.0.106"
|
|
143
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
144
|
+
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
|
|
145
|
+
dependencies = [
|
|
146
|
+
"unicode-ident",
|
|
147
|
+
]
|
|
148
|
+
|
|
149
|
+
[[package]]
|
|
150
|
+
name = "quote"
|
|
151
|
+
version = "1.0.45"
|
|
152
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
153
|
+
checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
|
|
154
|
+
dependencies = [
|
|
155
|
+
"proc-macro2",
|
|
156
|
+
]
|
|
157
|
+
|
|
158
|
+
[[package]]
|
|
159
|
+
name = "semver"
|
|
160
|
+
version = "1.0.27"
|
|
161
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
162
|
+
checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2"
|
|
163
|
+
|
|
164
|
+
[[package]]
|
|
165
|
+
name = "send_wrapper"
|
|
166
|
+
version = "0.6.0"
|
|
167
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
168
|
+
checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73"
|
|
169
|
+
|
|
170
|
+
[[package]]
|
|
171
|
+
name = "smallvec"
|
|
172
|
+
version = "1.15.1"
|
|
173
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
174
|
+
checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
|
|
175
|
+
|
|
176
|
+
[[package]]
|
|
177
|
+
name = "syn"
|
|
178
|
+
version = "2.0.117"
|
|
179
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
180
|
+
checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"
|
|
181
|
+
dependencies = [
|
|
182
|
+
"proc-macro2",
|
|
183
|
+
"quote",
|
|
184
|
+
"unicode-ident",
|
|
185
|
+
]
|
|
186
|
+
|
|
187
|
+
[[package]]
|
|
188
|
+
name = "unicode-ident"
|
|
189
|
+
version = "1.0.24"
|
|
190
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
191
|
+
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
|
192
|
+
|
|
193
|
+
[[package]]
|
|
194
|
+
name = "wasi"
|
|
195
|
+
version = "0.11.1+wasi-snapshot-preview1"
|
|
196
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
197
|
+
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
|
|
198
|
+
|
|
199
|
+
[[package]]
|
|
200
|
+
name = "windows-link"
|
|
201
|
+
version = "0.2.1"
|
|
202
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
203
|
+
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
package/Cargo.toml
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "myde-unix-socket"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
license = "ISC"
|
|
5
|
+
edition = "2024"
|
|
6
|
+
exclude = ["index.node"]
|
|
7
|
+
|
|
8
|
+
[lib]
|
|
9
|
+
crate-type = ["cdylib"]
|
|
10
|
+
|
|
11
|
+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
12
|
+
|
|
13
|
+
[dependencies]
|
|
14
|
+
neon = "1.1"
|
|
15
|
+
nix = { version = "0.27", features = ["fs", "socket", "uio", "poll"] }
|
|
16
|
+
libc = "0.2"
|
package/LICENSE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
# unix-socket
|
|
2
|
+
|
|
3
|
+
高性能的 Node.js Unix socket 库,使用 Rust (Neon) 实现,支持文件描述符传递 (SCM_RIGHTS)。
|
|
4
|
+
|
|
5
|
+
## 特性
|
|
6
|
+
|
|
7
|
+
- 🚀 **高性能** - 使用 Rust 实现,比纯 JavaScript 方案更快
|
|
8
|
+
- 📁 **文件描述符传递** - 支持通过 Unix socket 传递文件描述符 (SCM_RIGHTS)
|
|
9
|
+
- 🔄 **非阻塞 I/O** - 支持非阻塞的 accept 操作
|
|
10
|
+
- 📦 **TypeScript 支持** - 完整的类型定义
|
|
11
|
+
- 🧪 **测试覆盖** - 完整的测试用例
|
|
12
|
+
|
|
13
|
+
## 安装
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install unix-socket
|
|
17
|
+
# 或
|
|
18
|
+
pnpm add unix-socket
|
|
19
|
+
# 或
|
|
20
|
+
yarn add unix-socket
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 快速开始
|
|
24
|
+
|
|
25
|
+
### 基本用法
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { UServer, USocket } from "unix-socket";
|
|
29
|
+
|
|
30
|
+
// 创建服务器
|
|
31
|
+
const server = new UServer();
|
|
32
|
+
server.listen("/tmp/my-socket");
|
|
33
|
+
|
|
34
|
+
server.on("listening", () => {
|
|
35
|
+
console.log("Server listening");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// 创建客户端连接
|
|
39
|
+
const client = new USocket("/tmp/my-socket");
|
|
40
|
+
|
|
41
|
+
// 等待服务器接受连接
|
|
42
|
+
let serverSocket: USocket | null = null;
|
|
43
|
+
while (!serverSocket) {
|
|
44
|
+
serverSocket = server.accept();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 发送数据
|
|
48
|
+
const message = Buffer.from("Hello, Server!");
|
|
49
|
+
client.write(message);
|
|
50
|
+
|
|
51
|
+
// 读取数据
|
|
52
|
+
let data: Buffer | null = null;
|
|
53
|
+
while (!data) {
|
|
54
|
+
data = serverSocket.read(1024);
|
|
55
|
+
}
|
|
56
|
+
console.log(data.toString()); // "Hello, Server!"
|
|
57
|
+
|
|
58
|
+
// 清理
|
|
59
|
+
client.close();
|
|
60
|
+
serverSocket.close();
|
|
61
|
+
server.close();
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 文件描述符传递
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { UServer, USocket } from "unix-socket";
|
|
68
|
+
import * as fs from "fs";
|
|
69
|
+
|
|
70
|
+
// 创建服务器
|
|
71
|
+
const server = new UServer();
|
|
72
|
+
server.listen("/tmp/fd-socket");
|
|
73
|
+
|
|
74
|
+
// 创建客户端
|
|
75
|
+
const client = new USocket("/tmp/fd-socket");
|
|
76
|
+
|
|
77
|
+
// 等待服务器接受连接
|
|
78
|
+
let serverSocket: USocket | null = null;
|
|
79
|
+
while (!serverSocket) {
|
|
80
|
+
serverSocket = server.accept();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// 客户端打开文件并发送 fd
|
|
84
|
+
const fileFd = fs.openSync("/tmp/test.txt", "r");
|
|
85
|
+
const message = Buffer.from("fd-transfer");
|
|
86
|
+
client.write(message, [fileFd]);
|
|
87
|
+
|
|
88
|
+
// 服务器接收 fd
|
|
89
|
+
let result = null;
|
|
90
|
+
while (!result || result.fds.length === 0) {
|
|
91
|
+
result = serverSocket.readWithFds(1024);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// 使用接收到的 fd 读取文件
|
|
95
|
+
const receivedFd = result.fds[0];
|
|
96
|
+
const content = fs.readFileSync(receivedFd, "utf-8");
|
|
97
|
+
console.log(content);
|
|
98
|
+
|
|
99
|
+
// 清理
|
|
100
|
+
fs.closeSync(fileFd);
|
|
101
|
+
fs.closeSync(receivedFd);
|
|
102
|
+
client.close();
|
|
103
|
+
serverSocket.close();
|
|
104
|
+
server.close();
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## API
|
|
108
|
+
|
|
109
|
+
### USocket
|
|
110
|
+
|
|
111
|
+
Unix socket 客户端类。
|
|
112
|
+
|
|
113
|
+
#### 构造函数
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
new USocket(opts?: USocketOptions | string)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
- `opts.path` - 连接的 socket 路径
|
|
120
|
+
- `opts.fd` - 使用现有的文件描述符
|
|
121
|
+
|
|
122
|
+
#### 方法
|
|
123
|
+
|
|
124
|
+
##### `connect(opts: USocketOptions | string): void`
|
|
125
|
+
|
|
126
|
+
连接到 Unix socket 服务器。
|
|
127
|
+
|
|
128
|
+
##### `write(data: Buffer, fds?: number[]): number`
|
|
129
|
+
|
|
130
|
+
发送数据,可选择发送文件描述符数组。
|
|
131
|
+
|
|
132
|
+
- `data` - 要发送的数据
|
|
133
|
+
- `fds` - 要发送的文件描述符数组 (可选)
|
|
134
|
+
- 返回实际写入的字节数
|
|
135
|
+
|
|
136
|
+
##### `read(size: number): Buffer | null`
|
|
137
|
+
|
|
138
|
+
读取数据。
|
|
139
|
+
|
|
140
|
+
- `size` - 要读取的最大字节数
|
|
141
|
+
- 返回读取的数据或 null
|
|
142
|
+
|
|
143
|
+
##### `readWithFds(size: number): ReadWithFdsResult | null`
|
|
144
|
+
|
|
145
|
+
读取数据和文件描述符。
|
|
146
|
+
|
|
147
|
+
返回对象:
|
|
148
|
+
|
|
149
|
+
- `data` - 读取的数据 (Buffer | null)
|
|
150
|
+
- `fds` - 接收到的文件描述符数组
|
|
151
|
+
|
|
152
|
+
##### `shutdown(): void`
|
|
153
|
+
|
|
154
|
+
关闭 socket 连接。
|
|
155
|
+
|
|
156
|
+
##### `close(): void`
|
|
157
|
+
|
|
158
|
+
关闭并释放资源。
|
|
159
|
+
|
|
160
|
+
### UServer
|
|
161
|
+
|
|
162
|
+
Unix socket 服务器类,继承自 EventEmitter。
|
|
163
|
+
|
|
164
|
+
#### 构造函数
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
new UServer();
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
#### 方法
|
|
171
|
+
|
|
172
|
+
##### `listen(path: string, backlog?: number, cb?: () => void): void`
|
|
173
|
+
|
|
174
|
+
开始监听指定路径。
|
|
175
|
+
|
|
176
|
+
- `path` - socket 文件路径
|
|
177
|
+
- `backlog` - 连接队列长度 (默认: 16)
|
|
178
|
+
- `cb` - 监听成功回调 (可选)
|
|
179
|
+
|
|
180
|
+
##### `accept(): USocket | null`
|
|
181
|
+
|
|
182
|
+
接受新的连接。
|
|
183
|
+
|
|
184
|
+
- 返回新的 USocket 实例,如果没有连接则返回 null
|
|
185
|
+
|
|
186
|
+
##### `pause(): void`
|
|
187
|
+
|
|
188
|
+
暂停接受连接。
|
|
189
|
+
|
|
190
|
+
##### `resume(): void`
|
|
191
|
+
|
|
192
|
+
恢复接受连接。
|
|
193
|
+
|
|
194
|
+
##### `close(): void`
|
|
195
|
+
|
|
196
|
+
关闭服务器。
|
|
197
|
+
|
|
198
|
+
#### 事件
|
|
199
|
+
|
|
200
|
+
- `listening` - 服务器开始监听时触发
|
|
201
|
+
|
|
202
|
+
## 构建
|
|
203
|
+
|
|
204
|
+
### 前置要求
|
|
205
|
+
|
|
206
|
+
- Node.js >= 18
|
|
207
|
+
- Rust 和 Cargo
|
|
208
|
+
- pnpm (或 npm/yarn)
|
|
209
|
+
|
|
210
|
+
### 构建步骤
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
# 安装依赖
|
|
214
|
+
pnpm install
|
|
215
|
+
|
|
216
|
+
# 构建
|
|
217
|
+
pnpm run build
|
|
218
|
+
|
|
219
|
+
# 运行测试
|
|
220
|
+
pnpm test
|
|
221
|
+
|
|
222
|
+
# 监视模式测试
|
|
223
|
+
pnpm run test:watch
|
|
224
|
+
|
|
225
|
+
# 生成测试覆盖率报告
|
|
226
|
+
pnpm run test:coverage
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### 构建脚本
|
|
230
|
+
|
|
231
|
+
- `pnpm run build` - 完整构建 (Rust + TypeScript + 类型定义)
|
|
232
|
+
- `pnpm run build:rust` - 仅构建 Rust 原生模块
|
|
233
|
+
- `pnpm run build:ts` - 仅构建 TypeScript
|
|
234
|
+
- `pnpm run build:types` - 仅生成类型定义
|
|
235
|
+
- `pnpm test` - 运行测试
|
|
236
|
+
- `pnpm run test:rust` - 运行 Rust 测试
|
|
237
|
+
|
|
238
|
+
## 项目结构
|
|
239
|
+
|
|
240
|
+
```
|
|
241
|
+
├── src/
|
|
242
|
+
│ ├── index.ts # TypeScript 入口
|
|
243
|
+
│ ├── socket.rs # Rust 实现
|
|
244
|
+
│ └── socket.test.ts # 测试文件
|
|
245
|
+
├── dist/ # 构建输出
|
|
246
|
+
├── Cargo.toml # Rust 配置
|
|
247
|
+
├── package.json # Node.js 配置
|
|
248
|
+
├── tsconfig.json # TypeScript 配置
|
|
249
|
+
└── vite.config.ts # Vite 配置
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
## 技术栈
|
|
253
|
+
|
|
254
|
+
- **Rust** - 核心实现
|
|
255
|
+
- **Neon** - Rust 和 Node.js 的桥梁
|
|
256
|
+
- **Vite** - TypeScript 打包
|
|
257
|
+
- **Vitest** - 测试框架
|
|
258
|
+
- **nix** - Unix 系统调用
|
|
259
|
+
|
|
260
|
+
## 相关项目
|
|
261
|
+
|
|
262
|
+
- [neon](https://neon-bindings.com/) - Rust 和 Node.js 的绑定
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});let e=require(`node:events`);var t=require(`../index.node`),n=class{constructor(e){this._wrap=null,typeof e==`string`&&(e={path:e}),(e?.fd||e?.path)&&this.connect(e)}connect(e){if(this._wrap)throw Error(`connect on already connected USocket`);if(typeof e==`string`&&(e={path:e}),this._wrap=t.USocketWrap(),typeof e.fd==`number`){let n=t.USocketWrap_adopt(this._wrap,e.fd);this.fd=n>=0?n:void 0}else if(typeof e.path==`string`){let n=t.USocketWrap_connect(this._wrap,e.path);this.fd=n>=0?n:void 0}}write(e,n){if(!this._wrap)throw Error(`USocket not connected`);return t.USocketWrap_write(this._wrap,e,n)}read(e){return this._wrap?t.USocketWrap_read(this._wrap,e):null}readWithFds(e){return this._wrap?t.USocketWrap_read_with_fds(this._wrap,e):null}shutdown(){this._wrap&&t.USocketWrap_shutdown(this._wrap)}close(){this._wrap&&=(t.USocketWrap_close(this._wrap),null)}},r=class extends e.EventEmitter{constructor(){super(),this.listening=!1,this.paused=!1,this._wrap=null}listen(e,n,r){if(this._wrap||this.listening)throw Error(`listen on already listened UServer`);if(typeof e==`object`?(n=e.backlog,e=e.path,r=n):typeof n==`function`&&(r=n,n=0),n||=16,typeof e!=`string`)throw Error(`UServer expects valid path`);typeof r==`function`&&this.once(`listening`,r),this._wrap=t.UServerWrap();let i=t.UServerWrap_listen(this._wrap,e,n);this.fd=i>=0?i:void 0,this.listening=!0,this.emit(`listening`),this.paused||this.resume()}accept(){if(!this._wrap)return null;let e=t.UServerWrap_accept(this._wrap);return e===null?null:new n({fd:e})}pause(){this.paused=!0}resume(){this.paused=!1}close(){this._wrap&&=(t.UServerWrap_close(this._wrap),null)}},i={USocket:n,UServer:r};exports.UServer=r,exports.USocket=n,exports.default=i;
|