IRubyObject addr = sockaddr.pop(context);
IRubyObject port = sockaddr.pop(context);
InetSocketAddress iaddr = new InetSocketAddress(
addr.convertToString().toString(), RubyNumeric.fix2int(port));
Channel socketChannel = getChannel();
if (socketChannel instanceof SocketChannel) {
if(!((SocketChannel) socketChannel).connect(iaddr)) {
throw context.getRuntime().newErrnoEINPROGRESSError();
}
} else if (socketChannel instanceof DatagramChannel) {
((DatagramChannel)socketChannel).connect(iaddr);
} else {
throw getRuntime().newErrnoENOPROTOOPTError();
}
} catch(AlreadyConnectedException e) {
throw context.getRuntime().newErrnoEISCONNError();
} catch(ConnectionPendingException e) {
Channel socketChannel = getChannel();
if (socketChannel instanceof SocketChannel) {
try {
if (((SocketChannel) socketChannel).finishConnect()) {
throw context.getRuntime().newErrnoEISCONNError();
}