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

About hub.connect on windows run as blocking mode on uWebSocket #7

Closed
Furujiang opened this issue Aug 29, 2018 · 5 comments
Closed
Labels

Comments

@Furujiang
Copy link

Hi I could not find a place to quest under uWebsocket, so I post it here:
On winodws 10, while calling hub.connect to wws, it will block several seconds.
if I add predefine SOCK_CLOEXEC;SOCK_NONBLOCK; to project, error occured with identifier "accept4" not found error.

I am using the hub to connect to multi wws, so I need this "connect" function excute as nonblocking, could you please advice?
thank you!

@ghost
Copy link

ghost commented Aug 29, 2018

It blocks on DNS lookup, that's the only thing blocking. It's a valid issue for uSockets too, I haven't solved it yet. DNS lookup should happen in a thread pool.

@ghost ghost added the bug label Aug 29, 2018
@Furujiang
Copy link
Author

Thank you for quick response, I changed my design to use uws in multithread because I found it don't work for creating multi group and make connect calls, only last connect call works.
It works well in each thread for 1 hub. Thank you again!

@ghost
Copy link

ghost commented Aug 30, 2018

You shouldn't hack with threading. If you require nonblocking DNS lookup then do that part yourself with a third party library and pass the IP to connect

@Furujiang
Copy link
Author

the main problem for single thread is: below code only connect to url2 will work fine, no callback recieved from url1, is this a bug? thank you!

sample code:
hub_ = new Hub();
group1 = hub_->createGroup();
group1->onConnection([&](WebSocket *ws, HttpRequest req) {xxx});
group1->onError([&](void * self) {xxx};
group1->onDisconnection([&](WebSocket *ws, int code, char *data, size_t length) {xxx});
hub_->connect(url_1, nullptr, {}, 5000, group1);

group2 = hub_->createGroup();
group2->onConnection([&](WebSocket *ws, HttpRequest req) {xxx});
group2->onError([&](void * self) {xxx};
group2->onDisconnection([&](WebSocket *ws, int code, char *data, size_t length) {xxx});
hub_->connect(url_2, nullptr, {}, 5000, group2);
hub->run();

@ghost
Copy link

ghost commented Aug 31, 2018

Well since the first connection will block on DNS resolution the second connection might time out? Both should work.

This issue was closed.
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

1 participant