Skip to content

Commit 8a5c3db

Browse files
Long YangD-D-H
authored andcommitted
8312065: Socket.connect does not timeout when profiling
Reviewed-by: phh Backport-of: 1ce12c4f33d3d6905703d95df2574f4037dfd57d
1 parent fd62363 commit 8a5c3db

File tree

7 files changed

+327
-83
lines changed

7 files changed

+327
-83
lines changed

jdk/src/aix/native/java/net/aix_close.c

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#include <errno.h>
5656

5757
#include <sys/poll.h>
58+
#include "jvm.h"
5859

5960
/*
6061
* Stack allocated by thread when doing blocking operation
@@ -376,61 +377,61 @@ int NET_SocketClose(int fd) {
376377
/************** Basic I/O operations here ***************/
377378

378379
/*
379-
* Macro to perform a blocking IO operation. Restarts
380-
* automatically if interrupted by signal (other than
381-
* our wakeup signal)
380+
* Macro to perform a blocking IO operation.
381+
* If interrupted by signal (other than our wakeup signal), and if RETRY is true,
382+
* then restarts automatically
382383
*/
383-
#define BLOCKING_IO_RETURN_INT(FD, FUNC) { \
384-
int ret; \
385-
threadEntry_t self; \
386-
fdEntry_t *fdEntry = getFdEntry(FD); \
387-
if (fdEntry == NULL) { \
388-
errno = EBADF; \
389-
return -1; \
390-
} \
391-
do { \
392-
startOp(fdEntry, &self); \
393-
ret = FUNC; \
394-
endOp(fdEntry, &self); \
395-
} while (ret == -1 && errno == EINTR); \
396-
return ret; \
384+
#define BLOCKING_IO_RETURN_INT(FD, FUNC, RETRY) { \
385+
int ret; \
386+
threadEntry_t self; \
387+
fdEntry_t *fdEntry = getFdEntry(FD); \
388+
if (fdEntry == NULL) { \
389+
errno = EBADF; \
390+
return -1; \
391+
} \
392+
do { \
393+
startOp(fdEntry, &self); \
394+
ret = FUNC; \
395+
endOp(fdEntry, &self); \
396+
} while ((RETRY) && ret == -1 && errno == EINTR); \
397+
return ret; \
397398
}
398399

399400
int NET_Read(int s, void* buf, size_t len) {
400-
BLOCKING_IO_RETURN_INT( s, recv(s, buf, len, 0) );
401+
BLOCKING_IO_RETURN_INT( s, recv(s, buf, len, 0), JNI_TRUE );
401402
}
402403

403404
int NET_NonBlockingRead(int s, void* buf, size_t len) {
404-
BLOCKING_IO_RETURN_INT(s, recv(s, buf, len, MSG_NONBLOCK));
405+
BLOCKING_IO_RETURN_INT(s, recv(s, buf, len, MSG_NONBLOCK), JNI_TRUE );
405406
}
406407

407408
int NET_ReadV(int s, const struct iovec * vector, int count) {
408-
BLOCKING_IO_RETURN_INT( s, readv(s, vector, count) );
409+
BLOCKING_IO_RETURN_INT( s, readv(s, vector, count), JNI_TRUE );
409410
}
410411

411412
int NET_RecvFrom(int s, void *buf, int len, unsigned int flags,
412413
struct sockaddr *from, int *fromlen) {
413414
socklen_t socklen = *fromlen;
414-
BLOCKING_IO_RETURN_INT( s, recvfrom(s, buf, len, flags, from, &socklen) );
415+
BLOCKING_IO_RETURN_INT( s, recvfrom(s, buf, len, flags, from, &socklen), JNI_TRUE );
415416
*fromlen = socklen;
416417
}
417418

418419
int NET_Send(int s, void *msg, int len, unsigned int flags) {
419-
BLOCKING_IO_RETURN_INT( s, send(s, msg, len, flags) );
420+
BLOCKING_IO_RETURN_INT( s, send(s, msg, len, flags), JNI_TRUE );
420421
}
421422

422423
int NET_WriteV(int s, const struct iovec * vector, int count) {
423-
BLOCKING_IO_RETURN_INT( s, writev(s, vector, count) );
424+
BLOCKING_IO_RETURN_INT( s, writev(s, vector, count), JNI_TRUE );
424425
}
425426

