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

tcp.bind and tcp.listen always failed if settimeout(0). #412

Open
jakitliang opened this issue Sep 30, 2023 · 0 comments
Open

tcp.bind and tcp.listen always failed if settimeout(0). #412

jakitliang opened this issue Sep 30, 2023 · 0 comments

Comments

@jakitliang
Copy link

jakitliang commented Sep 30, 2023

As known to all. int bind(...) is an immediately completion function.

int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);

bind is not an async function but luasocket stupidly make it async

But luasocket needs set timeout(n) n > 0 to finish a simple bind.

Why do a bind need so much seconds?

And also tcp.listen is also an immediately completion function:

int listen(int sockfd, int backlog);

You just:

if (listen(&fd, 100) == -1)

to check the result immediately.

What does luasocket timeout for?

I GUESS the reason why luasocket is always failed coz using a stupid Thread way to do a dead easy bind:

void socked_bind() {
  auto ret = std::thread([]{
     return bind(fd, ...);
  })

  return ret
}

So the Lua side set timeout(0) means not to wait this thread and use the ret as result. And not doing Thread.join(ret).

So the bind procedure is released and failed.

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

No branches or pull requests

1 participant