Attempts to capture all known socket options and return the results as a InternalChannelz.SocketOptions. If getting a socket option threw an exception, log the error to the logger and report the value as an error in the response.
(Socket socket)
| 99 | * log the error to the logger and report the value as an error in the response. |
| 100 | */ |
| 101 | static InternalChannelz.SocketOptions getSocketOptions(Socket socket) { |
| 102 | InternalChannelz.SocketOptions.Builder builder = new InternalChannelz.SocketOptions.Builder(); |
| 103 | try { |
| 104 | builder.setSocketOptionLingerSeconds(socket.getSoLinger()); |
| 105 | } catch (SocketException e) { |
| 106 | log.log(Level.SEVERE, "Exception caught while reading socket option", e); |
| 107 | builder.addOption("SO_LINGER", "channelz_internal_error"); |
| 108 | } |
| 109 | |
| 110 | try { |
| 111 | builder.setSocketOptionTimeoutMillis(socket.getSoTimeout()); |
| 112 | } catch (Exception e) { |
| 113 | log.log(Level.SEVERE, "Exception caught while reading socket option", e); |
| 114 | builder.addOption("SO_TIMEOUT", "channelz_internal_error"); |
| 115 | } |
| 116 | |
| 117 | try { |
| 118 | builder.addOption("TCP_NODELAY", socket.getTcpNoDelay()); |
| 119 | } catch (SocketException e) { |
| 120 | log.log(Level.SEVERE, "Exception caught while reading socket option", e); |
| 121 | builder.addOption("TCP_NODELAY", "channelz_internal_error"); |
| 122 | } |
| 123 | |
| 124 | try { |
| 125 | builder.addOption("SO_REUSEADDR", socket.getReuseAddress()); |
| 126 | } catch (SocketException e) { |
| 127 | log.log(Level.SEVERE, "Exception caught while reading socket option", e); |
| 128 | builder.addOption("SO_REUSEADDR", "channelz_internal_error"); |
| 129 | } |
| 130 | |
| 131 | try { |
| 132 | builder.addOption("SO_SNDBUF", socket.getSendBufferSize()); |
| 133 | } catch (SocketException e) { |
| 134 | log.log(Level.SEVERE, "Exception caught while reading socket option", e); |
| 135 | builder.addOption("SO_SNDBUF", "channelz_internal_error"); |
| 136 | } |
| 137 | |
| 138 | try { |
| 139 | builder.addOption("SO_RECVBUF", socket.getReceiveBufferSize()); |
| 140 | } catch (SocketException e) { |
| 141 | log.log(Level.SEVERE, "Exception caught while reading socket option", e); |
| 142 | builder.addOption("SO_RECVBUF", "channelz_internal_error"); |
| 143 | } |
| 144 | |
| 145 | try { |
| 146 | builder.addOption("SO_KEEPALIVE", socket.getKeepAlive()); |
| 147 | } catch (SocketException e) { |
| 148 | log.log(Level.SEVERE, "Exception caught while reading socket option", e); |
| 149 | builder.addOption("SO_KEEPALIVE", "channelz_internal_error"); |
| 150 | } |
| 151 | |
| 152 | try { |
| 153 | builder.addOption("SO_OOBINLINE", socket.getOOBInline()); |
| 154 | } catch (SocketException e) { |
| 155 | log.log(Level.SEVERE, "Exception caught while reading socket option", e); |
| 156 | builder.addOption("SO_OOBINLINE", "channelz_internal_error"); |
| 157 | } |
| 158 |