public void end(int exit) { conn.close(exit); }
public void close() { conn.close(); }
default void close(int exit) { close(); }
default void close(int exit) { close(); }
} catch (Exception e) { conn.write("YOU LOST"); conn.close(); return;
public static void readline(Readline readline, TtyConnection conn) { readline.readline(conn, "% ", line -> { if (line == null) { conn.write("Logout").close(); } else { conn.write("User entered " + line + "\n"); // Read line again readline(readline, conn); } }); } }
public static void readline(Readline readline, TtyConnection conn) { readline.readline(conn, "% ", line -> { if (line == null) { conn.write("Logout").close(); } else { conn.write("User entered " + line + "\n"); // Read line again readline(readline, conn); } }); } }
private void onNewLine(TtyConnection conn, Readline readline, String line) { if (processStdinListener != null) { processStdinListener.accept(line); } if (line == null) { conn.close(); return; } PtyMaster task = new PtyMaster(line, buffer -> onStdOut(conn, buffer), empty -> doneHandler(conn, readline)); conn.setEventHandler((event,cp) -> { if (event == TtyEvent.INTR) { task.interruptProcess(); } }); if (processListener != null) { processListener.accept(task); } task.start(); }
@Override public void accept(TtyConnection conn) { conn.setCloseHandler(new Consumer<Void>() { @Override public void accept(Void v) { new Thread() { @Override public void run() { for (int i = 0;i < 100;i++) { if (checkDisconnected()) { testComplete(); return; } try { Thread.sleep(10); } catch (InterruptedException e) { fail(e); } } } }.start(); } }); conn.close(); } });
private void onNewLine(TtyConnection conn, Readline readline, String line) { if (processStdinListener != null) { processStdinListener.accept(line); } if (line == null) { conn.close(); return; } PtyMaster task = new PtyMaster(line, buffer -> onStdOut(conn, buffer), empty -> doneHandler(conn, readline)); conn.setEventHandler((event,cp) -> { if (event == TtyEvent.INTR) { task.interruptProcess(); } }); if (processListener != null) { processListener.accept(task); } task.start(); }
@Test public void testServerDisconnect() throws Exception { CountDownLatch closedLatch = new CountDownLatch(1); server(conn -> { conn.setStdinHandler(bytes -> { conn.close(); }); conn.setCloseHandler(v -> { closedLatch.countDown(); }); }); assertConnect(); assertWrite("whatever"); assertTrue(closedLatch.await(10, TimeUnit.SECONDS)); }
@Test public void testServerDisconnect() throws Exception { CountDownLatch closedLatch = new CountDownLatch(1); server(conn -> { conn.setStdinHandler(bytes -> { conn.close(); }); conn.setCloseHandler(v -> { closedLatch.countDown(); }); }); assertConnect(); assertWrite("whatever"); assertTrue(closedLatch.await(10, TimeUnit.SECONDS)); }
@Test public void testExitCode() throws Exception { server(conn -> { conn.setStdinHandler(bytes -> { conn.close(25); }); }); assertConnect(); assertWrite("whatever"); long timeout = System.currentTimeMillis() + 5000; while (!channel.isClosed()) { assertTrue(System.currentTimeMillis() < timeout); Thread.sleep(10); } assertEquals(25, channel.getExitStatus()); }
@Test public void testExitCode() throws Exception { server(conn -> { conn.setStdinHandler(bytes -> { conn.close(25); }); }); assertConnect(); assertWrite("whatever"); long timeout = System.currentTimeMillis() + 5000; while (!channel.isClosed()) { assertTrue(System.currentTimeMillis() < timeout); Thread.sleep(10); } assertEquals(25, channel.getExitStatus()); }
@Test public void testConnectionClose() throws Exception { AtomicInteger closeCount = new AtomicInteger(); server(conn -> { conn.setCloseHandler(v -> { if (closeCount.incrementAndGet() > 1) { fail("Closed call several times"); } else { testComplete(); } }); conn.setStdinHandler(text -> conn.close()); }); assertConnect(); assertWrite("bye"); await(); }
@Test public void testConnectionClose() throws Exception { AtomicInteger closeCount = new AtomicInteger(); server(conn -> { conn.setCloseHandler(v -> { if (closeCount.incrementAndGet() > 1) { fail("Closed call several times"); } else { testComplete(); } }); conn.setStdinHandler(text -> conn.close()); }); assertConnect(); assertWrite("bye"); await(); }
public static void handle(TtyConnection conn) { conn.setEventHandler((event, key) -> { switch (event) { case INTR: conn.write("You did a Ctrl-C\n"); break; case SUSP: conn.write("You did a Ctrl-Z\n"); break; case EOF: conn.write("You did a Ctrl-D: closing\n"); conn.close(); break; } }); conn.setSizeHandler(size -> { conn.write("You resized your terminal to " + size + "\n"); }); conn.setTerminalTypeHandler(term -> { conn.write("Your terminal is " + term + "\n"); }); conn.setStdinHandler(keys -> { for (int key : keys) { conn.write("You typed " + key + "\n"); } }); }
public static void handle(TtyConnection conn) { conn.setEventHandler((event, key) -> { switch (event) { case INTR: conn.write("You did a Ctrl-C\n"); break; case SUSP: conn.write("You did a Ctrl-Z\n"); break; case EOF: conn.write("You did a Ctrl-D: closing\n"); conn.close(); break; } }); conn.setSizeHandler(size -> { conn.write("You resized your terminal to " + size + "\n"); }); conn.setTerminalTypeHandler(term -> { conn.write("Your terminal is " + term + "\n"); }); conn.setStdinHandler(keys -> { for (int key : keys) { conn.write("You typed " + key + "\n"); } }); }
@Test public void testConnectionCloseImmediatly() throws Exception { server(conn -> { conn.setCloseHandler(v -> { new Thread() { @Override public void run() { for (int i = 0;i < 100;i++) { if (checkDisconnected()) { testComplete(); return; } try { Thread.sleep(10); } catch (InterruptedException e) { fail(e); } } } }.start(); }); conn.close(); }); assertConnect(); await(); }
@Test public void testConnectionCloseImmediatly() throws Exception { server(conn -> { conn.setCloseHandler(v -> { new Thread() { @Override public void run() { for (int i = 0;i < 100;i++) { if (checkDisconnected()) { testComplete(); return; } try { Thread.sleep(10); } catch (InterruptedException e) { fail(e); } } } }.start(); }); conn.close(); }); assertConnect(); await(); }