You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* SeqpacketServer is used to create a SOCK_SEQPACKET server.
26
10
* Note that sockets of SOCK_SEQPACKET don't works on MacOS and currently SeqpacketServer doesn't work with `cluster` module, i.e. you can share a SeqpacketServer across different Node.js processes.
@@ -44,10 +28,16 @@ function wrapSocket(obj: EventEmitter, fd?: number) {
44
28
*/
45
29
exportclassSeqpacketServerextendsEventEmitter{
46
30
privateclosed: boolean=false;
31
+
privatewrap: SeqpacketSocketWrap;
47
32
48
33
constructor(){
49
34
super();
50
-
wrapSocket(this);
35
+
36
+
this.emit=this.emit.bind(this);
37
+
this.wrap=newSeqpacketSocketWrap(this);
38
+
// TODO currently we can't get this object in rust side
39
+
this.wrap.init(this.wrap);
40
+
51
41
this.on('_connection',this.onConnection);
52
42
this.on('_error',this.onError);
53
43
}
@@ -74,7 +64,7 @@ export class SeqpacketServer extends EventEmitter {
74
64
*/
75
65
address(): string{
76
66
this.checkClosed();
77
-
returnseqAddress(this);
67
+
returnthis.wrap.address();
78
68
}
79
69
80
70
/**
@@ -88,7 +78,7 @@ export class SeqpacketServer extends EventEmitter {
88
78
return;
89
79
}
90
80
this.closed=true;
91
-
seqClose(this);
81
+
this.wrap.close();
92
82
}
93
83
94
84
/**
@@ -98,21 +88,21 @@ export class SeqpacketServer extends EventEmitter {
98
88
*/
99
89
listen(bindpath: string,backlog: number=511){
100
90
this.checkClosed();
101
-
seqListen(this,bindpath,backlog);
91
+
this.wrap.listen(bindpath,backlog);
102
92
}
103
93
104
94
/**
105
95
* Reference the server so that it will prevent Node.js process from exiting automatically.
106
96
*/
107
97
ref(){
108
-
seqRef(this);
98
+
this.wrap.uvRefer();
109
99
}
110
100
111
101
/**
112
102
* Unreference the server so that it won't prevent Node.js process from exiting automatically.
113
103
*/
114
104
unref(){
115
-
seqUnref(this);
105
+
this.wrap.uvUnrefer();
116
106
}
117
107
}
118
108
@@ -141,6 +131,7 @@ export class SeqpacketServer extends EventEmitter {
141
131
* Emitted once the socket is fully closed.
142
132
*/
143
133
exportclassSeqpacketSocketextendsEventEmitter{
134
+
privatewrap: SeqpacketSocketWrap;
144
135
privatedestroyed: boolean=false;
145
136
privateconnectCb?: NotifyCb;
146
137
privateshutdownCb?: NotifyCb;
@@ -149,9 +140,14 @@ export class SeqpacketSocket extends EventEmitter {
149
140
150
141
constructor(fd?: number){
151
142
super();
152
-
wrapSocket(this,fd);
143
+
144
+
this.emit=this.emit.bind(this);
145
+
this.wrap=newSeqpacketSocketWrap(this,fd);
146
+
// TODO currently we can't get this object in rust side
147
+
this.wrap.init(this.wrap);
148
+
153
149
if(fd){
154
-
seqStartRecv(this);
150
+
this.wrap.startRecv();
155
151
}
156
152
this.on('_data',this.onData);
157
153
this.on('end',this.onEnd);
@@ -192,7 +188,7 @@ export class SeqpacketSocket extends EventEmitter {
192
188
};
193
189
194
190
privateonConnect=()=>{
195
-
seqStartRecv(this);
191
+
this.wrap.startRecv();
196
192
this.emit('connect');
197
193
if(this.connectCb){
198
194
this.connectCb();
@@ -222,7 +218,7 @@ export class SeqpacketSocket extends EventEmitter {
222
218
connect(serverPath: string,connectCb?: NotifyCb){
223
219
this.checkDestroyed();
224
220
this.connectCb=connectCb;
225
-
seqConnect(this,serverPath);
221
+
this.wrap.connect(serverPath);
226
222
}
227
223
228
224
/**
@@ -238,7 +234,7 @@ export class SeqpacketSocket extends EventEmitter {
238
234
length=buf.length
239
235
}
240
236
this.checkDestroyed();
241
-
seqWrite(this,buf,offset,length,cb);
237
+
this.wrap.write(buf,offset,length,cb);
242
238
}
243
239
244
240
/**
@@ -247,7 +243,7 @@ export class SeqpacketSocket extends EventEmitter {
247
243
*/
248
244
end(cb?: NotifyCb){
249
245
this.shutdownCb=cb;
250
-
seqShutdownWhenFlushed(this);
246
+
this.wrap.shutdownWhenFlushed();
251
247
}
252
248
253
249
/**
@@ -257,7 +253,7 @@ export class SeqpacketSocket extends EventEmitter {
257
253
* @returns
258
254
*/
259
255
getInternalReadBufferSize(): number{
260
-
returnseqGetNapiBufSize(this);
256
+
returnthis.wrap.getReadBufSize();
261
257
}
262
258
263
259
/**
@@ -266,21 +262,21 @@ export class SeqpacketSocket extends EventEmitter {
266
262
* @param size
267
263
*/
268
264
setInternalReadBufferSize(size: number){
269
-
seqSetNapiBufSize(this,size);
265
+
this.wrap.setReadBufSize(size);
270
266
}
271
267
272
268
/**
273
269
* Reference the socket so that it will prevent Node.js process from exiting automatically.
274
270
*/
275
271
ref(){
276
-
seqRef(this);
272
+
this.wrap.uvRefer();
277
273
}
278
274
279
275
/**
280
276
* Unreference the socket so that it won't prevent Node.js process from exiting automatically.
281
277
*/
282
278
unref(){
283
-
seqUnref(this);
279
+
this.wrap.uvUnrefer();
284
280
}
285
281
286
282
/**
@@ -291,6 +287,6 @@ export class SeqpacketSocket extends EventEmitter {
0 commit comments