use of java.net.InetSocketAddress in project j2objc by google.
the class PlainDatagramSocketImpl method joinGroup.
@Override
public void joinGroup(SocketAddress addr, NetworkInterface netInterface) throws IOException {
if (addr instanceof InetSocketAddress) {
InetAddress groupAddr = ((InetSocketAddress) addr).getAddress();
setOption(NetworkBridge.JAVA_MCAST_JOIN_GROUP, makeGroupReq(groupAddr, netInterface));
}
}
use of java.net.InetSocketAddress in project j2objc by google.
the class PlainSocketImpl method accept.
@Override
protected void accept(SocketImpl newImpl) throws IOException {
if (usingSocks()) {
((PlainSocketImpl) newImpl).socksBind();
((PlainSocketImpl) newImpl).socksAccept();
return;
}
try {
InetSocketAddress peerAddress = new InetSocketAddress();
FileDescriptor clientFd = NetworkOs.accept(fd, peerAddress);
// TODO: we can't just set newImpl.fd to clientFd because a nio SocketChannel may
// be sharing the FileDescriptor. http://b//4452981.
newImpl.fd.setInt$(clientFd.getInt$());
newImpl.address = peerAddress.getAddress();
newImpl.port = peerAddress.getPort();
} catch (ErrnoException errnoException) {
if (errnoException.errno == EAGAIN) {
throw new SocketTimeoutException(errnoException);
}
throw new SocketException(errnoException.getMessage(), errnoException);
}
// Reset the client's inherited read timeout to the Java-specified default of 0.
newImpl.setOption(SocketOptions.SO_TIMEOUT, Integer.valueOf(0));
newImpl.localport = NetworkBridge.getSocketLocalPort(newImpl.fd);
}
use of java.net.InetSocketAddress in project j2objc by google.
the class PlainSocketImpl method socksGetServerAddress.
/**
* Gets the InetAddress of the SOCKS proxy server.
*/
private InetAddress socksGetServerAddress() throws UnknownHostException {
String proxyName;
// get socks server address from proxy. It is unnecessary to check
// "socksProxyHost" property, since all proxy setting should be
// determined by ProxySelector.
InetSocketAddress addr = (InetSocketAddress) proxy.address();
proxyName = addr.getHostName();
if (proxyName == null) {
proxyName = addr.getAddress().getHostAddress();
}
return InetAddress.getByName(proxyName);
}
use of java.net.InetSocketAddress in project j2objc by google.
the class DatagramChannelImpl method send.
@Override
public int send(ByteBuffer source, SocketAddress socketAddress) throws IOException {
checkNotNull(source);
checkOpen();
InetSocketAddress isa = (InetSocketAddress) socketAddress;
if (isa.getAddress() == null) {
throw new IOException();
}
if (isConnected() && !connectAddress.equals(isa)) {
throw new IllegalArgumentException("Connected to " + connectAddress + ", not " + socketAddress);
}
synchronized (writeLock) {
int sendCount = 0;
try {
begin();
int oldPosition = source.position();
sendCount = NetworkBridge.sendto(fd, source, 0, isa.getAddress(), isa.getPort());
if (sendCount > 0) {
source.position(oldPosition + sendCount);
}
if (!isBound) {
onBind(true);
}
} finally {
end(sendCount >= 0);
}
return sendCount;
}
}
use of java.net.InetSocketAddress in project j2objc by google.
the class DatagramChannelImpl method onBind.
/**
* Initialise the isBound, localAddress and localPort state from the file descriptor. Used when
* some or all of the bound state has been left to the OS to decide, or when the Socket handled
* bind() or connect().
*
* @param updateSocketState
* if the associated socket (if present) needs to be updated
* @hide used to sync state, non-private to avoid synthetic method
*/
void onBind(boolean updateSocketState) {
SocketAddress sa;
try {
sa = NetworkOs.getsockname(fd);
} catch (ErrnoException errnoException) {
throw new AssertionError(errnoException);
}
isBound = true;
InetSocketAddress localSocketAddress = (InetSocketAddress) sa;
localAddress = localSocketAddress.getAddress();
localPort = localSocketAddress.getPort();
if (updateSocketState && socket != null) {
socket.onBind(localAddress, localPort);
}
}
Aggregations