rust-pcap / pcap

Rust language pcap library
Apache License 2.0
595 stars 138 forks source link

There is no option to switch off non-blocking mode #304

Closed thegreathir closed 11 months ago

thegreathir commented 1 year ago

The value "1" is hard coded here so you can not switch off non-blocking mode as described here.

Stargateur commented 1 year ago

This lib is not a mirror of libpcap API, it's more an abstraction of libpcap API, thus I agree it's not possible to switch it off (using this lib only, you can always call pcap_setnonblock() yourself), in what case would you need to switch it off ?

Wojtek242 commented 1 year ago

The value "1" is hard coded here so you can not switch off non-blocking mode as described here.

You are right. The solution would be to make the pcap library take to: bool parameter and cast it appropriately when calling the raw API as done here.

I may get around to this at some point (I usually batch some amount of work for pcap before doing it), but if you submit a PR I can merge and release it as soon as it's ready.

Wojtek242 commented 1 year ago

This would however, require a major version bump, so please in your PR describe your use case.

thegreathir commented 1 year ago

I was testing something... I think because this API will produce a system call at the end, swtching on or off continuosly will drain performance. So I gave it up.

Stargateur commented 1 year ago

That why I asked you what was the use-case, I never see any usecase that needed to change the blocking mode of a socket. Also to avoid breaking change if really really this feature is needed I would first add a function and in a future breaking change merge the two functions. it's a trivial "problem" of our API I don't think bump to 2.0 is worth it. And again I don't think we need this feature at all.