| 555 | } |
| 556 | |
| 557 | static InternalChannelz.SocketOptions getSocketOptions(Channel channel) { |
| 558 | ChannelConfig config = channel.config(); |
| 559 | InternalChannelz.SocketOptions.Builder b = new InternalChannelz.SocketOptions.Builder(); |
| 560 | |
| 561 | // The API allows returning null but not sure if it can happen in practice. |
| 562 | // Let's be paranoid and do null checking just in case. |
| 563 | Integer lingerSeconds = config.getOption(SO_LINGER); |
| 564 | if (lingerSeconds != null) { |
| 565 | b.setSocketOptionLingerSeconds(lingerSeconds); |
| 566 | } |
| 567 | |
| 568 | Integer timeoutMillis = config.getOption(SO_TIMEOUT); |
| 569 | if (timeoutMillis != null) { |
| 570 | // in java, SO_TIMEOUT only applies to receiving |
| 571 | b.setSocketOptionTimeoutMillis(timeoutMillis); |
| 572 | } |
| 573 | |
| 574 | for (Map.Entry<ChannelOption<?>, Object> opt : config.getOptions().entrySet()) { |
| 575 | ChannelOption<?> key = opt.getKey(); |
| 576 | // Constants are pooled, so there should only be one instance of each constant |
| 577 | if (key.equals(SO_LINGER) || key.equals(SO_TIMEOUT)) { |
| 578 | continue; |
| 579 | } |
| 580 | Object value = opt.getValue(); |
| 581 | // zpencer: Can a netty option be null? |
| 582 | b.addOption(key.name(), String.valueOf(value)); |
| 583 | } |
| 584 | |
| 585 | NativeSocketOptions nativeOptions |
| 586 | = NettySocketSupport.getNativeSocketOptions(channel); |
| 587 | if (nativeOptions != null) { |
| 588 | b.setTcpInfo(nativeOptions.tcpInfo); // may be null |
| 589 | for (Map.Entry<String, String> entry : nativeOptions.otherInfo.entrySet()) { |
| 590 | b.addOption(entry.getKey(), entry.getValue()); |
| 591 | } |
| 592 | } |
| 593 | return b.build(); |
| 594 | } |
| 595 | |
| 596 | private enum EventLoopGroupType { |
| 597 | NIO, |