@@ -262,7 +262,6 @@ int st_netfd_poll(_st_netfd_t *fd, int how, st_utime_t timeout)
262
262
}
263
263
264
264
265
- #ifdef MD_ALWAYS_UNSERIALIZED_ACCEPT
266
265
/* No-op */
267
266
int st_netfd_serialize_accept (_st_netfd_t * fd )
268
267
{
@@ -310,112 +309,6 @@ _st_netfd_t *st_accept(_st_netfd_t *fd, struct sockaddr *addr, int *addrlen, st_
310
309
return newfd ;
311
310
}
312
311
313
- #else /* MD_ALWAYS_UNSERIALIZED_ACCEPT */
314
- /*
315
- * On some platforms accept() calls from different processes
316
- * on the same listen socket must be serialized.
317
- * The following code serializes accept()'s without process blocking.
318
- * A pipe is used as an inter-process semaphore.
319
- */
320
- int st_netfd_serialize_accept (_st_netfd_t * fd )
321
- {
322
- _st_netfd_t * * p ;
323
- int osfd [2 ], err ;
324
-
325
- if (fd -> aux_data ) {
326
- errno = EINVAL ;
327
- return -1 ;
328
- }
329
- if ((p = (_st_netfd_t * * )calloc (2 , sizeof (_st_netfd_t * ))) == NULL )
330
- return -1 ;
331
- if (pipe (osfd ) < 0 ) {
332
- free (p );
333
- return -1 ;
334
- }
335
- if ((p [0 ] = st_netfd_open (osfd [0 ])) != NULL && (p [1 ] = st_netfd_open (osfd [1 ])) != NULL && write (osfd [1 ], " " , 1 ) == 1 ) {
336
- fd -> aux_data = p ;
337
- return 0 ;
338
- }
339
- /* Error */
340
- err = errno ;
341
- if (p [0 ])
342
- st_netfd_free (p [0 ]);
343
- if (p [1 ])
344
- st_netfd_free (p [1 ]);
345
- close (osfd [0 ]);
346
- close (osfd [1 ]);
347
- free (p );
348
- errno = err ;
349
-
350
- return -1 ;
351
- }
352
-
353
- static void _st_netfd_free_aux_data (_st_netfd_t * fd )
354
- {
355
- _st_netfd_t * * p = (_st_netfd_t * * ) fd -> aux_data ;
356
-
357
- st_netfd_close (p [0 ]);
358
- st_netfd_close (p [1 ]);
359
- free (p );
360
- fd -> aux_data = NULL ;
361
- }
362
-
363
- _st_netfd_t * st_accept (_st_netfd_t * fd , struct sockaddr * addr , int * addrlen , st_utime_t timeout )
364
- {
365
- int osfd , err ;
366
- _st_netfd_t * newfd ;
367
- _st_netfd_t * * p = (_st_netfd_t * * ) fd -> aux_data ;
368
- ssize_t n ;
369
- char c ;
370
-
371
- for ( ; ; ) {
372
- if (p == NULL ) {
373
- osfd = accept (fd -> osfd , addr , (socklen_t * )addrlen );
374
- } else {
375
- /* Get the lock */
376
- n = st_read (p [0 ], & c , 1 , timeout );
377
- if (n < 0 )
378
- return NULL ;
379
- ST_ASSERT (n == 1 );
380
- /* Got the lock */
381
- osfd = accept (fd -> osfd , addr , (socklen_t * )addrlen );
382
- /* Unlock */
383
- err = errno ;
384
- n = st_write (p [1 ], & c , 1 , timeout );
385
- ST_ASSERT (n == 1 );
386
- errno = err ;
387
- }
388
- if (osfd >= 0 )
389
- break ;
390
- if (errno == EINTR )
391
- continue ;
392
- if (!_IO_NOT_READY_ERROR )
393
- return NULL ;
394
- /* Wait until the socket becomes readable */
395
- if (st_netfd_poll (fd , POLLIN , timeout ) < 0 )
396
- return NULL ;
397
- }
398
-
399
- /* On some platforms the new socket created by accept() inherits */
400
- /* the nonblocking attribute of the listening socket */
401
- #if defined (MD_ACCEPT_NB_INHERITED )
402
- newfd = _st_netfd_new (osfd , 0 , 1 );
403
- #elif defined (MD_ACCEPT_NB_NOT_INHERITED )
404
- newfd = _st_netfd_new (osfd , 1 , 1 );
405
- #else
406
- #error Unknown OS
407
- #endif
408
-
409
- if (!newfd ) {
410
- err = errno ;
411
- close (osfd );
412
- errno = err ;
413
- }
414
-
415
- return newfd ;
416
- }
417
- #endif /* MD_ALWAYS_UNSERIALIZED_ACCEPT */
418
-
419
312
420
313
int st_connect (_st_netfd_t * fd , const struct sockaddr * addr , int addrlen , st_utime_t timeout )
421
314
{
0 commit comments