Git Product home page Git Product logo

Comments (5)

yhirose avatar yhirose commented on May 21, 2024

@sgraham, thanks for the feedback. cpp-httplib doesn't have a method that tells the actual port.

It seems like we can figure out the actual port with getsockname system call. But it's a bit difficult to pass the result to a user, since Server::listen method is a blocking method.

We are able to make a method like Server::get_actuall_port. But a use can call the method only on a different thread.

Another way is that we could make a method like Server::on_connected which takes a callback function where we will receive the actual port number.

I'll get back to you when I decide which solution should be taken.

from cpp-httplib.

sgraham avatar sgraham commented on May 21, 2024

Thank you for considering this request! Perhaps an on_connected() would be slightly simpler conceptually, but either of those solutions seem fine to me.

from cpp-httplib.

sgraham avatar sgraham commented on May 21, 2024

Another thought I just had... I think the port is selected by this point? https://github.com/yhirose/cpp-httplib/blob/master/httplib.h#L1413

Perhaps it would be possible to split optionally split listen() at that location, so that the user can call something like bind_to_any(), which could return the selected port, and then call listen_after_bind(). I'm not sure if that's better or worse than an optional callback though.

from cpp-httplib.

sgraham avatar sgraham commented on May 21, 2024

Something like https://github.com/yhirose/cpp-httplib/compare/master...sgraham:system-assigned-port?expand=1 is what I was thinking for above, if you like that approach.

from cpp-httplib.

yhirose avatar yhirose commented on May 21, 2024

@sgraham, your approach looks much better than mine! Could you make a pull request, so that I could merge it to my master. The only thing is the name of bind_to_any(). Could something like bind_to_any_port() be clearer to users?

from cpp-httplib.

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.