323 c.close();
324 } catch (IOException x) {
325 // no matter - we're closing.
326 failed++;
327 }
328 }
329 connections.clear();
330 if (failed > 0) {
331 throw new IOException("Failed to close some connections");
332 }
333 }
334 }
335
336 /**
337 * A small TCP Server that emulates the echo service for tests purposes. See
338 * http://en.wikipedia.org/wiki/Echo_Protocol This server uses an anonymous
339 * port - NOT the standard port 7. We don't guarantee that its behavior
340 * exactly matches the RFC - the only purpose of this server is to have
341 * something that responds to nio tests...
342 */
343 static final class EchoServer extends AbstractTcpServer {
344
345 public EchoServer() {
346 this(0L);
347 }
348
349 public EchoServer(long linger) {
350 super(linger);
351 }
352
353 @Override
354 protected TcpConnectionThread createConnection(Socket s) {
355 return new EchoConnection(s);
356 }
357
358 private final class EchoConnection extends TcpConnectionThread {
359
360 public EchoConnection(Socket socket) {
361 super(socket);
362 }
363
383 "Failed to close echo connection socket");
384 }
385 }
386 removeConnection(this);
387 }
388 }
389 }
390
391 public static EchoServer startNewServer() throws IOException {
392 return startNewServer(0);
393 }
394
395 public static EchoServer startNewServer(long linger) throws IOException {
396 final EchoServer echoServer = new EchoServer(linger);
397 echoServer.start();
398 return echoServer;
399 }
400 }
401
402 /**
403 * A small TCP server that emulates the Day & Time service for tests
404 * purposes. See http://en.wikipedia.org/wiki/Daytime_Protocol This server
405 * uses an anonymous port - NOT the standard port 13. We don't guarantee
406 * that its behavior exactly matches the RFC - the only purpose of this
407 * server is to have something that responds to nio tests...
408 */
409 static final class DayTimeServer extends AbstractTcpServer {
410
411 public DayTimeServer() {
412 this(0L);
413 }
414
415 public DayTimeServer(long linger) {
416 super(linger);
417 }
418
419 @Override
420 protected TcpConnectionThread createConnection(Socket s) {
421 return new DayTimeServerConnection(s);
422 }
|
323 c.close();
324 } catch (IOException x) {
325 // no matter - we're closing.
326 failed++;
327 }
328 }
329 connections.clear();
330 if (failed > 0) {
331 throw new IOException("Failed to close some connections");
332 }
333 }
334 }
335
336 /**
337 * A small TCP Server that emulates the echo service for tests purposes. See
338 * http://en.wikipedia.org/wiki/Echo_Protocol This server uses an anonymous
339 * port - NOT the standard port 7. We don't guarantee that its behavior
340 * exactly matches the RFC - the only purpose of this server is to have
341 * something that responds to nio tests...
342 */
343 static class EchoServer extends AbstractTcpServer {
344
345 public EchoServer() {
346 this(0L);
347 }
348
349 public EchoServer(long linger) {
350 super(linger);
351 }
352
353 @Override
354 protected TcpConnectionThread createConnection(Socket s) {
355 return new EchoConnection(s);
356 }
357
358 private final class EchoConnection extends TcpConnectionThread {
359
360 public EchoConnection(Socket socket) {
361 super(socket);
362 }
363
383 "Failed to close echo connection socket");
384 }
385 }
386 removeConnection(this);
387 }
388 }
389 }
390
391 public static EchoServer startNewServer() throws IOException {
392 return startNewServer(0);
393 }
394
395 public static EchoServer startNewServer(long linger) throws IOException {
396 final EchoServer echoServer = new EchoServer(linger);
397 echoServer.start();
398 return echoServer;
399 }
400 }
401
402 /**
403 * A small TCP Server that accept connections but does not response to any input.
404 */
405 static final class NoResponseServer extends EchoServer {
406 public NoResponseServer() {
407 super(Long.MAX_VALUE);
408 }
409
410 public static NoResponseServer startNewServer() throws IOException {
411 final NoResponseServer noResponseServer = new NoResponseServer();
412 noResponseServer.start();
413 return noResponseServer;
414 }
415 }
416
417 /**
418 * A small TCP server that emulates the Day & Time service for tests
419 * purposes. See http://en.wikipedia.org/wiki/Daytime_Protocol This server
420 * uses an anonymous port - NOT the standard port 13. We don't guarantee
421 * that its behavior exactly matches the RFC - the only purpose of this
422 * server is to have something that responds to nio tests...
423 */
424 static final class DayTimeServer extends AbstractTcpServer {
425
426 public DayTimeServer() {
427 this(0L);
428 }
429
430 public DayTimeServer(long linger) {
431 super(linger);
432 }
433
434 @Override
435 protected TcpConnectionThread createConnection(Socket s) {
436 return new DayTimeServerConnection(s);
437 }
|