@Override protected int doReadMessages(MessageList<Object> buf) throws Exception { if (socket.isClosed()) { return -1; } try { Socket s = socket.accept(); try { if (s != null) { buf.add(new OioSocketChannel(this, s)); return 1; } } catch (Throwable t) { logger.warn("Failed to create a new channel from an accepted socket.", t); if (s != null) { try { s.close(); } catch (Throwable t2) { logger.warn("Failed to close a socket.", t2); } } } } catch (SocketTimeoutException e) { // Expected } return 0; }
@Parameters(name = "{index}: serverEngine = {0}, clientEngine = {1}") public static Collection<Object[]> data() throws Exception { List<SslContext> serverContexts = new ArrayList<SslContext>(); List<SslContext> clientContexts = new ArrayList<SslContext>(); clientContexts.add(new JdkSslClientContext(CERT_FILE)); boolean hasOpenSsl = OpenSsl.isAvailable(); if (hasOpenSsl) { OpenSslServerContext context = new OpenSslServerContext(CERT_FILE, KEY_FILE); context.setRejectRemoteInitiatedRenegotiation(true); serverContexts.add(context); } else { logger.warn( "OpenSSL is unavailable and thus will not be tested.", OpenSsl.unavailabilityCause()); } List<Object[]> params = new ArrayList<Object[]>(); for (SslContext sc : serverContexts) { for (SslContext cc : clientContexts) { for (int i = 0; i < 32; i++) { params.add(new Object[] {sc, cc}); } } } return params; }
static { boolean disabled; if (SystemPropertyUtil.get("io.netty.noResourceLeakDetection") != null) { boolean disabled = SystemPropertyUtil.getBoolean("io.netty.noResourceLeakDetection", false); logger.debug("-Dio.netty.noResourceLeakDetection: {}", Boolean.valueOf(disabled)); logger.warn( "-Dio.netty.noResourceLeakDetection is deprecated. Use '-D{}={}' instead.", "io.netty.leakDetectionLevel", DEFAULT_LEVEL.name().toLowerCase()); } else { disabled = false; } Level defaultLevel = disabled ? Level.DISABLED : DEFAULT_LEVEL; String levelStr = SystemPropertyUtil.get("io.netty.leakDetectionLevel", defaultLevel.name()) .trim() .toUpperCase(); Level level = DEFAULT_LEVEL; for (Level l : EnumSet.allOf(Level.class)) { if ((levelStr.equals(l.name())) || (levelStr.equals(String.valueOf(l.ordinal())))) { level = l; } } level = level; if (logger.isDebugEnabled()) { logger.debug("-D{}: {}", "io.netty.leakDetectionLevel", level.name().toLowerCase()); } }
private static void safeClose(OutputStream out) { try { out.close(); } catch (IOException e) { logger.warn("Failed to close a stream.", e); } }
private static void safeClose(InputStream in) { try { in.close(); } catch (IOException e) { logger.warn("Failed to close a stream.", e); } }
/** * Create a new instance from the given {@link ServerSocket} * * @param socket the {@link ServerSocket} which is used by this instance */ public OioServerSocketChannel(ServerSocket socket) { super(null); if (socket == null) { throw new NullPointerException("socket"); } boolean success = false; try { socket.setSoTimeout(SO_TIMEOUT); success = true; } catch (IOException e) { throw new ChannelException("Failed to set the server socket timeout.", e); } finally { if (!success) { try { socket.close(); } catch (IOException e) { if (logger.isWarnEnabled()) { logger.warn("Failed to close a partially initialized socket.", e); } } } } this.socket = socket; config = new DefaultOioServerSocketChannelConfig(this, socket); }
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof SslHandshakeCompletionEvent) { SslHandshakeCompletionEvent handshakeEvt = (SslHandshakeCompletionEvent) evt; if (handshakeCounter == 0) { handshakeCounter++; if (handshakeEvt.cause() != null) { logger.warn("Handshake failed:", handshakeEvt.cause()); } assertSame(SslHandshakeCompletionEvent.SUCCESS, evt); } else { if (ctx.channel().parent() == null) { assertTrue(handshakeEvt.cause() instanceof ClosedChannelException); } } } }
/** * Create a new instance * * @param parent the {@link Channel} which is the parent of this {@link NioSctpChannel} or {@code * null}. * @param sctpChannel the underlying {@link SctpChannel} */ public NioSctpChannel(Channel parent, SctpChannel sctpChannel) { super(parent, sctpChannel, SelectionKey.OP_READ); try { sctpChannel.configureBlocking(false); config = new NioSctpChannelConfig(this, sctpChannel); notificationHandler = new SctpNotificationHandler(this); } catch (IOException e) { try { sctpChannel.close(); } catch (IOException e2) { if (logger.isWarnEnabled()) { logger.warn("Failed to close a partially initialized sctp channel.", e2); } } throw new ChannelException("Failed to enter non-blocking mode.", e); } }
/** * Create a new instance from the given {@link Socket} * * @param parent the parent {@link Channel} which was used to create this instance. This can be * null if the {@link} has no parent as it was created by your self. * @param socket the {@link Socket} which is used by this instance */ public OioSocketChannel(Channel parent, EventLoop eventLoop, Socket socket) { super(parent, eventLoop); this.socket = socket; config = new DefaultOioSocketChannelConfig(this, socket); boolean success = false; try { if (socket.isConnected()) { activate(socket.getInputStream(), socket.getOutputStream()); } socket.setSoTimeout(SO_TIMEOUT); success = true; } catch (Exception e) { throw new ChannelException("failed to initialize a socket", e); } finally { if (!success) { try { socket.close(); } catch (IOException e) { logger.warn("Failed to close a socket.", e); } } } }
public void warn(Object arg0, Throwable arg1) { if (arg1 == null) return; if (arg0 != null) _log.warn(arg0.toString(), arg1); else _log.warn("null", arg1); }
public void warn(Object arg0) { if (arg0 != null) _log.warn(arg0.toString()); else _log.warn("null"); }