Skip to content

Commit 99017b0

Browse files
DarraghClarkeAlekseiEfimov
authored andcommitted
8293064: Remove unused NET_xxx functions
Reviewed-by: chegar, djelinski, aefimov, vtewari
1 parent 3419363 commit 99017b0

File tree

8 files changed

+6
-873
lines changed

8 files changed

+6
-873
lines changed

src/java.base/aix/native/libnet/aix_close.c

+1-171
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2016, 2019 SAP SE and/or its affiliates. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -295,96 +295,6 @@ static inline void endOp
295295
errno = orig_errno;
296296
}
297297

298-
/*
299-
* Close or dup2 a file descriptor ensuring that all threads blocked on
300-
* the file descriptor are notified via a wakeup signal.
301-
*
302-
* fd1 < 0 => close(fd2)
303-
* fd1 >= 0 => dup2(fd1, fd2)
304-
*
305-
* Returns -1 with errno set if operation fails.
306-
*/
307-
static int closefd(int fd1, int fd2) {
308-
int rv, orig_errno;
309-
fdEntry_t *fdEntry = getFdEntry(fd2);
310-
if (fdEntry == NULL) {
311-
errno = EBADF;
312-
return -1;
313-
}
314-
315-
/*
316-
* Lock the fd to hold-off additional I/O on this fd.
317-
*/
318-
pthread_mutex_lock(&(fdEntry->lock));
319-
320-
{
321-
/* On fast machines we see that we enter dup2 before the
322-
* accepting thread had a chance to get and process the signal.
323-
* So in case we woke a thread up, give it some time to cope.
324-
* Also see https://bugs.openjdk.java.net/browse/JDK-8006395 */
325-
int num_woken = 0;
326-
327-
/*
328-
* Send a wakeup signal to all threads blocked on this
329-
* file descriptor.
330-
*/
331-
threadEntry_t *curr = fdEntry->threads;
332-
while (curr != NULL) {
333-
curr->intr = 1;
334-
pthread_kill( curr->thr, sigWakeup );
335-
num_woken ++;
336-
curr = curr->next;
337-
}
338-
339-
if (num_woken > 0) {
340-
usleep(num_woken * 50);
341-
}
342-
343-
/*
344-
* And close/dup the file descriptor
345-
* (restart if interrupted by signal)
346-
*/
347-
do {
348-
if (fd1 < 0) {
349-
rv = close(fd2);
350-
} else {
351-
rv = dup2(fd1, fd2);
352-
}
353-
} while (rv == -1 && errno == EINTR);
354-
}
355-
356-
/*
357-
* Unlock without destroying errno
358-
*/
359-
orig_errno = errno;
360-
pthread_mutex_unlock(&(fdEntry->lock));
361-
errno = orig_errno;
362-
363-
return rv;
364-
}
365-
366-
/*
367-
* Wrapper for dup2 - same semantics as dup2 system call except
368-
* that any threads blocked in an I/O system call on fd2 will be
369-
* preempted and return -1/EBADF;
370-
*/
371-
int NET_Dup2(int fd, int fd2) {
372-
if (fd < 0) {
373-
errno = EBADF;
374-
return -1;
375-
}
376-
return closefd(fd, fd2);
377-
}
378-
379-
/*
380-
* Wrapper for close - same semantics as close system call
381-
* except that any threads blocked in an I/O on fd will be
382-
* preempted and the I/O system call will return -1/EBADF.
383-
*/
384-
int NET_SocketClose(int fd) {
385-
return closefd(-1, fd);
386-
}
387-
388298
/************** Basic I/O operations here ***************/
389299

