[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Non-blocking Connect
[Thread Prev] | [Thread Next]
- Subject: Non-blocking Connect
- From: Jason Curl <jason@xxxxxxxxxxxxxxxxxxxxxxxx>
- Reply-to: libssh@xxxxxxxxxx
- Date: Tue, 30 May 2017 06:59:05 +0000
- To: "libssh@xxxxxxxxxx" <libssh@xxxxxxxxxx>
Hello,
I'm trying non-blocking mode on master (dated 26th April) and as a test I'm
connected to localhost where no server is running. The docs say to call
connect() again after SSH_AGAIN, which I'm doing. As I know there is no
server, I'd expect at some time the connection to timeout. But it doesn't.
Is this a known bug in libssh.org?
The reason why I'm using a non-blocking connect is to have the ability to
abort it with .NET without memory leaks, putting a blocking connect on a
thread and killing that thread means any internal memory allocated by
libssh.org won't be freed.
To give you an idea of the code I'm using:
NativeMethods.ssh_set_blocking(m_Session, false);
bool connected = false;
int counter = 0;
while (!connected) {
SshResult crc =
(SshResult)NativeMethods.ssh_connect(m_Session);
if (crc == SshResult.SSH_OK) {
Console.WriteLine("Connected");
connected = true;
continue;
}
if (crc == SshResult.SSH_AGAIN) {
Console.WriteLine("Busy {0}", counter++);
System.Threading.Thread.Sleep(250);
continue;
}
if (crc != SshResult.SSH_OK) {
string message = string.Format("Cannot connect: {0}
({1})", GetError(), GetErrorCode());
throw new InvalidOperationException(message);
}
}
If I have blocking mode, the connection fails after about 6 seconds: "Cannot
connect: Timeout connecting to 127.0.0.1 (2)"
I would have expected nonblocking mode to also eventually return an error
with the same reason.
Any help would be appreciated.
Regards,
Jason.
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
| RE: Non-blocking Connect | Saju Panikulam <spanikulam@xxxxxxxxxxxx> |