Code Monkey home page Code Monkey logo

Comments (2)

betamos avatar betamos commented on June 5, 2024

Turns out I used an older version of the library. Context does indeed exist in the SSDP search API, although it doesn't appear to be respected in the httpu client, which still runs for its full duration even if the context is canceled. I added the following to the Do method:

	ctx, cancel := context.WithTimeout(req.Context(), timeout)
	defer cancel()
	go func() {
		<-ctx.Done()
		httpu.conn.SetDeadline(time.Now())
	}()

This terminated the httpu call on time, which is I believe the way context is supposed to work. Would something like that be considered a bug fix?

As for shortening the search period: I thought we could use timeout contexts for searches, but this won't work: afaik there are more calls after to get the "device info" (don't know the details of upnp - apologies). If we cancel the context to stop the search, we can't make those requests. For that, we still need to either (a) stream the results as they come available or (b) keep using a timeout (but perhaps we can make it more granular?). Context can still be used as a last resort to terminate everything quickly on teardown.

I also tried measuring the results on my Netgear home router, and it was very fast (1-3ms). Even if the SSDP protocol requires MX >= 1, I'd really want to act on those early results, especially if that's the common case.

from goupnp.

huin avatar huin commented on June 5, 2024

This seems like a good request. We'd need to retain the existing API for any code using it, perhaps:

  1. Adding a DoWithContext method that otherwise acts like Do, but provides a way to pass back results as they come in, and respects the context completion.
  2. And then Implement Do in terms of DoWithContext so that there's only one implementation.

from goupnp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.