src/java.base/solaris/native/libnet/solaris_close.c
author pchilanomate
Fri, 31 Aug 2018 10:22:04 -0400
changeset 51610 cdef4df6b0e7
parent 47216 71c04702a3d5
child 53741 38b6110d5db2
permissions -rw-r--r--
8206424: Use locking for cleaning ProtectionDomainTable Summary: ServiceThread is now in charge of cleaning ProtectionDomainTable entries Reviewed-by: coleenp, iklam
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23015
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
     1
/*
45061
74b09ee3cd55 8179905: Remove the use of gettimeofday in Networking code
vtewari
parents: 44921
diff changeset
     2
 * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
23015
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
     4
 *
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    10
 *
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    15
 * accompanied this code).
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    16
 *
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    20
 *
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    23
 * questions.
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    24
 */
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    25
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    26
#include <errno.h>
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    27
#include <sys/socket.h>
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    28
#include <stropts.h>
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    29
#include <unistd.h>
45061
74b09ee3cd55 8179905: Remove the use of gettimeofday in Networking code
vtewari
parents: 44921
diff changeset
    30
#include "jvm.h"
74b09ee3cd55 8179905: Remove the use of gettimeofday in Networking code
vtewari
parents: 44921
diff changeset
    31
#include "net_util.h"
23015
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    32
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    33
/* Support for restartable system calls on Solaris. */
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    34
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    35
#define RESTARTABLE_RETURN_INT(_cmd) do {             \
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    36
    int _result;                                      \
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    37
    if (1) {                                          \
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    38
        do {                                          \
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    39
            _result = _cmd;                           \
40937
f72e61ec734b 8075484: SocketInputStream.socketRead0 can hang even with soTimeout set
vtewari
parents: 28658
diff changeset
    40
        } while((_result == -1) && (errno == EINTR));      \
23015
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    41
        return _result;                               \
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    42
    }                                                 \
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    43
} while(0)
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    44
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    45
int NET_Read(int s, void* buf, size_t len) {
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    46
    RESTARTABLE_RETURN_INT(recv(s, buf, len, 0));
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    47
}
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    48
40937
f72e61ec734b 8075484: SocketInputStream.socketRead0 can hang even with soTimeout set
vtewari
parents: 28658
diff changeset
    49
int NET_NonBlockingRead(int s, void* buf, size_t len) {
f72e61ec734b 8075484: SocketInputStream.socketRead0 can hang even with soTimeout set
vtewari
parents: 28658
diff changeset
    50
    RESTARTABLE_RETURN_INT(recv(s, buf, len, MSG_DONTWAIT));
f72e61ec734b 8075484: SocketInputStream.socketRead0 can hang even with soTimeout set
vtewari
parents: 28658
diff changeset
    51
}
f72e61ec734b 8075484: SocketInputStream.socketRead0 can hang even with soTimeout set
vtewari
parents: 28658
diff changeset
    52
23015
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    53
int NET_RecvFrom(int s, void *buf, int len, unsigned int flags,
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    54
                 struct sockaddr *from, socklen_t *fromlen) {
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    55
    RESTARTABLE_RETURN_INT(recvfrom(s, buf, len, flags, from, fromlen));
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    56
}
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    57
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    58
int NET_ReadV(int s, const struct iovec * vector, int count) {
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    59
    RESTARTABLE_RETURN_INT(readv(s, vector, count));
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    60
}
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    61
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    62
int NET_WriteV(int s, const struct iovec * vector, int count) {
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    63
    RESTARTABLE_RETURN_INT(writev(s, vector, count));
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    64
}
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    65
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    66
int NET_Send(int s, void *msg, int len, unsigned int flags) {
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    67
    RESTARTABLE_RETURN_INT(send(s, msg, len, flags));
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    68
}
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    69
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    70
int NET_SendTo(int s, const void *msg, int len,  unsigned  int flags,
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    71
               const struct sockaddr *to, int tolen) {
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    72
    RESTARTABLE_RETURN_INT(sendto(s, msg, len, flags, to, tolen));
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    73
}
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    74
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    75
int NET_Connect(int s, struct sockaddr *addr, int addrlen) {
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    76
    RESTARTABLE_RETURN_INT(connect(s, addr, addrlen));
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    77
}
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    78
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    79
int NET_Accept(int s, struct sockaddr *addr, socklen_t *addrlen) {
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    80
    RESTARTABLE_RETURN_INT(accept(s, addr, addrlen));
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    81
}
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    82
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    83
int NET_SocketClose(int fd) {
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    84
    return close(fd);
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    85
}
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    86
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    87
int NET_Dup2(int fd, int fd2) {
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    88
    return dup2(fd, fd2);
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    89
}
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    90
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    91
int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout) {
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    92
    RESTARTABLE_RETURN_INT(poll(ufds, nfds, timeout));
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    93
}
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    94
45061
74b09ee3cd55 8179905: Remove the use of gettimeofday in Networking code
vtewari
parents: 44921
diff changeset
    95
int NET_Timeout(JNIEnv *env, int s, long timeout, jlong nanoTimeStamp) {
23015
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    96
    int result;
45061
74b09ee3cd55 8179905: Remove the use of gettimeofday in Networking code
vtewari
parents: 44921
diff changeset
    97
    jlong prevNanoTime = nanoTimeStamp;
74b09ee3cd55 8179905: Remove the use of gettimeofday in Networking code
vtewari
parents: 44921
diff changeset
    98
    jlong nanoTimeout = (jlong) timeout * NET_NSEC_PER_MSEC;
23015
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
    99
    struct pollfd pfd;
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
   100
    pfd.fd = s;
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
   101
    pfd.events = POLLIN;
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
   102
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
   103
    for(;;) {
45061
74b09ee3cd55 8179905: Remove the use of gettimeofday in Networking code
vtewari
parents: 44921
diff changeset
   104
        result = poll(&pfd, 1, nanoTimeout / NET_NSEC_PER_MSEC);
23015
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
   105
        if (result < 0 && errno == EINTR) {
45061
74b09ee3cd55 8179905: Remove the use of gettimeofday in Networking code
vtewari
parents: 44921
diff changeset
   106
            jlong newNanoTime = JVM_NanoTime(env, 0);
74b09ee3cd55 8179905: Remove the use of gettimeofday in Networking code
vtewari
parents: 44921
diff changeset
   107
            nanoTimeout -= newNanoTime - prevNanoTime;
74b09ee3cd55 8179905: Remove the use of gettimeofday in Networking code
vtewari
parents: 44921
diff changeset
   108
            if (nanoTimeout < NET_NSEC_PER_MSEC)
74b09ee3cd55 8179905: Remove the use of gettimeofday in Networking code
vtewari
parents: 44921
diff changeset
   109
                return 0;
74b09ee3cd55 8179905: Remove the use of gettimeofday in Networking code
vtewari
parents: 44921
diff changeset
   110
            prevNanoTime = newNanoTime;
23015
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
   111
        } else {
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
   112
            return result;
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
   113
        }
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
   114
    }
73b21ab36615 8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
diff changeset
   115
}