Refine search
@Override public void close() throws IOException { channel.close(); inputShutdown = true; outputShutdown = true; }
channel = UnixSocketChannel.open( unixAddress ); channel.configureBlocking(false); selectorManager.accept(channel, context); x = new SocketException("Could not connect to " + address).initCause(x); channel.close();
protected void init_unixsock(Ruby runtime, IRubyObject _path, boolean server) { ByteList path = _path.convertToString().getByteList(); String fpath = Helpers.decodeByteList(runtime, path); int maxSize = 103; // Max size from Darwin, lowest common value we know of if (fpath.length() > 103) { throw runtime.newArgumentError("too long unix socket path (max: " + maxSize + "bytes)"); } try { if (server) { UnixServerSocketChannel channel = UnixServerSocketChannel.open(); UnixServerSocket socket = channel.socket(); // TODO: listen backlog socket.bind(new UnixSocketAddress(new File(fpath))); init_sock(runtime, channel, fpath); } else { File fpathFile = new File(fpath); if (!fpathFile.exists()) { throw runtime.newErrnoENOENTError("unix socket"); } UnixSocketChannel channel = UnixSocketChannel.open(); channel.connect(new UnixSocketAddress(fpathFile)); init_sock(runtime, channel); } } catch (IOException ioe) { throw runtime.newIOErrorFromException(ioe); } }
UnixSocket() throws IOException { channel = UnixSocketChannel.open(); }
protected ChannelDescriptor initChannel(Ruby runtime) { Channel channel; try { if(soType == Sock.SOCK_STREAM) { if (soProtocol == ProtocolFamily.PF_UNIX || soProtocol == ProtocolFamily.PF_LOCAL) { channel = UnixSocketChannel.open(); } else if (soProtocol == ProtocolFamily.PF_INET || soProtocol == ProtocolFamily.PF_INET6 || soProtocol == ProtocolFamily.PF_UNSPEC) { channel = SocketChannel.open(); } else { throw runtime.newArgumentError("unsupported protocol family `" + soProtocol + "'"); } } else if(soType == Sock.SOCK_DGRAM) { channel = DatagramChannel.open(); } else { throw runtime.newArgumentError("unsupported socket type `" + soType + "'"); } return newChannelDescriptor(runtime, channel); } catch(IOException e) { throw SocketUtils.sockerr(runtime, "initialize: " + e.toString()); } }
result = ((UnixSocketChannel) channel).connect((UnixSocketAddress) addr); throw runtime.newErrnoENOPROTOOPTError(); if (!ex) return runtime.newSymbol("wait_writable"); throw runtime.newErrnoEINPROGRESSWritableError();
if (runtime.is1_9()) { throw runtime.newErrnoEINPROGRESSWritableError(); } else { throw runtime.newErrnoEINPROGRESSError(); ((UnixSocketChannel)channel).connect((UnixSocketAddress)addr);
public static void main(String[] args) throws IOException { java.io.File path = new java.io.File("/tmp/fubar.sock"); String data = "blah blah"; UnixSocketAddress address = new UnixSocketAddress(path); UnixSocketChannel channel = UnixSocketChannel.open(address); System.out.println("connected to " + channel.getRemoteSocketAddress()); PrintWriter w = new PrintWriter(Channels.newOutputStream(channel)); w.print(data); w.flush(); InputStreamReader r = new InputStreamReader(Channels.newInputStream(channel)); CharBuffer result = CharBuffer.allocate(1024); r.read(result); result.flip(); System.out.println("read from server: " + result.toString()); if (!result.toString().equals(data)) { System.out.println("ERROR: data mismatch"); } else { System.out.println("SUCCESS"); } } }
@Override public void shutdownOutput() throws IOException { channel.shutdownOutput(); outputShutdown = true; }
public static final UnixSocketChannel open(UnixSocketAddress remote) throws IOException { UnixSocketChannel channel = new UnixSocketChannel(); try { channel.connect(remote); } catch (IOException e) { channel.close(); throw e; } return channel; }
@Override public void shutdownInput() throws IOException { channel.shutdownInput(); inputShutdown = true; }
public final UnixSocketAddress getLocalSocketAddress() { if (localAddress != null) { return localAddress; } else { localAddress = Common.getsockname(getFD()); return localAddress; } }
@Override public void connect(SocketAddress endpoint, int timeout) throws IOException { if (timeout < 0) { throw new IllegalArgumentException("Timeout may not be negative: " + timeout); } if (!(endpoint instanceof UnixSocketAddress)) { throw new IllegalArgumentException("Unsupported address type: " + endpoint.getClass().getName()); } synchronized (connectLock) { channel.connect((UnixSocketAddress) endpoint); } }
public void process(SelectionKey key) { try { ByteBuffer buf = ByteBuffer.allocate(1024); int result = sessionChannel.read(buf); if (result > 0) { buf.flip(); messageReceived(new Buffer(buf.array(), buf.position(), buf.remaining())); return; } if (result == -1) { // EOF => remote closed the connection, cancel the selection key and close the channel. key.cancel(); sessionChannel.close(); } } catch (IOException e) { LOGGER.log(Level.INFO, "Could not write response to socket", e); key.cancel(); safelyClose(sessionChannel); } }
public static final UnixSocketChannel open(UnixSocketAddress remote) throws IOException { UnixSocketChannel channel = new UnixSocketChannel(); channel.connect(remote); return channel; }
@Override public <T> T getOption(SocketOption<T> name) throws IOException { if (!supportedOptions().contains(name)) { throw new UnsupportedOperationException("'" + name + "' not supported"); } return Common.getSocketOption(getFD(), name); }