390300
/*
@@ -408,31 +318,6 @@ int NET_SocketClose(int fd) {
408318
return ret; \
409319
}
410320

411-
int NET_Read(int s, void* buf, size_t len) {
412-
BLOCKING_IO_RETURN_INT( s, recv(s, buf, len, 0) );
413-
}
414-
415-
int NET_NonBlockingRead(int s, void* buf, size_t len) {
416-
BLOCKING_IO_RETURN_INT(s, recv(s, buf, len, MSG_NONBLOCK));
417-
}
418-
419-
int NET_RecvFrom(int s, void *buf, int len, unsigned int flags,
420-
struct sockaddr *from, socklen_t *fromlen) {
421-
BLOCKING_IO_RETURN_INT( s, recvfrom(s, buf, len, flags, from, fromlen) );
422-
}
423-
424-
int NET_Send(int s, void *msg, int len, unsigned int flags) {
425-
BLOCKING_IO_RETURN_INT( s, send(s, msg, len, flags) );
426-
}
427-
428-
int NET_SendTo(int s, const void *msg, int len, unsigned int
429-
flags, const struct sockaddr *to, int tolen) {
430-
BLOCKING_IO_RETURN_INT( s, sendto(s, msg, len, flags, to, tolen) );
431-
}
432-
433-
int NET_Accept(int s, struct sockaddr *addr, socklen_t *addrlen) {
434-
BLOCKING_IO_RETURN_INT( s, accept(s, addr, addrlen) );
435-
}
436321

437322
int NET_Connect(int s, struct sockaddr *addr, int addrlen) {
438323
int crc = -1, prc = -1;
@@ -491,58 +376,3 @@ int NET_Connect(int s, struct sockaddr *addr, int addrlen) {
491376
int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout) {
492377
BLOCKING_IO_RETURN_INT( ufds[0].fd, poll(ufds, nfds, timeout) );
493378
}
494-
495-
/*
496-
* Wrapper for poll(s, timeout).
497-
* Auto restarts with adjusted timeout if interrupted by
498-
* signal other than our wakeup signal.
499-
*/
500-
int NET_Timeout(JNIEnv *env, int s, long timeout, jlong nanoTimeStamp) {
501-
jlong prevNanoTime = nanoTimeStamp;
502-
jlong nanoTimeout = (jlong) timeout * NET_NSEC_PER_MSEC;
503-
fdEntry_t *fdEntry = getFdEntry(s);
504-
505-
/*
506-
* Check that fd hasn't been closed.
507-
*/
508-
if (fdEntry == NULL) {
509-
errno = EBADF;
510-
return -1;
511-
}
512-
513-
for(;;) {
514-
struct pollfd pfd;
515-
int rv;
516-
threadEntry_t self;
517-
518-
/*
519-
* Poll the fd. If interrupted by our wakeup signal
520-
* errno will be set to EBADF.
521-
*/
522-
pfd.fd = s;
523-
pfd.events = POLLIN | POLLERR;
524-
525-
startOp(fdEntry, &self);
526-
rv = poll(&pfd, 1, nanoTimeout / NET_NSEC_PER_MSEC);
527-
endOp(fdEntry, &self);
528-
529-
/*
530-
* If interrupted then adjust timeout. If timeout
531-
* has expired return 0 (indicating timeout expired).
532-
*/
533-
if (rv < 0 && errno == EINTR) {
534-
if (timeout > 0) {
535-
jlong newNanoTime = JVM_NanoTime(env, 0);
536-
nanoTimeout -= newNanoTime - prevNanoTime;
537-
if (nanoTimeout < NET_NSEC_PER_MSEC) {
538-
return 0;
539-
}
540-
prevNanoTime = newNanoTime;
541-
} else {
542-
continue; // timeout is -1, so loop again.
543-
}
544-
} else {
545-
return rv;
546-
}
547-
}
548-
}

src/java.base/linux/native/libnet/linux_close.c

+1-160
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -263,85 +263,6 @@ static inline void endOp
263263
errno = orig_errno;
264264
}
265265

266-
/*
267-
* Close or dup2 a file descriptor ensuring that all threads blocked on
268-
* the file descriptor are notified via a wakeup signal.
269-
*
270-
* fd1 < 0 => close(fd2)
271-
* fd1 >= 0 => dup2(fd1, fd2)
272-
*
273-
* Returns -1 with errno set if operation fails.
274-
*/
275-
static int closefd(int fd1, int fd2) {
276-
int rv, orig_errno;
277-
fdEntry_t *fdEntry = getFdEntry(fd2);
278-
if (fdEntry == NULL) {
279-
errno = EBADF;
280-
return -1;
281-
}
282-
283-
/*
284-
* Lock the fd to hold-off additional I/O on this fd.
285-
*/
286-
pthread_mutex_lock(&(fdEntry->lock));
287-
288-
{
289-
/*
290-
* And close/dup the file descriptor
291-
* (restart if interrupted by signal)
292-
*/
293-
if (fd1 < 0) {
294-
rv = close(fd2);
295-
} else {
296-
do {
297-
rv = dup2(fd1, fd2);
298-
} while (rv == -1 && errno == EINTR);
299-
}
300-
301-
/*
302-
* Send a wakeup signal to all threads blocked on this
303-
* file descriptor.
304-
*/
305-
threadEntry_t *curr = fdEntry->threads;
306-
while (curr != NULL) {
307-
curr->intr = 1;
308-
pthread_kill( curr->thr, WAKEUP_SIGNAL);
309-
curr = curr->next;
310-
}
311-
}
312-
313-
/*
314-
* Unlock without destroying errno
315-
*/
316-
orig_errno = errno;
317-
pthread_mutex_unlock(&(fdEntry->lock));
318-
errno = orig_errno;
319-
320-
return rv;
321-
}
322-
323-
/*
324-
* Wrapper for dup2 - same semantics as dup2 system call except
325-
* that any threads blocked in an I/O system call on fd2 will be
326-
* preempted and return -1/EBADF;
327-
*/
328-
int NET_Dup2(int fd, int fd2) {
329-
if (fd < 0) {
330-
errno = EBADF;
331-
return -1;
332-
}
333-
return closefd(fd, fd2);
334-
}
335-
336-
/*
337-
* Wrapper for close - same semantics as close system call
338-
* except that any threads blocked in an I/O on fd will be
339-
* preempted and the I/O system call will return -1/EBADF.
340-
*/
341-
int NET_SocketClose(int fd) {
342-
return closefd(-1, fd);
343-
}
344-
345266
/************** Basic I/O operations here ***************/
346267

