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

add timeout handler #48

Closed
wants to merge 2 commits into from
Closed

Conversation

zey1996
Copy link

@zey1996 zey1996 commented Jun 20, 2023

I believe that developers should have a way to know when a data packet is lost or does not return within a specified time.

you can set MaxRtt and OnTimeout func

Ontime func while be call when a request was not answered within a specified time

you only need add:

  pinger.MaxRtt = time.Second * 3

  pinger.OnTimeOut = func(packet *probing.Packet) {
    fmt.Println("timeout", packet.Addr, packet.Rtt, packet.TTL)
  }

It has good compatibility, as if MaxRtt is not set, it will have the same behavior as before.

However, there are still some issues remaining.

  • The timing is not precise; for example, if a maximum round-trip time (maxrtt) of 100ms is set, but the request time exceeds 101ms, it is possible that the OnRecv function will still be used.
  • If a request is received after the timeout, the OnDuplicateRecv function will be called.

But I believe that this is acceptable.

zhangenyao and others added 2 commits June 20, 2023 16:36
you can set MaxRtt and OnTimeout func

Ontime func while be call when a request was not answered within a specified time
# Conflicts:
#	ping.go
select {
case <-p.done:
return nil

case <-time.After(subTime):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the performance implications of this. IIRC this will spawn a new sleeping goroutine for every packet. If there are a lot of outstanding packets it could bloat memory quite a lot.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I create a new pr: #49 and fix some problem

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about it. but I rewrite it use time.timer

@SuperQ
Copy link
Contributor

SuperQ commented Jun 20, 2023

This needs a DCO sign-off. You can use git commit -s --amend to add it.

@zey1996 zey1996 closed this Jun 21, 2023
@zey1996
Copy link
Author

zey1996 commented Jun 21, 2023

please see also: #49

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

Successfully merging this pull request may close these issues.

2 participants