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

Creating an UDP server is cumbersome #289

Open
Geod24 opened this issue Aug 17, 2021 · 4 comments
Open

Creating an UDP server is cumbersome #289

Geod24 opened this issue Aug 17, 2021 · 4 comments
Labels

Comments

@Geod24
Copy link
Contributor

Geod24 commented Aug 17, 2021

Creating a TCP server is rather straightforward and documented.
However, as I tried to create an UDP server, I hit a few issues:

@Geod24
Copy link
Contributor Author

Geod24 commented Aug 17, 2021

Additionally, calling listenUDP before the event loop is running results in an invalidHandle error.
I had the following code:

    if (cmdline_args.dns)
    {
        auto udp = listenUDP(53);
        runTask({
                while (true) {
                    auto pack = udp.recv();
                    logInfo("Got packet: %s", pack);
                }
            });
    }

    return runEventLoop();

And got an error. Moving the listenUDP inside runTask cleared it.
To be precise, it seems like the UDP handle's validationCounter stays at 0 while the common is 1.

@Geod24 Geod24 added the bug label Aug 17, 2021
@mkykadir
Copy link

I've tried this recently and it seems to be working properly now.

@dushibaiyu
Copy link

dushibaiyu commented Oct 16, 2023

you shoud use listenUDP on run Task.
like this:

    if (cmdline_args.dns)
    {
        runTask({
               auto udp = listenUDP(53);
               ubyte[] buffer = cast(ubyte[]) Mallocator.instance.allocate(2048);
                scope(exit) Mallocator.instance.deallocate(cast(void[]) buffer);
                while (true) {
                    auto pack = udp.recv(buffer,null);
                    logInfo("Got packet: %s", pack);
                }
            });
    }

    return runEventLoop();

@Geod24
Copy link
Contributor Author

Geod24 commented Oct 16, 2023

If the fiber is in the same thread it should not make a difference. Also in this case I think we were saving the listener somewhere so we could shut it down when the user pressed Ctrl+C, so it wasn't actually an option.

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

No branches or pull requests

3 participants