Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The echo UDP server example does not compile against package installed by vcpkg. #293

Open
denismakogon opened this issue Oct 20, 2022 · 3 comments

Comments

@denismakogon
Copy link

CMakeLists.txt:

cmake_minimum_required (VERSION 3.24)

project (udplib LANGUAGES C CXX VERSION 0.0.1 DESCRIPTION "udplib")

set (CMAKE_CXX_STANDARD 20)

add_executable(${PROJECT_NAME} src/main.cc ${HEADERS})

find_package(unofficial-evpp CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE unofficial::evpp::evpp_static)

code:

#include <stdio.h>

#include <evpp/udp/udp_message.h>
#include <evpp/event_loop.h>
#include <evpp/event_loop_thread_pool.h>

int main(int argc, char* argv[]) {
    std::vector<int> ports = { 1053, 5353 };
    int port = 29099;
    int thread_num = 2;

    if (argc > 1) {
        if (std::string("-h") == argv[1] ||
            std::string("--h") == argv[1] ||
            std::string("-help") == argv[1] ||
            std::string("--help") == argv[1]) {
            std::cout << "usage : " << argv[0] << " <listen_port> <thread_num>\n";
            std::cout << " e.g. : " << argv[0] << " 8080 24\n";
            return 0;
        }
    }

    if (argc == 2) {
        port = atoi(argv[1]);
    }
    ports.push_back(port);

    if (argc == 3) {
        port = atoi(argv[1]);
        thread_num = atoi(argv[2]);
    }

    evpp::udp::Server server;
    server.SetThreadDispatchPolicy(evpp::ThreadDispatchPolicy::kIPAddressHashing);
    server.SetMessageHandler([](evpp::EventLoop* loop, evpp::udp::MessagePtr& msg) {
        std::stringstream oss;
        oss << "func=" << __FUNCTION__ << " OK"
            << " body=" << std::string(msg->data(), msg->size()) << "\n";
        evpp::udp::SendMessage(msg);
    });
    server.Init(ports);
    server.Start();

    evpp::EventLoop loop;
    std::shared_ptr<evpp::EventLoopThreadPool> tpool(new evpp::EventLoopThreadPool(&loop, thread_num));
    tpool->Start(true);
    server.SetEventLoopThreadPool(tpool);
    loop.Run();
    server.Stop(true);
    tpool->Stop(true);
    return 0;
}

errors:

[ 50%] Building CXX object CMakeFiles/udplib.dir/src/main.cc.o
/Users/denismakogon/go/src/github.com/denismakogon/udplib/src/main.cc:33:16: error: no type named 'Server' in namespace 'evpp::udp'
    evpp::udp::Server server;
    ~~~~~~~~~~~^
/Users/denismakogon/go/src/github.com/denismakogon/udplib/src/main.cc:34:42: error: no member named 'ThreadDispatchPolicy' in namespace 'evpp'
    server.SetThreadDispatchPolicy(evpp::ThreadDispatchPolicy::kIPAddressHashing);
                                   ~~~~~~^
2 errors generated.
make[2]: *** [CMakeFiles/udplib.dir/src/main.cc.o] Error 1
make[1]: *** [CMakeFiles/udplib.dir/all] Error 2
make: *** [all] Error 2
@jinguoli
Copy link
Collaborator

add #include <evpp/udp/udp_server.h> to the main.cc

@denismakogon
Copy link
Author

@jinguoli Hey, thank you for the reply. It indeed helped to build a binary, but now I'm having another issue:

./udplib 8080 24
WARNING: Logging before InitGoogleLogging() is written to STDERR
I20221021 13:36:36.108130 5764915 inner_pre.cc:27] ignore SIGPIPE
E20221021 13:36:36.109118 5764915 sockets.cc:89] socket bind error=22 Invalid argument
E20221021 13:36:36.109143 5764915 udp_server.cc:41] listen error
Assertion failed: (ret), function Init, file udp_server.cc, line 111.

I'm on macOS 12.6[M1].

@denismakogon
Copy link
Author

@jinguoli any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants