ipkn / crow

Crow is very fast and easy to use C++ micro web framework (inspired by Python Flask)
BSD 3-Clause "New" or "Revised" License
7.43k stars 889 forks source link

get_io_service() #398

Closed dsimog01 closed 2 years ago

dsimog01 commented 2 years ago

socket_.get_io_service() seems to be deprecated, so I can't run a server using crow.

bastien8060 commented 2 years ago

Hey, you seem to be talking about file socket_adaptors.h right?

bastien8060 commented 2 years ago

You can add a macro right after the includes:

#if BOOST_VERSION >= 107000
#define GET_IO_SERVICE(s) ((boost::asio::io_context&)(s).get_executor().context())
#else
#define GET_IO_SERVICE(s) ((s).get_io_service())
#endif

Then implement it. Replace:

        boost::asio::io_service& get_io_service()
        {
            return socket_.get_io_service();
        }

with:

        boost::asio::io_service& get_io_service()
        {
            return GET_IO_SERVICE(socket_);
        }
bastien8060 commented 2 years ago

Another solution would be to use a fork. Because the maintainer of this repo is inactive, people forked it and took over the development. This one is our MVP: https://github.com/CrowCpp/crow

Everything you need in there, including updates, and fixes. I recommend you use his fixes, updates and work, instead of the code here, which is outdated. The work made by the group CrowCpp is fantastic!

dsimog01 commented 2 years ago

I am amazed. So fast and so good. The first solution you provided worked.

bastien8060 commented 2 years ago

Ah, happy for you it worked! 👍

dsimog01 commented 2 years ago

I get some errors with the repo you told me. Any ideas? image

bastien8060 commented 2 years ago

Hmm, currently looking into it. Indeed, I can reproduce the same error as you. Will get back, with a solution shortly.

The-EDev commented 2 years ago

Hi, CrowCpp/Crow requires you add #define CROW_MAIN to the top of your main cpp file. This is to avoid multiple definitions when using multiple source files (We're working to remove the need for it however).

dsimog01 commented 2 years ago

It works! Thank you!

bastien8060 commented 2 years ago

Hi, CrowCpp/Crow requires you add #define CROW_MAIN to the top of your main cpp file. This is to avoid multiple definitions when using multiple source files (We're working to remove the need for it however).

You beat me to it :). I had just found https://github.com/CrowCpp/Crow/issues/150