< prev index next >

src/jdk.jdwp.agent/unix/native/libdt_socket/socket_md.c

Print this page
rev 59104 : imported patch serviceability


  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include <stdlib.h>
  27 #include <sys/types.h>
  28 #include <sys/socket.h>
  29 #include <netinet/in.h>
  30 #include <arpa/inet.h>
  31 #include <unistd.h>
  32 #include <fcntl.h>
  33 #include <errno.h>
  34 #include <string.h>
  35 #include <sys/time.h>
  36 #ifdef __solaris__
  37 #include <thread.h>
  38 #else
  39 #include <pthread.h>
  40 #include <poll.h>
  41 #endif
  42 
  43 #include "socket_md.h"
  44 #include "sysSocket.h"
  45 
  46 int
  47 dbgsysListen(int fd, int backlog) {
  48     return listen(fd, backlog);
  49 }
  50 
  51 int
  52 dbgsysConnect(int fd, struct sockaddr *name, socklen_t namelen) {
  53     int rv = connect(fd, name, namelen);
  54     if (rv < 0 && (errno == EINPROGRESS || errno == EINTR)) {
  55         return DBG_EINPROGRESS;
  56     } else {
  57         return rv;
  58     }
  59 }
  60 
  61 int


 260     if (rv >= 0) {
 261         rv = 0;
 262         if (fds[0].revents & POLLIN) {
 263             rv |= DBG_POLLIN;
 264         }
 265         if (fds[0].revents & POLLOUT) {
 266             rv |= DBG_POLLOUT;
 267         }
 268     }
 269     return rv;
 270 }
 271 
 272 int
 273 dbgsysGetLastIOError(char *buf, jint size) {
 274     char *msg = strerror(errno);
 275     strncpy(buf, msg, size-1);
 276     buf[size-1] = '\0';
 277     return 0;
 278 }
 279 
 280 #ifdef __solaris__
 281 int
 282 dbgsysTlsAlloc() {
 283     thread_key_t tk;
 284     if (thr_keycreate(&tk, NULL)) {
 285         perror("thr_keycreate");
 286         exit(-1);
 287     }
 288     return (int)tk;
 289 }
 290 
 291 void
 292 dbgsysTlsFree(int index) {
 293    /* no-op */
 294 }
 295 
 296 void
 297 dbgsysTlsPut(int index, void *value) {
 298     thr_setspecific((thread_key_t)index, value) ;
 299 }
 300 
 301 void *
 302 dbgsysTlsGet(int index) {
 303     void* r = NULL;
 304     thr_getspecific((thread_key_t)index, &r);
 305     return r;
 306 }
 307 
 308 #else
 309 int
 310 dbgsysTlsAlloc() {
 311     pthread_key_t key;
 312     if (pthread_key_create(&key, NULL)) {
 313         perror("pthread_key_create");
 314         exit(-1);
 315     }
 316     return (int)key;
 317 }
 318 
 319 void
 320 dbgsysTlsFree(int index) {
 321     pthread_key_delete((pthread_key_t)index);
 322 }
 323 
 324 void
 325 dbgsysTlsPut(int index, void *value) {
 326     pthread_setspecific((pthread_key_t)index, value) ;
 327 }
 328 
 329 void *
 330 dbgsysTlsGet(int index) {
 331     return pthread_getspecific((pthread_key_t)index);
 332 }
 333 
 334 #endif
 335 
 336 long
 337 dbgsysCurrentTimeMillis() {
 338     struct timeval t;
 339     gettimeofday(&t, 0);
 340     return ((jlong)t.tv_sec) * 1000 + (jlong)(t.tv_usec/1000);
 341 }


  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include <stdlib.h>
  27 #include <sys/types.h>
  28 #include <sys/socket.h>
  29 #include <netinet/in.h>
  30 #include <arpa/inet.h>
  31 #include <unistd.h>
  32 #include <fcntl.h>
  33 #include <errno.h>
  34 #include <string.h>
  35 #include <sys/time.h>



  36 #include <pthread.h>
  37 #include <poll.h>

  38 
  39 #include "socket_md.h"
  40 #include "sysSocket.h"
  41 
  42 int
  43 dbgsysListen(int fd, int backlog) {
  44     return listen(fd, backlog);
  45 }
  46 
  47 int
  48 dbgsysConnect(int fd, struct sockaddr *name, socklen_t namelen) {
  49     int rv = connect(fd, name, namelen);
  50     if (rv < 0 && (errno == EINPROGRESS || errno == EINTR)) {
  51         return DBG_EINPROGRESS;
  52     } else {
  53         return rv;
  54     }
  55 }
  56 
  57 int


 256     if (rv >= 0) {
 257         rv = 0;
 258         if (fds[0].revents & POLLIN) {
 259             rv |= DBG_POLLIN;
 260         }
 261         if (fds[0].revents & POLLOUT) {
 262             rv |= DBG_POLLOUT;
 263         }
 264     }
 265     return rv;
 266 }
 267 
 268 int
 269 dbgsysGetLastIOError(char *buf, jint size) {
 270     char *msg = strerror(errno);
 271     strncpy(buf, msg, size-1);
 272     buf[size-1] = '\0';
 273     return 0;
 274 }
 275 





























 276 int
 277 dbgsysTlsAlloc() {
 278     pthread_key_t key;
 279     if (pthread_key_create(&key, NULL)) {
 280         perror("pthread_key_create");
 281         exit(-1);
 282     }
 283     return (int)key;
 284 }
 285 
 286 void
 287 dbgsysTlsFree(int index) {
 288     pthread_key_delete((pthread_key_t)index);
 289 }
 290 
 291 void
 292 dbgsysTlsPut(int index, void *value) {
 293     pthread_setspecific((pthread_key_t)index, value) ;
 294 }
 295 
 296 void *
 297 dbgsysTlsGet(int index) {
 298     return pthread_getspecific((pthread_key_t)index);
 299 }


 300 
 301 long
 302 dbgsysCurrentTimeMillis() {
 303     struct timeval t;
 304     gettimeofday(&t, 0);
 305     return ((jlong)t.tv_sec) * 1000 + (jlong)(t.tv_usec/1000);
 306 }
< prev index next >