426427
int NET_SendTo(int s, const void *msg, int len, unsigned int
427428
flags, const struct sockaddr *to, int tolen) {
428-
BLOCKING_IO_RETURN_INT( s, sendto(s, msg, len, flags, to, tolen) );
429+
BLOCKING_IO_RETURN_INT( s, sendto(s, msg, len, flags, to, tolen), JNI_TRUE );
429430
}
430431

431432
int NET_Accept(int s, struct sockaddr *addr, int *addrlen) {
432433
socklen_t socklen = *addrlen;
433-
BLOCKING_IO_RETURN_INT( s, accept(s, addr, &socklen) );
434+
BLOCKING_IO_RETURN_INT( s, accept(s, addr, &socklen), JNI_TRUE );
434435
*addrlen = socklen;
435436
}
436437

@@ -490,13 +491,13 @@ int NET_Connect(int s, struct sockaddr *addr, int addrlen) {
490491

491492
#ifndef USE_SELECT
492493
int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout) {
493-
BLOCKING_IO_RETURN_INT( ufds[0].fd, poll(ufds, nfds, timeout) );
494+
BLOCKING_IO_RETURN_INT( ufds[0].fd, poll(ufds, nfds, timeout), JNI_FALSE );
494495
}
495496
#else
496497
int NET_Select(int s, fd_set *readfds, fd_set *writefds,
497498
fd_set *exceptfds, struct timeval *timeout) {
498499
BLOCKING_IO_RETURN_INT( s-1,
499-
select(s, readfds, writefds, exceptfds, timeout) );
500+
select(s, readfds, writefds, exceptfds, timeout), JNI_TRUE );
500501
}
501502
#endif
502503

jdk/src/solaris/native/java/net/bsd_close.c

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <unistd.h>
4040
#include <errno.h>
4141
#include <sys/poll.h>
42+
#include "jvm.h"
4243

4344
/*
4445
* Stack allocated by thread when doing blocking operation
@@ -347,78 +348,78 @@ int NET_SocketClose(int fd) {
347348
/************** Basic I/O operations here ***************/
348349

349350
/*
350-
* Macro to perform a blocking IO operation. Restarts
351-
* automatically if interrupted by signal (other than
352-
* our wakeup signal)
351+
* Macro to perform a blocking IO operation.
352+
* If interrupted by signal (other than our wakeup signal), and if RETRY is true,
353+
* then restarts automatically
353354
*/
354-
#define BLOCKING_IO_RETURN_INT(FD, FUNC) { \
355-
int ret; \
356-
threadEntry_t self; \
357-
fdEntry_t *fdEntry = getFdEntry(FD); \
358-
if (fdEntry == NULL) { \
359-
errno = EBADF; \
360-
return -1; \
361-
} \
362-
do { \
363-
startOp(fdEntry, &self); \
364-
ret = FUNC; \
365-
endOp(fdEntry, &self); \
366-
} while (ret == -1 && errno == EINTR); \
367-
return ret; \
355+
#define BLOCKING_IO_RETURN_INT(FD, FUNC, RETRY) { \
356+
int ret; \
357+
threadEntry_t self; \
358+
fdEntry_t *fdEntry = getFdEntry(FD); \
359+
if (fdEntry == NULL) { \
360+
errno = EBADF; \
361+
return -1; \
362+
} \
363+
do { \
364+
startOp(fdEntry, &self); \
365+
ret = FUNC; \
366+
endOp(fdEntry, &self); \
367+
} while ((RETRY) && ret == -1 && errno == EINTR); \
368+
return ret; \
368369
}
369370

370371
int NET_Read(int s, void* buf, size_t len) {
371-
BLOCKING_IO_RETURN_INT( s, recv(s, buf, len, 0) );
372+
BLOCKING_IO_RETURN_INT( s, recv(s, buf, len, 0), JNI_TRUE );
372373
}
373374

374375
int NET_NonBlockingRead(int s, void* buf, size_t len) {
375-
BLOCKING_IO_RETURN_INT( s, recv(s, buf, len, MSG_DONTWAIT));
376+
BLOCKING_IO_RETURN_INT( s, recv(s, buf, len, MSG_DONTWAIT), JNI_TRUE );
376377
}
377378

378379
int NET_ReadV(int s, const struct iovec * vector, int count) {
379-
BLOCKING_IO_RETURN_INT( s, readv(s, vector, count) );
380+
BLOCKING_IO_RETURN_INT( s, readv(s, vector, count), JNI_TRUE );
380381
}
381382