347268
/*
@@ -365,90 +286,10 @@ int NET_SocketClose(int fd) {
365286
return ret; \
366287
}
367288

368-
int NET_Read(int s, void* buf, size_t len) {
369-
BLOCKING_IO_RETURN_INT( s, recv(s, buf, len, 0) );
370-
}
371-
372-
int NET_NonBlockingRead(int s, void* buf, size_t len) {
373-
BLOCKING_IO_RETURN_INT( s, recv(s, buf, len, MSG_DONTWAIT) );
374-
}
375-
376-
int NET_RecvFrom(int s, void *buf, int len, unsigned int flags,
377-
struct sockaddr *from, socklen_t *fromlen) {
378-
BLOCKING_IO_RETURN_INT( s, recvfrom(s, buf, len, flags, from, fromlen) );
379-
}
380-
381-
int NET_Send(int s, void *msg, int len, unsigned int flags) {
382-
BLOCKING_IO_RETURN_INT( s, send(s, msg, len, flags) );
383-
}
384-
385-
int NET_SendTo(int s, const void *msg, int len, unsigned int
386-
flags, const struct sockaddr *to, int tolen) {
387-
BLOCKING_IO_RETURN_INT( s, sendto(s, msg, len, flags, to, tolen) );
388-
}
389-
390-
int NET_Accept(int s, struct sockaddr *addr, socklen_t *addrlen) {
391-
BLOCKING_IO_RETURN_INT( s, accept(s, addr, addrlen) );
392-
}
393-
394289
int NET_Connect(int s, struct sockaddr *addr, int addrlen) {
395290
BLOCKING_IO_RETURN_INT( s, connect(s, addr, addrlen) );
396291
}
397292

398293
int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout) {
399294
BLOCKING_IO_RETURN_INT( ufds[0].fd, poll(ufds, nfds, timeout) );
400295
}
401-
402-
/*
403-
* Wrapper for poll(s, timeout).
404-
* Auto restarts with adjusted timeout if interrupted by
405-
* signal other than our wakeup signal.
406-
*/
407-
int NET_Timeout(JNIEnv *env, int s, long timeout, jlong nanoTimeStamp) {
408-
jlong prevNanoTime = nanoTimeStamp;
409-
jlong nanoTimeout = (jlong)timeout * NET_NSEC_PER_MSEC;
410-
fdEntry_t *fdEntry = getFdEntry(s);
411-
412-
/*
413-
* Check that fd hasn't been closed.
414-
*/
415-
if (fdEntry == NULL) {
416-
errno = EBADF;
417-
return -1;
418-
}
419-
420-
for(;;) {
421-
struct pollfd pfd;
422-
int rv;
423-
threadEntry_t self;
424-
425-
/*
426-
* Poll the fd. If interrupted by our wakeup signal
427-
* errno will be set to EBADF.
428-
*/
429-
pfd.fd = s;
430-
pfd.events = POLLIN | POLLERR;
431-
432-
startOp(fdEntry, &self);
433-
rv = poll(&pfd, 1, nanoTimeout / NET_NSEC_PER_MSEC);
434-
endOp(fdEntry, &self);
435-
/*
436-
* If interrupted then adjust timeout. If timeout
437-
* has expired return 0 (indicating timeout expired).
438-
*/
439-
if (rv < 0 && errno == EINTR) {
440-
if (timeout > 0) {
441-
jlong newNanoTime = JVM_NanoTime(env, 0);
442-
nanoTimeout -= newNanoTime - prevNanoTime;
443-
if (nanoTimeout < NET_NSEC_PER_MSEC) {
444-
return 0;
445-
}
446-
prevNanoTime = newNanoTime;
447-
} else {
448-
continue; // timeout is -1, so loop again.
449-
}
450-
} else {
451-
return rv;
452-
}
453-
}
454-
}

0 commit comments

Comments
 (0)