1
1
/*
2
- * Copyright (c) 2001, 2020 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2001, 2022 , Oracle and/or its affiliates. All rights reserved.
3
3
* Copyright (c) 2016, 2019 SAP SE and/or its affiliates. All rights reserved.
4
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
5
*
@@ -295,96 +295,6 @@ static inline void endOp
295
295
errno = orig_errno ;
296
296
}
297
297
298
- /*
299
- * Close or dup2 a file descriptor ensuring that all threads blocked on
300
- * the file descriptor are notified via a wakeup signal.
301
- *
302
- * fd1 < 0 => close(fd2)
303
- * fd1 >= 0 => dup2(fd1, fd2)
304
- *
305
- * Returns -1 with errno set if operation fails.
306
- */
307
- static int closefd (int fd1 , int fd2 ) {
308
- int rv , orig_errno ;
309
- fdEntry_t * fdEntry = getFdEntry (fd2 );
310
- if (fdEntry == NULL ) {
311
- errno = EBADF ;
312
- return -1 ;
313
- }
314
-
315
- /*
316
- * Lock the fd to hold-off additional I/O on this fd.
317
- */
318
- pthread_mutex_lock (& (fdEntry -> lock ));
319
-
320
- {
321
- /* On fast machines we see that we enter dup2 before the
322
- * accepting thread had a chance to get and process the signal.
323
- * So in case we woke a thread up, give it some time to cope.
324
- * Also see https://bugs.openjdk.java.net/browse/JDK-8006395 */
325
- int num_woken = 0 ;
326
-
327
- /*
328
- * Send a wakeup signal to all threads blocked on this
329
- * file descriptor.
330
- */
331
- threadEntry_t * curr = fdEntry -> threads ;
332
- while (curr != NULL ) {
333
- curr -> intr = 1 ;
334
- pthread_kill ( curr -> thr , sigWakeup );
335
- num_woken ++ ;
336
- curr = curr -> next ;
337
- }
338
-
339
- if (num_woken > 0 ) {
340
- usleep (num_woken * 50 );
341
- }
342
-
343
- /*
344
- * And close/dup the file descriptor
345
- * (restart if interrupted by signal)
346
- */
347
- do {
348
- if (fd1 < 0 ) {
349
- rv = close (fd2 );
350
- } else {
351
- rv = dup2 (fd1 , fd2 );
352
- }
353
- } while (rv == -1 && errno == EINTR );
354
- }
355
-
356
- /*
357
- * Unlock without destroying errno
358
- */
359
- orig_errno = errno ;
360
- pthread_mutex_unlock (& (fdEntry -> lock ));
361
- errno = orig_errno ;
362
-
363
- return rv ;
364
- }
365
-
366
- /*
367
- * Wrapper for dup2 - same semantics as dup2 system call except
368
- * that any threads blocked in an I/O system call on fd2 will be
369
- * preempted and return -1/EBADF;
370
- */
371
- int NET_Dup2 (int fd , int fd2 ) {
372
- if (fd < 0 ) {
373
- errno = EBADF ;
374
- return -1 ;
375
- }
376
- return closefd (fd , fd2 );
377
- }
378
-
379
- /*
380
- * Wrapper for close - same semantics as close system call
381
- * except that any threads blocked in an I/O on fd will be
382
- * preempted and the I/O system call will return -1/EBADF.
383
- */
384
- int NET_SocketClose (int fd ) {
385
- return closefd (-1 , fd );
386
- }
387
-
388
298
/************** Basic I/O operations here ***************/
389
299
390
300
/*
@@ -408,31 +318,6 @@ int NET_SocketClose(int fd) {
408
318
return ret; \
409
319
}
410
320
411
- int NET_Read (int s , void * buf , size_t len ) {
412
- BLOCKING_IO_RETURN_INT ( s , recv (s , buf , len , 0 ) );
413
- }
414
-
415
- int NET_NonBlockingRead (int s , void * buf , size_t len ) {
416
- BLOCKING_IO_RETURN_INT (s , recv (s , buf , len , MSG_NONBLOCK ));
417
- }
418
-
419
- int NET_RecvFrom (int s , void * buf , int len , unsigned int flags ,
420
- struct sockaddr * from , socklen_t * fromlen ) {
421
- BLOCKING_IO_RETURN_INT ( s , recvfrom (s , buf , len , flags , from , fromlen ) );
422
- }
423
-
424
- int NET_Send (int s , void * msg , int len , unsigned int flags ) {
425
- BLOCKING_IO_RETURN_INT ( s , send (s , msg , len , flags ) );
426
- }
427
-
428
- int NET_SendTo (int s , const void * msg , int len , unsigned int
429
- flags , const struct sockaddr * to , int tolen ) {
430
- BLOCKING_IO_RETURN_INT ( s , sendto (s , msg , len , flags , to , tolen ) );
431
- }
432
-
433
- int NET_Accept (int s , struct sockaddr * addr , socklen_t * addrlen ) {
434
- BLOCKING_IO_RETURN_INT ( s , accept (s , addr , addrlen ) );
435
- }
436
321
437
322
int NET_Connect (int s , struct sockaddr * addr , int addrlen ) {
438
323
int crc = -1 , prc = -1 ;
@@ -491,58 +376,3 @@ int NET_Connect(int s, struct sockaddr *addr, int addrlen) {
491
376
int NET_Poll (struct pollfd * ufds , unsigned int nfds , int timeout ) {
492
377
BLOCKING_IO_RETURN_INT ( ufds [0 ].fd , poll (ufds , nfds , timeout ) );
493
378
}
494
-
495
- /*
496
- * Wrapper for poll(s, timeout).
497
- * Auto restarts with adjusted timeout if interrupted by
498
- * signal other than our wakeup signal.
499
- */
500
- int NET_Timeout (JNIEnv * env , int s , long timeout , jlong nanoTimeStamp ) {
501
- jlong prevNanoTime = nanoTimeStamp ;
502
- jlong nanoTimeout = (jlong ) timeout * NET_NSEC_PER_MSEC ;
503
- fdEntry_t * fdEntry = getFdEntry (s );
504
-
505
- /*
506
- * Check that fd hasn't been closed.
507
- */
508
- if (fdEntry == NULL ) {
509
- errno = EBADF ;
510
- return -1 ;
511
- }
512
-
513
- for (;;) {
514
- struct pollfd pfd ;
515
- int rv ;
516
- threadEntry_t self ;
517
-
518
- /*
519
- * Poll the fd. If interrupted by our wakeup signal
520
- * errno will be set to EBADF.
521
- */
522
- pfd .fd = s ;
523
- pfd .events = POLLIN | POLLERR ;
524
-
525
- startOp (fdEntry , & self );
526
- rv = poll (& pfd , 1 , nanoTimeout / NET_NSEC_PER_MSEC );
527
- endOp (fdEntry , & self );
528
-
529
- /*
530
- * If interrupted then adjust timeout. If timeout
531
- * has expired return 0 (indicating timeout expired).
532
- */
533
- if (rv < 0 && errno == EINTR ) {
534
- if (timeout > 0 ) {
535
- jlong newNanoTime = JVM_NanoTime (env , 0 );
536
- nanoTimeout -= newNanoTime - prevNanoTime ;
537
- if (nanoTimeout < NET_NSEC_PER_MSEC ) {
538
- return 0 ;
539
- }
540
- prevNanoTime = newNanoTime ;
541
- } else {
542
- continue ; // timeout is -1, so loop again.
543
- }
544
- } else {
545
- return rv ;
546
- }
547
- }
548
- }
0 commit comments