src/jdk.jdwp.agent/unix/native/libdt_socket/socket_md.c
author ihse
Sat, 03 Mar 2018 08:21:47 +0100
branchihse-warnings-cflags-branch
changeset 56230 489867818774
parent 48767 0c6ce8fdb50a
permissions -rw-r--r--
No longer disable E_OLD_STYLE_FUNC_DEF.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
48767
0c6ce8fdb50a 8080990: libdt_socket/socket_md.c(202) : warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW()
gadams
parents: 47216
diff changeset
     2
 * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <sys/types.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include <sys/socket.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include <netinet/in.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include <arpa/inet.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include <unistd.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include <fcntl.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include <errno.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include <sys/time.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#ifdef __solaris__
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include <thread.h>
12291
1be435e23542 7155300: Include pthread.h on all POSIX platforms except Solaris to improve portability
zhangshj
parents: 12047
diff changeset
    38
#else
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include <pthread.h>
46862
cb4b080576fa 8180003: Remove sys/ prefix from poll.h and signal.h includes
mikael
parents: 42687
diff changeset
    40
#include <poll.h>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#include "socket_md.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#include "sysSocket.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
int
896
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
    47
dbgsysListen(int fd, int backlog) {
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
    48
    return listen(fd, backlog);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
int
15274
a77cdd5ea6e3 8005120: Compiler warnings in socket transport native code
jzavgren
parents: 14342
diff changeset
    52
dbgsysConnect(int fd, struct sockaddr *name, socklen_t namelen) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    int rv = connect(fd, name, namelen);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    54
    if (rv < 0 && (errno == EINPROGRESS || errno == EINTR)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        return DBG_EINPROGRESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
int
15274
a77cdd5ea6e3 8005120: Compiler warnings in socket transport native code
jzavgren
parents: 14342
diff changeset
    62
dbgsysFinishConnect(int fd, int timeout) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    int rv = dbgsysPoll(fd, 0, 1, timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    if (rv == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        return DBG_ETIMEOUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    if (rv > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
int
15274
a77cdd5ea6e3 8005120: Compiler warnings in socket transport native code
jzavgren
parents: 14342
diff changeset
    74
dbgsysAccept(int fd, struct sockaddr *name, socklen_t *namelen) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    int rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        rv = accept(fd, name, namelen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        if (rv >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    81
        if (errno != ECONNABORTED && errno != EINTR) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
int
15274
a77cdd5ea6e3 8005120: Compiler warnings in socket transport native code
jzavgren
parents: 14342
diff changeset
    88
dbgsysRecvFrom(int fd, char *buf, size_t nBytes,
a77cdd5ea6e3 8005120: Compiler warnings in socket transport native code
jzavgren
parents: 14342
diff changeset
    89
                  int flags, struct sockaddr *from, socklen_t *fromlen) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    90
    int rv;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    91
    do {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    92
        rv = recvfrom(fd, buf, nBytes, flags, from, fromlen);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    93
    } while (rv == -1 && errno == EINTR);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    94
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    95
    return rv;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
int
15274
a77cdd5ea6e3 8005120: Compiler warnings in socket transport native code
jzavgren
parents: 14342
diff changeset
    99
dbgsysSendTo(int fd, char *buf, size_t len,
a77cdd5ea6e3 8005120: Compiler warnings in socket transport native code
jzavgren
parents: 14342
diff changeset
   100
                int flags, struct sockaddr *to, socklen_t tolen) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   101
    int rv;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   102
    do {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   103
        rv = sendto(fd, buf, len, flags, to, tolen);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   104
    } while (rv == -1 && errno == EINTR);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   105
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   106
    return rv;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
int
15274
a77cdd5ea6e3 8005120: Compiler warnings in socket transport native code
jzavgren
parents: 14342
diff changeset
   110
dbgsysRecv(int fd, char *buf, size_t nBytes, int flags) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   111
    int rv;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   112
    do {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   113
        rv = recv(fd, buf, nBytes, flags);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   114
    } while (rv == -1 && errno == EINTR);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   115
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   116
    return rv;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
int
15274
a77cdd5ea6e3 8005120: Compiler warnings in socket transport native code
jzavgren
parents: 14342
diff changeset
   120
dbgsysSend(int fd, char *buf, size_t nBytes, int flags) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   121
    int rv;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   122
    do {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   123
        rv = send(fd, buf, nBytes, flags);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   124
    } while (rv == -1 && errno == EINTR);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   125
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   126
    return rv;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
48767
0c6ce8fdb50a 8080990: libdt_socket/socket_md.c(202) : warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW()
gadams
parents: 47216
diff changeset
   129
int
0c6ce8fdb50a 8080990: libdt_socket/socket_md.c(202) : warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW()
gadams
parents: 47216
diff changeset
   130
dbgsysGetAddrInfo(char *hostname, char *service,
0c6ce8fdb50a 8080990: libdt_socket/socket_md.c(202) : warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW()
gadams
parents: 47216
diff changeset
   131
                  struct addrinfo *hints,
0c6ce8fdb50a 8080990: libdt_socket/socket_md.c(202) : warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW()
gadams
parents: 47216
diff changeset
   132
                  struct addrinfo **results) {
0c6ce8fdb50a 8080990: libdt_socket/socket_md.c(202) : warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW()
gadams
parents: 47216
diff changeset
   133
    return getaddrinfo(hostname, service, hints, results);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
unsigned short
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
dbgsysHostToNetworkShort(unsigned short hostshort) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    return htons(hostshort);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
dbgsysSocket(int domain, int type, int protocol) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    return socket(domain, type, protocol);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
int dbgsysSocketClose(int fd) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   147
    int rv;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   148
    do {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   149
        rv = close(fd);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   150
    } while (rv == -1 && errno == EINTR);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   151
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   152
    return rv;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
int
15274
a77cdd5ea6e3 8005120: Compiler warnings in socket transport native code
jzavgren
parents: 14342
diff changeset
   156
dbgsysBind(int fd, struct sockaddr *name, socklen_t namelen) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    return bind(fd, name, namelen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
896
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   160
uint32_t
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
dbgsysInetAddr(const char* cp) {
896
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   162
    return (uint32_t)inet_addr(cp);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
896
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   165
uint32_t
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   166
dbgsysHostToNetworkLong(uint32_t hostlong) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    return htonl(hostlong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
unsigned short
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
dbgsysNetworkToHostShort(unsigned short netshort) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    return ntohs(netshort);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
int
15274
a77cdd5ea6e3 8005120: Compiler warnings in socket transport native code
jzavgren
parents: 14342
diff changeset
   176
dbgsysGetSocketName(int fd, struct sockaddr *name, socklen_t *namelen) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    return getsockname(fd, name, namelen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
896
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   180
uint32_t
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   181
dbgsysNetworkToHostLong(uint32_t netlong) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    return ntohl(netlong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
dbgsysSetSocketOption(int fd, jint cmd, jboolean on, jvalue value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    if (cmd == TCP_NODELAY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        struct protoent *proto = getprotobyname("TCP");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        int tcp_level = (proto == 0 ? IPPROTO_TCP: proto->p_proto);
896
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   192
        uint32_t onl = (uint32_t)on;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        if (setsockopt(fd, tcp_level, TCP_NODELAY,
896
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   195
                       (char *)&onl, sizeof(uint32_t)) < 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                return SYS_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    } else if (cmd == SO_LINGER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        struct linger arg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        arg.l_onoff = on;
42687
7a5929518e6a 8170663: Fix minor issues in corelib and servicabilty coding.
goetz
parents: 25859
diff changeset
   201
        arg.l_linger = (on) ? (unsigned short)value.i : 0;
7a5929518e6a 8170663: Fix minor issues in corelib and servicabilty coding.
goetz
parents: 25859
diff changeset
   202
        if (setsockopt(fd, SOL_SOCKET, SO_LINGER,
7a5929518e6a 8170663: Fix minor issues in corelib and servicabilty coding.
goetz
parents: 25859
diff changeset
   203
                       (char*)&arg, sizeof(arg)) < 0) {
7a5929518e6a 8170663: Fix minor issues in corelib and servicabilty coding.
goetz
parents: 25859
diff changeset
   204
          return SYS_ERR;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    } else if (cmd == SO_SNDBUF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        jint buflen = value.i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                       (char *)&buflen, sizeof(buflen)) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            return SYS_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    } else if (cmd == SO_REUSEADDR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        int oni = (int)on;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                       (char *)&oni, sizeof(oni)) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            return SYS_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        return SYS_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    return SYS_OK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
dbgsysConfigureBlocking(int fd, jboolean blocking) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    int flags = fcntl(fd, F_GETFL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    if ((blocking == JNI_FALSE) && !(flags & O_NONBLOCK)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    if ((blocking == JNI_TRUE) && (flags & O_NONBLOCK)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        return fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
dbgsysPoll(int fd, jboolean rd, jboolean wr, long timeout) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    struct pollfd fds[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    int rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    fds[0].fd = fd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    fds[0].events = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    if (rd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        fds[0].events |= POLLIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    if (wr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        fds[0].events |= POLLOUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    fds[0].revents = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    rv = poll(&fds[0], 1, timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    if (rv >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        rv = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        if (fds[0].revents & POLLIN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            rv |= DBG_POLLIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        if (fds[0].revents & POLLOUT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            rv |= DBG_POLLOUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
dbgsysGetLastIOError(char *buf, jint size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    char *msg = strerror(errno);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    strncpy(buf, msg, size-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    buf[size-1] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
#ifdef __solaris__
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
int
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 48767
diff changeset
   276
dbgsysTlsAlloc(void) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    thread_key_t tk;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    if (thr_keycreate(&tk, NULL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        perror("thr_keycreate");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        exit(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    return (int)tk;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
dbgsysTlsFree(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
   /* no-op */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
dbgsysTlsPut(int index, void *value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    thr_setspecific((thread_key_t)index, value) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
void *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
dbgsysTlsGet(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    void* r = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    thr_getspecific((thread_key_t)index, &r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
12291
1be435e23542 7155300: Include pthread.h on all POSIX platforms except Solaris to improve portability
zhangshj
parents: 12047
diff changeset
   302
#else
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
dbgsysTlsAlloc() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    pthread_key_t key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    if (pthread_key_create(&key, NULL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        perror("pthread_key_create");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        exit(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    return (int)key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
dbgsysTlsFree(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    pthread_key_delete((pthread_key_t)index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
dbgsysTlsPut(int index, void *value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    pthread_setspecific((pthread_key_t)index, value) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
void *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
dbgsysTlsGet(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    return pthread_getspecific((pthread_key_t)index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
long
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 48767
diff changeset
   331
dbgsysCurrentTimeMillis(void) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    struct timeval t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    gettimeofday(&t, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    return ((jlong)t.tv_sec) * 1000 + (jlong)(t.tv_usec/1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
}