Is it safe to call disconnect? - WeOnlyDo Discussion board

Is it safe to call disconnect? (General questions)

by Tushar, Sunday, August 14, 2005, 10:18 (7040 days ago)

Hi,
I am using wodSSH COM component (2.2.0.3). I have a question on whether it is safe to call a disconnect if the client has not yet connected to the remote server.

This I think is a common scenario. Assuming that a user has initiated a connection to the remote server, but s/he cancels the connection before the actual connection has established but after connect command has been issued.

When I do this my app crashes and the debugger shows me invalid heap address passed. The call stack shows that DllUnregisterServer has been called from with the wodssh.dll.

Can you please tell me what am I doing wrong. Also please note that the thread that created the component is different from the thread from where the cancel operation was called.

Thanks in Advance.
[:smile:]

Re: Is it safe to call disconnect?

by wodSupport, Sunday, August 14, 2005, 23:37 (7040 days ago) @ Tushar

Tushar,

it is safe to call Disconnect after Connect when nonblocking mode is used. But, it's dangerous to use component from multiple threads (component is apartment-threaded), you must use it from same thread where you initialized it, otherwise it may crash - as you experienced it.

I suggest you reorganize your code a bit so you can call Disconnect from same thread. Possible?

Re: Is it safe to call disconnect?

by Tushar, Wednesday, August 31, 2005, 11:30 (7023 days ago) @ wodSupport

Hi,
Thanks for the reply. But I have a common suitation here. A user issues a connect command to the server, a dialog is shown to the user displaying the status of the connection, also provided is a Cancel button so that the user can break the current operation.

Now hoping I am right once a Connect command is issued the call will not be returned till a connection is established or a timeout occurs or some other error occurs. In such a case the call to Disconnect has to come from a different thread (Am I wrong here?)

Now in my application when a Disconnect is called the application breaks in a debugger indicating invalid RtlHeapAddress (The call coming from wodSSH.dll, DllUnRegisterServer method)

I am using the component in Blocking mode(i.e. Blocking=TRUE) and my TimeOut property is set to 0 as I do not want to disconnect automatically.

Please let me know what can I do here?
Thanks.

Re: Is it safe to call disconnect?

by wodSupport, Wednesday, August 31, 2005, 16:08 (7023 days ago) @ Tushar

Tushar,

you're doing all the things I said it's not safe :) You're using multiple threads, and calling methods from multiple threads - not a good idea.

But still - perhaps we could fix this (I don't promise anything yet). Can you zip your C++ project and send it over so I can run it and see this error for myself - in which case we could probably fix it? You can send it to techsupport email.

Thanks,
Kreso