Is the SshChannnel.Receive function thread safe?

0 votes
asked Dec 5, 2017 by tom.abcd (320 points)

So can I do this:
In thread 1 create the SSHSession and SshChannel.
Also in thread 1 use the SshChannel.Send function.
In Thread 2 use the SshChannel.Poll and SshChannel.Receive functions.

Would the Isocket (SshChannel.ToSocket) interface be ok to use in another thread? ( My guess is the Isocket and SShchannel would be calling the same functions so no different.... Is this correct? )

I am using the Channel to send some binary data (not a file) to an embedded system.


related to an answer for: Best way to read from a SshChannel?

1 Answer

0 votes
answered Dec 6, 2017 by Lukas Matyska (59,530 points)
selected Dec 6, 2017 by tom.abcd
Best answer

Yes, the SshChannel class is thread safe in mentioned manner. You can call Send and Poll+Receive concurrently.

Also, ISocket objects created by calling SshChannel.ToSocket() method are thread save in mentioned manner. The ISocket object created this way simply invokes corresponding method on the parent SshChannel object.

I would like to note that calling ISocket.Close() closes the parent SshChannel as well.