Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the documentation for __next__() #73

Open
JosiahDub opened this issue May 22, 2018 · 5 comments
Open

Improve the documentation for __next__() #73

JosiahDub opened this issue May 22, 2018 · 5 comments

Comments

@JosiahDub
Copy link

After 924dfde, __next__() continues instead of returning None when timing out. This does not seem like ideal behavior. Am I misinterpreting timeout or misusing the function? Ideal code snippet:

import pcap
p = pcap.pcap(timeout_ms=50)
# Set the filter so that no packets will arrive
p.setfilter("port 55555")
try:
    timestamp, packet = p.__next__()
except TypeError:
    print("__next__() returned None in a reasonable time-frame!")

I modified pcap.pyx to return None and the code snippet worked.

@hellais
Copy link
Member

hellais commented Sep 4, 2018

@nuald what are you thoughts on this?

@nuald
Copy link

nuald commented Sep 5, 2018

I've already mentioned it here: https://github.com/pynetwork/pypcap/pull/47/files#r116732203 The loop should be infinite - it's the user responsibility to correctly exit the loop. The timeout_ms parameter corresponds to packet buffer timeout (see https://www.tcpdump.org/manpages/pcap.3pcap.html), not to the timeout for exiting the loop if nothing happens. I'd recommend to update the documentation or provide additional timeout parameter to avoid confusion.

@hellais
Copy link
Member

hellais commented Sep 17, 2018

Ah right, thanks for reminding me of that. I would say then this ticket should become that of updating the docs to document this as the expected behaviour.

@hellais hellais changed the title __next__() continues instead of returning None when timing out Improve the documentation for __next__() Sep 17, 2018
@wtdcode
Copy link

wtdcode commented Apr 16, 2020

@nuald But why not give users a choice to handle the event, like raise TimeoutError or something else?

@nuald
Copy link

nuald commented Apr 16, 2020

@wtdcode Sorry, I'm not working on this project nowadays, and only can give some advice: please feel free to modify pcap.pyx for your needs - the packet buffer timeout occurs when pcap_ex_next returns 0 (please see https://www.tcpdump.org/manpages/pcap_next_ex.3pcap.html for the details). Right now in the code there is no special processing for it, and I guess you could add something there instead of just calling continue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants