danikf / tik4net

Manage mikrotik routers with .NET C# code via ADO.NET like API or enjoy O/R mapper like highlevel api.
Apache License 2.0
174 stars 93 forks source link

ExecuteListWithDuration doesn't stop on disconnection #41

Closed AsafMag closed 6 years ago

AsafMag commented 6 years ago

The following code:

var cmd = connection.CreateCommand("interface/wireless/sniffer/sniff")
cmd.AddParameter("interface", "wlan1");
cmd.ExecuteListWithDuration(9999);

Doesn't stop when I shut down my MikroTik board. A breakpoint inside ExecuteListWithDuration shows that Connection._isOpened == true.

I haven't tested other functions such as ExecuteAsync etc.

danikf commented 6 years ago

Hi, and what behavior do you expect? Exception? D

AsafMag commented 6 years ago

I think an exception could do the trick, considering the function can't return a boolean result or launch an event because it is synchronous

AsafMag commented 6 years ago

@danikf This doesn't seem to work even after the updates you uploaded yesterday: I launched a command for 9999 seconds and disabled the ethernet interface on the PC. Connection.IsConnected was then set to false but ExecuteListWithDuration was still running. Can you reopen?

danikf commented 6 years ago

Hi, could you please test your scenario with last commited fix?

Thanks, D

AsafMag commented 6 years ago

It returns immediately. There are other problems now:

  1. How can I know if it returned due to disconnection or duration?
  2. IsRunning stays true (kind of answers the first problem but I believe it shouldn't be like that).

Shouldn't it break instead of return? It will cause a TikConnectionException to be thrown.

danikf commented 6 years ago

Hi,

the problem in my test scenario is, that !done is returned before connection si closed. So in this situation, response with incomplete list of items is (from my point of view) correct.

> /tool/torch
> =interface=ether1
> .tag=1
> /system/reboot
< !re
< =tx=864
< =rx=1024
< =tx-packets=2
< =rx-packets=2
< .tag=1
< 
< !re
< =tx=864
< =rx=1024
< =tx-packets=2
< =rx-packets=2
< .tag=1
< 
< !re
< =tx=1776
< =rx=960
< =tx-packets=2
< =rx-packets=2
< .tag=1
< 
< !re
< =tx=1776
< =rx=960
< =tx-packets=2
< =rx-packets=2
< .tag=1
< 
< !done
< 
< !done
< .tag=1
... connection closed ...
danikf commented 6 years ago

Hi, finally I have implemented both scenarios (overloads with exception and also second overload with returning incomplete response with error info).

In hope it solved your case, D PS: I would still recommend to use 1) Single connection + multiple ExecuteAsync calls 2) Multiple connections + single sync call

AsafMag commented 6 years ago

@danikf Looking good, thanks :)