use of java.net.InetAddress in project j2objc by google.
the class SocketChannelImpl method finishConnect.
@Override
public boolean finishConnect() throws IOException {
synchronized (this) {
if (!isOpen()) {
throw new ClosedChannelException();
}
if (status == SOCKET_STATUS_CONNECTED) {
return true;
}
if (status != SOCKET_STATUS_PENDING) {
throw new NoConnectionPendingException();
}
}
boolean finished = false;
try {
begin();
InetAddress inetAddress = connectAddress.getAddress();
int port = connectAddress.getPort();
// Return immediately.
finished = NetworkBridge.isConnected(fd, inetAddress, port, 0, 0);
} catch (ConnectException e) {
if (isOpen()) {
close();
finished = true;
}
throw e;
} finally {
end(finished);
}
synchronized (this) {
status = (finished ? SOCKET_STATUS_CONNECTED : status);
if (finished && socket != null) {
socket.onConnect(connectAddress.getAddress(), connectAddress.getPort());
}
}
return finished;
}
use of java.net.InetAddress in project j2objc by google.
the class PlainDatagramSocketImpl method send.
@Override
public void send(DatagramPacket packet) throws IOException {
int port = isNativeConnected ? 0 : packet.getPort();
InetAddress address = isNativeConnected ? null : packet.getAddress();
NetworkBridge.sendto(fd, packet.getData(), packet.getOffset(), packet.getLength(), 0, address, port);
}
use of java.net.InetAddress 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.InetAddress in project j2objc by google.
the class PlainSocketImpl method connect.
/**
* Connects this socket to the specified remote host address/port.
*
* @param anAddr
* the remote host address to connect to
* @param aPort
* the remote port to connect to
* @param timeout
* a timeout where supported. 0 means no timeout
* @throws IOException
* if an error occurs while connecting
*/
private void connect(InetAddress anAddr, int aPort, int timeout) throws IOException {
InetAddress normalAddr = anAddr.isAnyLocalAddress() ? InetAddress.getLocalHost() : anAddr;
if (streaming && usingSocks()) {
socksConnect(anAddr, aPort, 0);
} else {
NetworkBridge.connect(fd, normalAddr, aPort, timeout);
}
super.address = normalAddr;
super.port = aPort;
}
use of java.net.InetAddress in project j2objc by google.
the class DatagramChannelImpl method connect.
@Override
public synchronized DatagramChannel connect(SocketAddress address) throws IOException {
// must be open
checkOpen();
// status must be un-connected.
if (connected) {
throw new IllegalStateException();
}
// check the address
InetSocketAddress inetSocketAddress = SocketChannelImpl.validateAddress(address);
InetAddress remoteAddress = inetSocketAddress.getAddress();
int remotePort = inetSocketAddress.getPort();
try {
begin();
NetworkBridge.connect(fd, remoteAddress, remotePort);
} catch (ConnectException e) {
// ConnectException means connect fail, not exception
} finally {
end(true);
}
// address state held by the channel and the socket up to date.
if (!isBound) {
onBind(true);
}
// Keep the connected state held by the channel and the socket up to date.
onConnect(remoteAddress, remotePort, true);
return this;
}
Aggregations