equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved. |
3 * Copyright (c) 2016, SAP SE and/or its affiliates. All rights reserved. |
3 * Copyright (c) 2016, 2017, SAP SE and/or its affiliates. All rights reserved. |
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5 * |
5 * |
6 * This code is free software; you can redistribute it and/or modify it |
6 * This code is free software; you can redistribute it and/or modify it |
7 * under the terms of the GNU General Public License version 2 only, as |
7 * under the terms of the GNU General Public License version 2 only, as |
8 * published by the Free Software Foundation. Oracle designates this |
8 * published by the Free Software Foundation. Oracle designates this |
63 #include <sys/resource.h> |
63 #include <sys/resource.h> |
64 #include <sys/uio.h> |
64 #include <sys/uio.h> |
65 #include <unistd.h> |
65 #include <unistd.h> |
66 #include <errno.h> |
66 #include <errno.h> |
67 #include <sys/poll.h> |
67 #include <sys/poll.h> |
|
68 #include "jvm.h" |
|
69 #include "net_util.h" |
68 |
70 |
69 /* |
71 /* |
70 * Stack allocated by thread when doing blocking operation |
72 * Stack allocated by thread when doing blocking operation |
71 */ |
73 */ |
72 typedef struct threadEntry { |
74 typedef struct threadEntry { |
505 /* |
507 /* |
506 * Wrapper for poll(s, timeout). |
508 * Wrapper for poll(s, timeout). |
507 * Auto restarts with adjusted timeout if interrupted by |
509 * Auto restarts with adjusted timeout if interrupted by |
508 * signal other than our wakeup signal. |
510 * signal other than our wakeup signal. |
509 */ |
511 */ |
510 int NET_Timeout0(int s, long timeout, long currentTime) { |
512 int NET_Timeout(JNIEnv *env, int s, long timeout, jlong nanoTimeStamp) { |
511 long prevtime = currentTime, newtime; |
513 jlong prevNanoTime = nanoTimeStamp; |
512 struct timeval t; |
514 jlong nanoTimeout = (jlong) timeout * NET_NSEC_PER_MSEC; |
513 fdEntry_t *fdEntry = getFdEntry(s); |
515 fdEntry_t *fdEntry = getFdEntry(s); |
514 |
516 |
515 /* |
517 /* |
516 * Check that fd hasn't been closed. |
518 * Check that fd hasn't been closed. |
517 */ |
519 */ |
531 */ |
533 */ |
532 pfd.fd = s; |
534 pfd.fd = s; |
533 pfd.events = POLLIN | POLLERR; |
535 pfd.events = POLLIN | POLLERR; |
534 |
536 |
535 startOp(fdEntry, &self); |
537 startOp(fdEntry, &self); |
536 rv = poll(&pfd, 1, timeout); |
538 rv = poll(&pfd, 1, nanoTimeout / NET_NSEC_PER_MSEC); |
537 endOp(fdEntry, &self); |
539 endOp(fdEntry, &self); |
538 |
540 |
539 /* |
541 /* |
540 * If interrupted then adjust timeout. If timeout |
542 * If interrupted then adjust timeout. If timeout |
541 * has expired return 0 (indicating timeout expired). |
543 * has expired return 0 (indicating timeout expired). |
542 */ |
544 */ |
543 if (rv < 0 && errno == EINTR) { |
545 if (rv < 0 && errno == EINTR) { |
544 if (timeout > 0) { |
546 jlong newNanoTime = JVM_NanoTime(env, 0); |
545 gettimeofday(&t, NULL); |
547 nanoTimeout -= newNanoTime - prevNanoTime; |
546 newtime = t.tv_sec * 1000 + t.tv_usec / 1000; |
548 if (nanoTimeout < NET_NSEC_PER_MSEC) { |
547 timeout -= newtime - prevtime; |
549 return 0; |
548 if (timeout <= 0) { |
|
549 return 0; |
|
550 } |
|
551 prevtime = newtime; |
|
552 } |
550 } |
|
551 prevNanoTime = newNanoTime; |
553 } else { |
552 } else { |
554 return rv; |
553 return rv; |
555 } |
554 } |
556 |
555 } |
557 } |
556 } |
558 } |
|