382383
int NET_RecvFrom(int s, void *buf, int len, unsigned int flags,
383384
struct sockaddr *from, int *fromlen) {
384385
/* casting int *fromlen -> socklen_t* Both are ints */
385-
BLOCKING_IO_RETURN_INT( s, recvfrom(s, buf, len, flags, from, (socklen_t *)fromlen) );
386+
BLOCKING_IO_RETURN_INT( s, recvfrom(s, buf, len, flags, from, (socklen_t *)fromlen), JNI_TRUE );
386387
}
387388

388389
int NET_Send(int s, void *msg, int len, unsigned int flags) {
389-
BLOCKING_IO_RETURN_INT( s, send(s, msg, len, flags) );
390+
BLOCKING_IO_RETURN_INT( s, send(s, msg, len, flags), JNI_TRUE );
390391
}
391392

392393
int NET_WriteV(int s, const struct iovec * vector, int count) {
393-
BLOCKING_IO_RETURN_INT( s, writev(s, vector, count) );
394+
BLOCKING_IO_RETURN_INT( s, writev(s, vector, count), JNI_TRUE );
394395
}
395396

396397
int NET_SendTo(int s, const void *msg, int len, unsigned int
397398
flags, const struct sockaddr *to, int tolen) {
398-
BLOCKING_IO_RETURN_INT( s, sendto(s, msg, len, flags, to, tolen) );
399+
BLOCKING_IO_RETURN_INT( s, sendto(s, msg, len, flags, to, tolen), JNI_TRUE );
399400
}
400401

401402
int NET_Accept(int s, struct sockaddr *addr, int *addrlen) {
402403
socklen_t len = *addrlen;
403404
int error = accept(s, addr, &len);
404405
if (error != -1)
405406
*addrlen = (int)len;
406-
BLOCKING_IO_RETURN_INT( s, error );
407+
BLOCKING_IO_RETURN_INT( s, error, JNI_FALSE );
407408
}
408409

409410
int NET_Connect(int s, struct sockaddr *addr, int addrlen) {
410-
BLOCKING_IO_RETURN_INT( s, connect(s, addr, addrlen) );
411+
BLOCKING_IO_RETURN_INT( s, connect(s, addr, addrlen), JNI_TRUE );
411412
}
412413

413414
#ifndef USE_SELECT
414415
int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout) {
415-
BLOCKING_IO_RETURN_INT( ufds[0].fd, poll(ufds, nfds, timeout) );
416+
BLOCKING_IO_RETURN_INT( ufds[0].fd, poll(ufds, nfds, timeout), JNI_FALSE );
416417
}
417418
#else
418419
int NET_Select(int s, fd_set *readfds, fd_set *writefds,
419420
fd_set *exceptfds, struct timeval *timeout) {
420421
BLOCKING_IO_RETURN_INT( s-1,
421-
select(s, readfds, writefds, exceptfds, timeout) );
422+
select(s, readfds, writefds, exceptfds, timeout), JNI_TRUE );
422423
}
423424
#endif
424425

jdk/src/solaris/native/java/net/linux_close.c

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <unistd.h>
3838
#include <errno.h>
3939
#include <sys/poll.h>
40+
#include "jvm.h"
4041

4142
/*
4243
* Stack allocated by thread when doing blocking operation
@@ -343,77 +344,77 @@ int NET_SocketClose(int fd) {
343344
/************** Basic I/O operations here ***************/
344345

345346
/*
346-
* Macro to perform a blocking IO operation. Restarts
347-
* automatically if interrupted by signal (other than
348-
* our wakeup signal)
347+
* Macro to perform a blocking IO operation.
348+
* If interrupted by signal (other than our wakeup signal), and if RETRY is true,
349+
* then restarts automatically
349350
*/
350-
#define BLOCKING_IO_RETURN_INT(FD, FUNC) { \
351-
int ret; \
352-
threadEntry_t self; \
353-
fdEntry_t *fdEntry = getFdEntry(FD); \
354-
if (fdEntry == NULL) { \
355-
errno = EBADF; \
356-
return -1; \
357-
} \
358-
do { \
359-
startOp(fdEntry, &self); \
360-
ret = FUNC; \
361-
endOp(fdEntry, &self); \
362-
} while (ret == -1 && errno == EINTR); \
363-
return ret; \
351+
#define BLOCKING_IO_RETURN_INT(FD, FUNC, RETRY) { \
352+
int ret; \
353+
threadEntry_t self; \
354+
fdEntry_t *fdEntry = getFdEntry(FD); \
355+
if (fdEntry == NULL) { \
356+
errno = EBADF; \
357+
return -1; \
358+
} \
359+
do { \
360+
startOp(fdEntry, &self); \
361+
ret = FUNC; \
362+
endOp(fdEntry, &self); \
363+
} while ((RETRY) && ret == -1 && errno == EINTR); \
364+
return ret; \
364365
}
365366

