jdk/src/solaris/transport/socket/socket_md.c
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 1247 b4c26443dee5
child 12047 320a714614e9
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
     2
 * Copyright (c) 1998, 2008, 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>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#ifdef __linux__
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include <pthread.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#include <sys/poll.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#include "socket_md.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#include "sysSocket.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
int
896
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
    48
dbgsysListen(int fd, int backlog) {
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
    49
    return listen(fd, backlog);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
dbgsysConnect(int fd, struct sockaddr *name, int namelen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    int rv = connect(fd, name, namelen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    if (rv < 0 && errno == EINPROGRESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        return DBG_EINPROGRESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
dbgsysFinishConnect(int fd, long timeout) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    int rv = dbgsysPoll(fd, 0, 1, timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    if (rv == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        return DBG_ETIMEOUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    if (rv > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
dbgsysAccept(int fd, struct sockaddr *name, int *namelen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    int rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        rv = accept(fd, name, namelen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        if (rv >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        if (errno != ECONNABORTED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            return rv;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
dbgsysRecvFrom(int fd, char *buf, int nBytes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                  int flags, struct sockaddr *from, int *fromlen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    return recvfrom(fd, buf, nBytes, flags, from, fromlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
dbgsysSendTo(int fd, char *buf, int len,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                int flags, struct sockaddr *to, int tolen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    return sendto(fd, buf, len, flags, to, tolen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
dbgsysRecv(int fd, char *buf, int nBytes, int flags) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    return recv(fd, buf, nBytes, flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
dbgsysSend(int fd, char *buf, int nBytes, int flags) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    return send(fd, buf, nBytes, flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
struct hostent *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
dbgsysGetHostByName(char *hostname) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    return gethostbyname(hostname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
unsigned short
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
dbgsysHostToNetworkShort(unsigned short hostshort) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    return htons(hostshort);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
dbgsysSocket(int domain, int type, int protocol) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    return socket(domain, type, protocol);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
int dbgsysSocketClose(int fd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    return close(fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
dbgsysBind(int fd, struct sockaddr *name, int namelen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    return bind(fd, name, namelen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
896
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   134
uint32_t
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
dbgsysInetAddr(const char* cp) {
896
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   136
    return (uint32_t)inet_addr(cp);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
896
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   139
uint32_t
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   140
dbgsysHostToNetworkLong(uint32_t hostlong) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    return htonl(hostlong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
unsigned short
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
dbgsysNetworkToHostShort(unsigned short netshort) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    return ntohs(netshort);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
dbgsysGetSocketName(int fd, struct sockaddr *name, int *namelen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    return getsockname(fd, name, namelen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
896
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   154
uint32_t
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   155
dbgsysNetworkToHostLong(uint32_t netlong) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    return ntohl(netlong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
dbgsysSetSocketOption(int fd, jint cmd, jboolean on, jvalue value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    if (cmd == TCP_NODELAY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        struct protoent *proto = getprotobyname("TCP");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        int tcp_level = (proto == 0 ? IPPROTO_TCP: proto->p_proto);
896
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   166
        uint32_t onl = (uint32_t)on;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        if (setsockopt(fd, tcp_level, TCP_NODELAY,
896
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   169
                       (char *)&onl, sizeof(uint32_t)) < 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                return SYS_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    } else if (cmd == SO_LINGER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        struct linger arg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        arg.l_onoff = on;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        if(on) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            arg.l_linger = (unsigned short)value.i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            if(setsockopt(fd, SOL_SOCKET, SO_LINGER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                          (char*)&arg, sizeof(arg)) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                return SYS_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            if (setsockopt(fd, SOL_SOCKET, SO_LINGER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                           (char*)&arg, sizeof(arg)) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                return SYS_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    } else if (cmd == SO_SNDBUF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        jint buflen = value.i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                       (char *)&buflen, sizeof(buflen)) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            return SYS_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    } else if (cmd == SO_REUSEADDR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        int oni = (int)on;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                       (char *)&oni, sizeof(oni)) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            return SYS_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        return SYS_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    return SYS_OK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
dbgsysConfigureBlocking(int fd, jboolean blocking) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    int flags = fcntl(fd, F_GETFL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    if ((blocking == JNI_FALSE) && !(flags & O_NONBLOCK)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    if ((blocking == JNI_TRUE) && (flags & O_NONBLOCK)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        return fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
dbgsysPoll(int fd, jboolean rd, jboolean wr, long timeout) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    struct pollfd fds[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    int rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    fds[0].fd = fd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    fds[0].events = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    if (rd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        fds[0].events |= POLLIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    if (wr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        fds[0].events |= POLLOUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    fds[0].revents = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    rv = poll(&fds[0], 1, timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    if (rv >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        rv = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        if (fds[0].revents & POLLIN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            rv |= DBG_POLLIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        if (fds[0].revents & POLLOUT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            rv |= DBG_POLLOUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
dbgsysGetLastIOError(char *buf, jint size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    char *msg = strerror(errno);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    strncpy(buf, msg, size-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    buf[size-1] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
#ifdef __solaris__
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
dbgsysTlsAlloc() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    thread_key_t tk;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    if (thr_keycreate(&tk, NULL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        perror("thr_keycreate");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        exit(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    return (int)tk;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
dbgsysTlsFree(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
   /* no-op */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
dbgsysTlsPut(int index, void *value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    thr_setspecific((thread_key_t)index, value) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
void *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
dbgsysTlsGet(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    void* r = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    thr_getspecific((thread_key_t)index, &r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
#ifdef __linux__
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
dbgsysTlsAlloc() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    pthread_key_t key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    if (pthread_key_create(&key, NULL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        perror("pthread_key_create");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        exit(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    return (int)key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
dbgsysTlsFree(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    pthread_key_delete((pthread_key_t)index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
dbgsysTlsPut(int index, void *value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    pthread_setspecific((pthread_key_t)index, value) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
void *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
dbgsysTlsGet(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    return pthread_getspecific((pthread_key_t)index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
long
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
dbgsysCurrentTimeMillis() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    struct timeval t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    gettimeofday(&t, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    return ((jlong)t.tv_sec) * 1000 + (jlong)(t.tv_usec/1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
}