Comments (2)
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.
This seems like a good request. We'd need to retain the existing API for any code using it, perhaps:
- Adding a
DoWithContext
method that otherwise acts likeDo
, but provides a way to pass back results as they come in, and respects the context completion. - And then Implement
Do
in terms ofDoWithContext
so that there's only one implementation.
from goupnp.
Related Issues (20)
- Unable to find devices most of the time HOT 7
- It's not possible to query ssdp:all HOT 1
- Incorrect err (nil) returned incase of timeout in httpu HOT 6
- Discover UPnP as not active if UPnP not ON in device HOT 4
- Show devices connected to discovered UPnP enabled device. HOT 2
- Why can't i find this upnp device (http://192.168.61.1:5000/rootDesc.xml)? HOT 5
- GetTotalBytesSent() can't parse value, if it's negative HOT 3
- Fail on http post request to router. HOT 12
- httpu multicast fails on multiple interfaces HOT 7
- Please provide example of AV dlna device implementation (audio) HOT 2
- Could you specify some examples? HOT 10
- Making charset dependency optional HOT 6
- SSDPRawSearch: With the same USN, ipv4Response was replaced by ipv6Response, which is not effected for ipv4only client. HOT 1
- Contexts on HTTP calls HOT 6
- httpu: error while parsing response HOT 4
- Any plan to add SSDP Server Support ? HOT 1
- get the IP associated with the interface used to successfully discover the upnp setup ? HOT 26
- update the guide HOT 1
- Provide an API to use specific ip addresses for discovery HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from goupnp.