8217500: (sc) Move SocketChannelImpl's remaining native methods to Net

Reviewed-by: bpb
This commit is contained in:
Alan Bateman 2019-01-23 13:16:16 +00:00
parent a4ec99239c
commit 779991a9c8
10 changed files with 150 additions and 293 deletions

View file

@ -524,11 +524,28 @@ public class Net {
static native int poll(FileDescriptor fd, int events, long timeout)
throws IOException;
/**
* Polls a connecting socket to test if the connection has been established.
*
* @apiNote This method is public to allow it be used by code in jdk.sctp.
*
* @param timeout the timeout to wait; 0 to not wait, -1 to wait indefinitely
* @return 1 if connected, 0 if not connected, or IOS_INTERRUPTED
*/
public static native int pollConnect(FileDescriptor fd, long timeout)
throws IOException;
/**
* Return the number of bytes in the socket input buffer.
*/
static native int available(FileDescriptor fd) throws IOException;
/**
* Send one byte of urgent data (MSG_OOB) on the socket.
*/
static native int sendOOB(FileDescriptor fd, byte data) throws IOException;
// -- Multicast support --
/**

View file

@ -65,7 +65,7 @@ class SocketChannelImpl
implements SelChImpl
{
// Used to make native read and write calls
private static NativeDispatcher nd;
private static final NativeDispatcher nd = new SocketDispatcher();
// Our file descriptor object
private final FileDescriptor fd;
@ -517,10 +517,10 @@ class SocketChannelImpl
beginWrite(blocking);
if (blocking) {
do {
n = sendOutOfBandData(fd, b);
n = Net.sendOOB(fd, b);
} while (n == IOStatus.INTERRUPTED && isOpen());
} else {
n = sendOutOfBandData(fd, b);
n = Net.sendOOB(fd, b);
}
} finally {
endWrite(blocking, n > 0);
@ -772,10 +772,10 @@ class SocketChannelImpl
int n = 0;
if (blocking) {
do {
n = checkConnect(fd, true);
n = Net.pollConnect(fd, -1);
} while ((n == 0 || n == IOStatus.INTERRUPTED) && isOpen());
} else {
n = checkConnect(fd, false);
n = Net.pollConnect(fd, 0);
}
connected = (n > 0);
} finally {
@ -1112,19 +1112,4 @@ class SocketChannelImpl
sb.append(']');
return sb.toString();
}
// -- Native methods --
private static native int checkConnect(FileDescriptor fd, boolean block)
throws IOException;
private static native int sendOutOfBandData(FileDescriptor fd, byte data)
throws IOException;
static {
IOUtil.load();
nd = new SocketDispatcher();
}
}