@@ -39,6 +39,8 @@ static const uv_buf_t uv_null_buf_ = { 0, NULL };
39
39
/* when the local ends wants to shut it down. */
40
40
static const int64_t eof_timeout = 50 ; /* ms */
41
41
42
+ static const int default_pending_pipe_instances = 4 ;
43
+
42
44
/* IPC protocol flags. */
43
45
#define UV_IPC_RAW_DATA 0x0001
44
46
#define UV_IPC_UV_STREAM 0x0002
@@ -293,6 +295,12 @@ void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle) {
293
295
}
294
296
}
295
297
298
+ if (handle -> flags & UV_HANDLE_PIPESERVER ) {
299
+ assert (handle -> accept_reqs );
300
+ free (handle -> accept_reqs );
301
+ handle -> accept_reqs = NULL ;
302
+ }
303
+
296
304
/* Remember the state of this flag because the close callback is */
297
305
/* allowed to clobber or free the handle's memory */
298
306
uv_alloced = handle -> flags & UV_HANDLE_UV_ALLOCED ;
@@ -310,6 +318,12 @@ void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle) {
310
318
}
311
319
312
320
321
+ void uv_pipe_pending_instances (uv_pipe_t * handle , int count ) {
322
+ handle -> pending_instances = count ;
323
+ handle -> flags |= UV_HANDLE_PIPESERVER ;
324
+ }
325
+
326
+
313
327
/* Creates a pipe server. */
314
328
int uv_pipe_bind (uv_pipe_t * handle , const char * name ) {
315
329
uv_loop_t * loop = handle -> loop ;
@@ -326,7 +340,17 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
326
340
return -1 ;
327
341
}
328
342
329
- for (i = 0 ; i < COUNTOF (handle -> accept_reqs ); i ++ ) {
343
+ if (!(handle -> flags & UV_HANDLE_PIPESERVER )) {
344
+ handle -> pending_instances = default_pending_pipe_instances ;
345
+ }
346
+
347
+ handle -> accept_reqs = (uv_pipe_accept_t * )
348
+ malloc (sizeof (uv_pipe_accept_t ) * handle -> pending_instances );
349
+ if (!handle -> accept_reqs ) {
350
+ uv_fatal_error (ERROR_OUTOFMEMORY , "malloc" );
351
+ }
352
+
353
+ for (i = 0 ; i < handle -> pending_instances ; i ++ ) {
330
354
req = & handle -> accept_reqs [i ];
331
355
uv_req_init (loop , (uv_req_t * ) req );
332
356
req -> type = UV_ACCEPT ;
@@ -537,14 +561,13 @@ void close_pipe(uv_pipe_t* handle, int* status, uv_err_t* err) {
537
561
}
538
562
539
563
if (handle -> flags & UV_HANDLE_PIPESERVER ) {
540
- for (i = 0 ; i < COUNTOF ( handle -> accept_reqs ) ; i ++ ) {
564
+ for (i = 0 ; i < handle -> pending_instances ; i ++ ) {
541
565
pipeHandle = handle -> accept_reqs [i ].pipeHandle ;
542
566
if (pipeHandle != INVALID_HANDLE_VALUE ) {
543
567
CloseHandle (pipeHandle );
544
568
handle -> accept_reqs [i ].pipeHandle = INVALID_HANDLE_VALUE ;
545
569
}
546
570
}
547
-
548
571
}
549
572
550
573
if (handle -> flags & UV_HANDLE_CONNECTION ) {
@@ -686,7 +709,7 @@ int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb) {
686
709
/* First pipe handle should have already been created in uv_pipe_bind */
687
710
assert (handle -> accept_reqs [0 ].pipeHandle != INVALID_HANDLE_VALUE );
688
711
689
- for (i = 0 ; i < COUNTOF ( handle -> accept_reqs ) ; i ++ ) {
712
+ for (i = 0 ; i < handle -> pending_instances ; i ++ ) {
690
713
uv_pipe_queue_accept (loop , handle , & handle -> accept_reqs [i ], i == 0 );
691
714
}
692
715
0 commit comments