Search in sources :

Example 1 with UnixServerSocketChannel

use of jnr.unixsocket.UnixServerSocketChannel 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);
    }
}
Also used : UnixSocketChannel(jnr.unixsocket.UnixSocketChannel) UnixServerSocketChannel(jnr.unixsocket.UnixServerSocketChannel)

Example 2 with UnixServerSocketChannel

use of jnr.unixsocket.UnixServerSocketChannel in project jetty.project by eclipse.

the class UnixSocketConnector method close.

public void close() {
    UnixServerSocketChannel serverChannel = _acceptChannel;
    _acceptChannel = null;
    if (serverChannel != null) {
        removeBean(serverChannel);
        // If the interrupt did not close it, we should close it
        if (serverChannel.isOpen()) {
            try {
                serverChannel.close();
            } catch (IOException e) {
                LOG.warn(e);
            }
        }
        new File(_unixSocket).delete();
    }
}
Also used : IOException(java.io.IOException) File(java.io.File) UnixServerSocketChannel(jnr.unixsocket.UnixServerSocketChannel)

Example 3 with UnixServerSocketChannel

use of jnr.unixsocket.UnixServerSocketChannel in project acceptance-test-harness by jenkinsci.

the class UnixDomainSocketTestServer method main.

public static void main(String[] args) throws Exception {
    File path = new File("./jenkins.sock");
    path.deleteOnExit();
    UnixServerSocketChannel channel = UnixServerSocketChannel.open();
    channel.configureBlocking(true);
    channel.socket().bind(new UnixSocketAddress(path));
    while (true) {
        UnixSocketChannel c = channel.accept();
        System.out.println("Accepted");
        InputStream in = Channels.newInputStream(c);
        OutputStream out = Channels.newOutputStream(c);
        IOUtils.copy(in, out);
        System.out.println("Closed");
        c.close();
    }
}
Also used : UnixSocketChannel(jnr.unixsocket.UnixSocketChannel) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) File(java.io.File) UnixServerSocketChannel(jnr.unixsocket.UnixServerSocketChannel) UnixSocketAddress(jnr.unixsocket.UnixSocketAddress)

Example 4 with UnixServerSocketChannel

use of jnr.unixsocket.UnixServerSocketChannel in project jetty.project by eclipse.

the class UnixSocketConnector method open.

public void open() throws IOException {
    if (_acceptChannel == null) {
        UnixServerSocketChannel serverChannel = UnixServerSocketChannel.open();
        SocketAddress bindAddress = new UnixSocketAddress(new File(_unixSocket));
        serverChannel.socket().bind(bindAddress, getAcceptQueueSize());
        serverChannel.configureBlocking(getAcceptors() > 0);
        addBean(serverChannel);
        LOG.debug("opened {}", serverChannel);
        _acceptChannel = serverChannel;
    }
}
Also used : SocketAddress(java.net.SocketAddress) UnixSocketAddress(jnr.unixsocket.UnixSocketAddress) File(java.io.File) UnixServerSocketChannel(jnr.unixsocket.UnixServerSocketChannel) UnixSocketAddress(jnr.unixsocket.UnixSocketAddress)

Example 5 with UnixServerSocketChannel

use of jnr.unixsocket.UnixServerSocketChannel in project acceptance-test-harness by jenkinsci.

the class JenkinsControllerPoolProcess method processServerSocket.

/**
 * Accepts connection to Unix domain socket and hand it off to a connection handling thread.
 */
private void processServerSocket() throws IOException, InterruptedException {
    socket.deleteOnExit();
    socket.delete();
    try (UnixServerSocketChannel channel = UnixServerSocketChannel.open()) {
        channel.configureBlocking(true);
        channel.socket().bind(new UnixSocketAddress(socket));
        System.out.println("JUT Server is ready and listening at " + socket.getAbsolutePath());
        while (true) {
            final UnixSocketChannel c = channel.accept();
            System.out.println("Accepted");
            final QueueItem qi = queue.take();
            final JenkinsController j = qi.controller;
            System.out.println("Handed out " + j.getUrl());
            new Thread("Connection handling thread") {

                @Override
                public void run() {
                    lifecycle.import_(qi.testScope);
                    try {
                        processConnection(c, j);
                    } finally {
                        TestCleaner scope = injector.getInstance(TestCleaner.class);
                        if (scope != null)
                            scope.performCleanUp();
                        lifecycle.endTestScope();
                    }
                }
            }.start();
        }
    }
}
Also used : TestCleaner(org.jenkinsci.test.acceptance.guice.TestCleaner) UnixSocketChannel(jnr.unixsocket.UnixSocketChannel) JenkinsController(org.jenkinsci.test.acceptance.controller.JenkinsController) IJenkinsController(org.jenkinsci.test.acceptance.controller.IJenkinsController) UnixServerSocketChannel(jnr.unixsocket.UnixServerSocketChannel) UnixSocketAddress(jnr.unixsocket.UnixSocketAddress)

Aggregations

UnixServerSocketChannel (jnr.unixsocket.UnixServerSocketChannel)5 File (java.io.File)3 UnixSocketAddress (jnr.unixsocket.UnixSocketAddress)3 UnixSocketChannel (jnr.unixsocket.UnixSocketChannel)3 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 SocketAddress (java.net.SocketAddress)1 IJenkinsController (org.jenkinsci.test.acceptance.controller.IJenkinsController)1 JenkinsController (org.jenkinsci.test.acceptance.controller.JenkinsController)1 TestCleaner (org.jenkinsci.test.acceptance.guice.TestCleaner)1