366367
int NET_Read(int s, void* buf, size_t len) {
367-
BLOCKING_IO_RETURN_INT( s, recv(s, buf, len, 0) );
368+
BLOCKING_IO_RETURN_INT( s, recv(s, buf, len, 0), JNI_TRUE );
368369
}
369370

370371
int NET_NonBlockingRead(int s, void* buf, size_t len) {
371-
BLOCKING_IO_RETURN_INT( s, recv(s, buf, len, MSG_DONTWAIT) );
372+
BLOCKING_IO_RETURN_INT( s, recv(s, buf, len, MSG_DONTWAIT), JNI_TRUE );
372373
}
373374

374375
int NET_ReadV(int s, const struct iovec * vector, int count) {
375-
BLOCKING_IO_RETURN_INT( s, readv(s, vector, count) );
376+
BLOCKING_IO_RETURN_INT( s, readv(s, vector, count), JNI_TRUE );
376377
}
377378

378379
int NET_RecvFrom(int s, void *buf, int len, unsigned int flags,
379380
struct sockaddr *from, int *fromlen) {
380381
socklen_t socklen = *fromlen;
381-
BLOCKING_IO_RETURN_INT( s, recvfrom(s, buf, len, flags, from, &socklen) );
382+
BLOCKING_IO_RETURN_INT( s, recvfrom(s, buf, len, flags, from, &socklen), JNI_TRUE );
382383
*fromlen = socklen;
383384
}
384385

385386
int NET_Send(int s, void *msg, int len, unsigned int flags) {
386-
BLOCKING_IO_RETURN_INT( s, send(s, msg, len, flags) );
387+
BLOCKING_IO_RETURN_INT( s, send(s, msg, len, flags), JNI_TRUE );
387388
}
388389

389390
int NET_WriteV(int s, const struct iovec * vector, int count) {
390-
BLOCKING_IO_RETURN_INT( s, writev(s, vector, count) );
391+
BLOCKING_IO_RETURN_INT( s, writev(s, vector, count), JNI_TRUE );
391392
}
392393

393394
int NET_SendTo(int s, const void *msg, int len, unsigned int
394395
flags, const struct sockaddr *to, int tolen) {
395-
BLOCKING_IO_RETURN_INT( s, sendto(s, msg, len, flags, to, tolen) );
396+
BLOCKING_IO_RETURN_INT( s, sendto(s, msg, len, flags, to, tolen), JNI_TRUE );
396397
}
397398

398399
int NET_Accept(int s, struct sockaddr *addr, int *addrlen) {
399400
socklen_t socklen = *addrlen;
400-
BLOCKING_IO_RETURN_INT( s, accept(s, addr, &socklen) );
401+
BLOCKING_IO_RETURN_INT( s, accept(s, addr, &socklen), JNI_TRUE );
401402
*addrlen = socklen;
402403
}
403404

404405
int NET_Connect(int s, struct sockaddr *addr, int addrlen) {
405-
BLOCKING_IO_RETURN_INT( s, connect(s, addr, addrlen) );
406+
BLOCKING_IO_RETURN_INT( s, connect(s, addr, addrlen), JNI_TRUE );
406407
}
407408

408409
#ifndef USE_SELECT
409410
int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout) {
410-
BLOCKING_IO_RETURN_INT( ufds[0].fd, poll(ufds, nfds, timeout) );
411+
BLOCKING_IO_RETURN_INT( ufds[0].fd, poll(ufds, nfds, timeout), JNI_FALSE );
411412
}
412413
#else
413414
int NET_Select(int s, fd_set *readfds, fd_set *writefds,
414415
fd_set *exceptfds, struct timeval *timeout) {
415416
BLOCKING_IO_RETURN_INT( s-1,
416-
select(s, readfds, writefds, exceptfds, timeout) );
417+
select(s, readfds, writefds, exceptfds, timeout), JNI_TRUE );
417418
}
418419
#endif
419420

0 commit comments

Comments
 (0)