skypjack / uvw

Header-only, event based, tiny and easy to use libuv wrapper in modern C++ - now available as also shared/static library!
MIT License
1.82k stars 207 forks source link

48 error #283

Closed andrey231 closed 1 year ago

andrey231 commented 1 year ago

Hello, what's my mistake? I use visual studio community edition 2022, c++17

  1. vcpkg install uvw:x64-windows
  2. Include directories - C:\Users\andre\vcpkg\packages\uvw_x64-windows\include;C:\Users\andre\vcpkg\packages\libuv_x64-windows\include;$(IncludePath)
  3. Library directories - C:\Users\andre\vcpkg\packages\libuv_x64-windows\lib;$(LibraryPath)
  4. Additional dependencies - uv.lib;%(AdditionalDependencies)
  5. Run code example
#include <uvw.hpp>
#include <memory>

void listen(uvw::loop &loop) {
    std::shared_ptr<uvw::tcp_handle> tcp = loop.resource<uvw::tcp_handle>();

    tcp->once<uvw::listen_event>([](const uvw::listen_event &, uvw::tcp_handle &srv) {
        std::shared_ptr<uvw::tcp_handle> client = srv.parent().resource<uvw::tcp_handle>();

        client->on<uvw::close_event>([ptr = srv.shared_from_this()](const uvw::close_event &, uvw::tcp_handle &) { ptr->close(); });
        client->on<uvw::end_event>([](const uvw::end_event &, uvw::tcp_handle &client) { client.close(); });

        srv.accept(*client);
        client->read();
    });

    tcp->bind("127.0.0.1", 4242);
    tcp->listen();
}

void conn(uvw::loop &loop) {
    auto tcp = loop.resource<uvw::tcp_handle>();

    tcp->on<uvw::error_event>([](const uvw::error_event &, uvw::tcp_handle &) { /* handle errors */ });

    tcp->once<uvw::connect_event>([](const uvw::connect_event &, uvw::tcp_handle &tcp) {
        auto dataWrite = std::unique_ptr<char[]>(new char[2]{ 'b', 'c' });
        tcp.write(std::move(dataWrite), 2);
        tcp.close();
    });

    tcp->connect(std::string{"127.0.0.1"}, 4242);
}

int main() {
    auto loop = uvw::loop::get_default();
    listen(*loop);
    conn(*loop);
    loop->run();
}
  1. I get 48 errors

Severity Code Description Project File Line Suppression State Error C2146 syntax error: missing ';' before identifier 'once' ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 7
Error C2146 syntax error: missing ';' before identifier 'listen' ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 18
Error C2146 syntax error: missing ';' before identifier 'bind' ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 17
Error C2143 syntax error: missing ';' before '}' ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 19
Error C2143 syntax error: missing ';' before '{' ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 4
Error C2143 syntax error: missing ';' before '{' ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 7
Error C2143 syntax error: missing ';' before '{' ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 21
Error C2143 syntax error: missing ')' before ';' ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 7
Error C2059 syntax error: '}' ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 19
Error C2059 syntax error: ')' ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 5
Error C2059 syntax error: ')' ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 15
Error (active) E0135 namespace "uvw" has no member "loop" ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 4
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 7
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 17
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 18
Error C3613 missing return type after '->' ('int' assumed) ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 7
Error C3613 missing return type after '->' ('int' assumed) ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 17
Error C3613 missing return type after '->' ('int' assumed) ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 18
Error (active) E0020 identifier "loop" is undefined ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 4
Error (active) E0065 expected a ';' ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 4
Error C2447 '{': missing function header (old-style formal list?) ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 7
Error C2447 '{': missing function header (old-style formal list?) ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 21
Error C2065 'tcp_handle': undeclared identifier ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 5
Error C2065 'tcp_handle': undeclared identifier ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 5
Error C2039 'tcp_handle': is not a member of 'uvw' ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 5
Error C2039 'tcp_handle': is not a member of 'uvw' ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 5
Error C2039 'tcp_handle': is not a member of 'uvw' ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 7
Error C2371 'tcp': redefinition; different basic types ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 7
Error C2371 'tcp': redefinition; different basic types ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 17
Error C2371 'tcp': redefinition; different basic types ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 18
Error C2923 'std::shared_ptr': 'tcp_handle' is not a valid template type argument for parameter '_Ty' ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 5
Error C2065 'loop': undeclared identifier ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 4
Error C2065 'loop': undeclared identifier ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 4
Error C2065 'loop': undeclared identifier ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 5
Error C3083 'loop': the symbol to the left of a '::' must be a type ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 36
Error C2039 'loop': is not a member of 'uvw' ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 4
Error C2039 'loop': is not a member of 'uvw' ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 21
Error C2039 'listen_event': is not a member of 'uvw' ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 7
Error C2039 'listen_event': is not a member of 'uvw' ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 7
Error C2182 'listen': this use of 'void' is not valid ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 4
Error C2365 'listen': redefinition; previous definition was 'function' ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 4
Error C2660 'listen': function does not take 1 arguments ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 37
Error C2039 'get_default': is not a member of 'uvw' ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 36
Error C3861 'get_default': identifier not found ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 36
Error C3861 'conn': identifier not found ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 38
Error C3927 '->': trailing return type is not allowed after a non-function declarator ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 7
Error C3927 '->': trailing return type is not allowed after a non-function declarator ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 17
Error C3927 '->': trailing return type is not allowed after a non-function declarator ServerTest C:\Users\andre\source\repos\ServerTest\ServerTest\main.cpp 18

skypjack commented 1 year ago

It's not tcp->once, it's tcp->on. I just realized that there is a typo in the example. The updated version works just fine locally with VS and C++17.