Giter Site home page Giter Site logo

Comments (6)

huin avatar huin commented on July 23, 2024

I'm not sure if the original code is actually incorrect. Can you explain more a case where the code does the wrong thing?

I think my intent on writing this code was that the timeout is not an error, but rather an indication that the function should stop waiting for further responses.

from goupnp.

upperwal avatar upperwal commented on July 23, 2024

Do you intent to send the previous err (error from ResolveUDPAddr) incase of timeout in the following code?

goupnp/httpu/httpu.go

Lines 130 to 132 in 167b976

}
return responses, err
}

Use case with timeout: Calling DiscoverDevices and it timed out.
Output: DiscoverDevices returns (MaybeRootDevice = [], err = nil)
Expected Output: DiscoverDevices should return (MaybeRootDevice = [], err = error("timeout"))

So if the current implementation is correct how are upstream function calls knowing about timeout from n, _, err := httpu.conn.ReadFrom(responseBytes)

SSDPRawSearch and all the downstream function calls are returning err = nil in case of timeout. Although responses is an empty array. Is this how it should work?

goupnp/goupnp.go

Lines 60 to 67 in 167b976

func DiscoverDevices(searchTarget string) ([]MaybeRootDevice, error) {
httpu, err := httpu.NewHTTPUClient()
if err != nil {
return nil, err
}
defer httpu.Close()
responses, err := ssdp.SSDPRawSearch(httpu, string(searchTarget), 2, 3)
if err != nil {

from goupnp.

huin avatar huin commented on July 23, 2024

I think the code I wrote was a bit misleading - the final line in HTTPUClient.Do should return responses, nil.

Note that the for loop is unconditional, and only breaks upon timeout - the timeout means that we've collected all results that we expect - it's not an error condition. If responses is empty, then that means that no HTTPU responses were received within the given timeframe, which may legitimately mean that there are no devices to respond to it. Or maybe there's some other condition preventing them from responding.

from goupnp.

huin avatar huin commented on July 23, 2024

I've committed 1395d14 to clarify the code a little.

from goupnp.

upperwal avatar upperwal commented on July 23, 2024

Ok. If that's the intention then it's fine. Will be closing the issue and the corresponding PR.

Thanks.

from goupnp.

huin avatar huin commented on July 23, 2024

No problem :)

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.