mirror of
https://github.com/corda/corda.git
synced 2025-06-17 06:38:21 +00:00
Merge branch 'dns'
This commit is contained in:
53
classpath/java/net/InetAddress.java
Normal file
53
classpath/java/net/InetAddress.java
Normal file
@ -0,0 +1,53 @@
|
||||
/* Copyright (c) 2010, Avian Contributors
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software
|
||||
for any purpose with or without fee is hereby granted, provided
|
||||
that the above copyright notice and this permission notice appear
|
||||
in all copies.
|
||||
|
||||
There is NO WARRANTY for this software. See license.txt for
|
||||
details. */
|
||||
|
||||
package java.net;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class InetAddress {
|
||||
private final String address;
|
||||
|
||||
private InetAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public String getHostAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public static InetAddress getByName(String name)
|
||||
throws UnknownHostException
|
||||
{
|
||||
try {
|
||||
Socket.init();
|
||||
} catch (IOException e) {
|
||||
UnknownHostException uhe = new UnknownHostException(name);
|
||||
uhe.initCause(e);
|
||||
throw uhe;
|
||||
}
|
||||
|
||||
int address = ipv4AddressForName(name);
|
||||
if (address == 0) {
|
||||
throw new UnknownHostException(name);
|
||||
} else {
|
||||
return new InetAddress(ipv4AddressToString(address));
|
||||
}
|
||||
}
|
||||
|
||||
private static String ipv4AddressToString(int address) {
|
||||
return (((address >>> 24) ) + "." +
|
||||
((address >>> 16) & 0xFF) + "." +
|
||||
((address >>> 8 ) & 0xFF) + "." +
|
||||
((address ) & 0xFF));
|
||||
}
|
||||
|
||||
private static native int ipv4AddressForName(String name);
|
||||
}
|
@ -10,6 +10,10 @@
|
||||
|
||||
package java.net;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class Socket {
|
||||
public static native void init() throws IOException;
|
||||
|
||||
public abstract void setTcpNoDelay(boolean on) throws SocketException;
|
||||
}
|
||||
|
21
classpath/java/net/UnknownHostException.java
Normal file
21
classpath/java/net/UnknownHostException.java
Normal file
@ -0,0 +1,21 @@
|
||||
/* Copyright (c) 2010, Avian Contributors
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software
|
||||
for any purpose with or without fee is hereby granted, provided
|
||||
that the above copyright notice and this permission notice appear
|
||||
in all copies.
|
||||
|
||||
There is NO WARRANTY for this software. See license.txt for
|
||||
details. */
|
||||
|
||||
package java.net;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class UnknownHostException extends IOException {
|
||||
public UnknownHostException(String host) {
|
||||
super(host);
|
||||
}
|
||||
|
||||
public UnknownHostException() { }
|
||||
}
|
@ -18,7 +18,7 @@ public abstract class Selector {
|
||||
protected final Set<SelectionKey> keys = new HashSet();
|
||||
protected final Set<SelectionKey> selectedKeys = new HashSet();
|
||||
|
||||
public static Selector open() {
|
||||
public static Selector open() throws IOException {
|
||||
return new SocketSelector();
|
||||
}
|
||||
|
||||
|
@ -15,11 +15,16 @@ import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
|
||||
public class ServerSocketChannel extends SelectableChannel {
|
||||
private final SocketChannel channel = new SocketChannel();
|
||||
private final SocketChannel channel;
|
||||
|
||||
public static ServerSocketChannel open() {
|
||||
private ServerSocketChannel() throws IOException {
|
||||
channel = new SocketChannel();
|
||||
}
|
||||
|
||||
public static ServerSocketChannel open() throws IOException {
|
||||
return new ServerSocketChannel();
|
||||
}
|
||||
|
||||
@ -58,6 +63,8 @@ public class ServerSocketChannel extends SelectableChannel {
|
||||
}
|
||||
|
||||
private int doListen(String host, int port) throws IOException {
|
||||
Socket.init();
|
||||
|
||||
return natDoListen(host, port);
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,9 @@ public class SocketChannel extends SelectableChannel
|
||||
boolean connected = false;
|
||||
boolean blocking = true;
|
||||
|
||||
public static SocketChannel open() {
|
||||
public static SocketChannel open() throws IOException {
|
||||
Socket.init();
|
||||
|
||||
return new SocketChannel();
|
||||
}
|
||||
|
||||
|
@ -12,13 +12,16 @@ package java.nio.channels;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.net.Socket;
|
||||
|
||||
class SocketSelector extends Selector {
|
||||
protected long state;
|
||||
protected final Object lock = new Object();
|
||||
protected boolean woken = false;
|
||||
|
||||
public SocketSelector() {
|
||||
public SocketSelector() throws IOException {
|
||||
Socket.init();
|
||||
|
||||
state = natInit();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user