[ 
https://issues.apache.org/jira/browse/SSHD-722?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Li Fangning reopened SSHD-722:
------------------------------

For the following reasons, I do not agree that you think it is not a problem.
# I can not use the official way provided by SSHD-CORE (i.e. the 
FactoryManager.SOCKET_KEEPALIVE parameter) to enabling SO_KEEPALIVE option on 
the server socket. 
If you think this parameter should not be provided, you can remove it, instead 
of put it there but it can not be used.
# The check action provided by Nio2Service#setOption may be useful for 
Nio2Connector, but it is useless for Nio2Acceptor. Because the former is the 
AsynchronousSocketChannel object, but the latter is the 
AsynchronousServerSocketChannel object. The Javadoc has made it clear that the 
latter does not support the SO_KEEPALIVE attribute 
(https://docs.oracle.com/javase/8/docs/api/java/nio/channels/AsynchronousServerSocketChannel.html).
# In fact, I can circumvent this problem by using the following code 
(implements the SessionAware interface):
{code}
    public void setSession(ServerSession session) {
        try {
            ((Nio2Session) session.getIoSession()).getSocket().setOption(
                StandardSocketOptions.SO_KEEPALIVE, Boolean.TRUE);
        } catch (IOException ioe) {
            ......
        }
    }
{code}
But I do not think this is the formal way to deal with this problem.
So I put this issue, I hope it can be resolved in future version.

Best regards.

> Failed to setting SO_KEEPALIVE option for sshd server socket
> ------------------------------------------------------------
>
>                 Key: SSHD-722
>                 URL: https://issues.apache.org/jira/browse/SSHD-722
>             Project: MINA SSHD
>          Issue Type: Bug
>    Affects Versions: 1.3.0
>            Reporter: Li Fangning
>            Assignee: Goldstein Lyor
>            Priority: Minor
>
> Use the following code to set the SO_KEEPALIVE property:
>   PropertyResolverUtils.updateProperty(sshd, SshServer.SOCKET_KEEPALIVE, true)
> I get the error message: Unsupported socket option (SO_KEEPALIVE) to set 
> ......
> After I check the code in org.apache.sshd.common.io.nio2.Nio2Acceptor#bind(), 
> I found that the SO_KEEPALIVE option is set on the 
> AsynchronousServerSocketChannel, i.e. a listening socket which can only 
> accept new incoming connections and not exchange data. The socket option is 
> not applicable to a listening socket. 
> (https://docs.oracle.com/javase/8/docs/api/java/nio/channels/AsynchronousServerSocketChannel.html)
> Whether this code can be changed to the 
> org.apache.sshd.common.io.nio2.Nio2Acceptor$AcceptCompletionHandler#onCompleted(),
>  and set the options on the AsynchronousSocketChannel object?
> SO_SENDBUF, TCP_NODELAY options have the same issue.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to