use of jnr.unixsocket.UnixSocketChannel in project jetty.project by eclipse.
the class UnixSocketConnector method accept.
@Override
public void accept(int acceptorID) throws IOException {
LOG.warn("Blocking UnixSocket accept used. Cannot be interrupted!");
UnixServerSocketChannel serverChannel = _acceptChannel;
if (serverChannel != null && serverChannel.isOpen()) {
LOG.debug("accept {}", serverChannel);
UnixSocketChannel channel = serverChannel.accept();
LOG.debug("accepted {}", channel);
accepted(channel);
}
}
use of jnr.unixsocket.UnixSocketChannel in project jetty.project by eclipse.
the class UnixSocketClient method main.
public static void main(String[] args) throws Exception {
java.io.File path = new java.io.File("/tmp/jetty.sock");
String data = "GET / HTTP/1.1\r\nHost: unixsock\r\n\r\n";
UnixSocketAddress address = new UnixSocketAddress(path);
UnixSocketChannel channel = UnixSocketChannel.open(address);
System.out.println("connected to " + channel.getRemoteSocketAddress());
PrintWriter w = new PrintWriter(Channels.newOutputStream(channel));
InputStreamReader r = new InputStreamReader(Channels.newInputStream(channel));
while (true) {
w.print(data);
w.flush();
CharBuffer result = CharBuffer.allocate(4096);
r.read(result);
result.flip();
System.out.println("read from server: " + result.toString());
Thread.sleep(1000);
}
}
use of jnr.unixsocket.UnixSocketChannel in project linuxtools by eclipse.
the class DefaultUnixConnectionSettingsProvider method getConnectionSettings.
@Override
public List<IDockerConnectionSettings> getConnectionSettings() {
// $NON-NLS-1$
final File unixSocketFile = new File("/var/run/docker.sock");
if (unixSocketFile.exists() && unixSocketFile.canRead() && unixSocketFile.canWrite()) {
final UnixSocketAddress address = new UnixSocketAddress(unixSocketFile);
try (final UnixSocketChannel channel = UnixSocketChannel.open(address)) {
// assume socket works
final UnixSocketConnectionSettings socket = new UnixSocketConnectionSettings(DefaultDockerConnectionSettingsFinder.Defaults.DEFAULT_UNIX_SOCKET_PATH);
socket.setName(socket.getPath());
return Arrays.asList(socket);
} catch (IOException e) {
// do nothing, just assume socket did not work.
}
}
return Collections.emptyList();
}
Aggregations