-
Notifications
You must be signed in to change notification settings - Fork 164
Make DNS operations non-blocking when using c-ares #261
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,22 +57,19 @@ | |
| #include "strophe.h" | ||
| #include "common.h" | ||
| #include "parser.h" | ||
| #include "resolver.h" | ||
|
|
||
| #ifndef STROPHE_MESSAGE_BUFFER_SIZE | ||
| /** Max buffer size for receiving messages. */ | ||
| #define STROPHE_MESSAGE_BUFFER_SIZE 4096 | ||
| #endif | ||
|
|
||
| static int _connect_next(xmpp_conn_t *conn) | ||
| static void _connect_next(xmpp_conn_t *conn) | ||
| { | ||
| sock_close(conn->sock); | ||
| conn->sock = sock_connect(conn->xsock); | ||
| if (conn->sock == INVALID_SOCKET) | ||
| return -1; | ||
|
|
||
| conn->sock = INVALID_SOCKET; | ||
| conn->timeout_stamp = time_stamp(); | ||
|
|
||
| return 0; | ||
| sock_connect(conn->xsock); | ||
| } | ||
|
|
||
| /** Run the event loop once. | ||
|
|
@@ -220,17 +217,14 @@ void xmpp_run_once(xmpp_ctx_t *ctx, unsigned long timeout) | |
|
|
||
| /* make sure the timeout hasn't expired */ | ||
| if (time_elapsed(conn->timeout_stamp, time_stamp()) <= | ||
| conn->connect_timeout) | ||
| FD_SET(conn->sock, &wfds); | ||
| else { | ||
| conn->connect_timeout) { | ||
| if (conn->sock != INVALID_SOCKET) | ||
| FD_SET(conn->sock, &wfds); | ||
| } else { | ||
| strophe_info(ctx, "xmpp", "Connection attempt timed out."); | ||
| ret = _connect_next(conn); | ||
| if (ret != 0) { | ||
| conn->error = ETIMEDOUT; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as written, this error is no longer produced and will always end up as XMPP_EINT instead |
||
| conn_disconnect(conn); | ||
| } else { | ||
| _connect_next(conn); | ||
| if (conn->sock != INVALID_SOCKET) | ||
| FD_SET(conn->sock, &wfds); | ||
| } | ||
| } | ||
| break; | ||
| case XMPP_STATE_CONNECTED: | ||
|
|
@@ -254,6 +248,15 @@ void xmpp_run_once(xmpp_ctx_t *ctx, unsigned long timeout) | |
| connitem = connitem->next; | ||
| } | ||
|
|
||
| #ifdef HAVE_CARES | ||
| if (ares_chan) { | ||
| int ares_max = ares_fds(ares_chan, &rfds, &wfds); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, shouldn't one of these new constructs be used then? Just to be clear: I'm only looking at the c-ares header&source files and don't have any experience with it (yet).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if (ares_max > max) | ||
| max = ares_max; | ||
| ares_timeout(ares_chan, &tv, &tv); | ||
| } | ||
| #endif | ||
|
|
||
| /* check for events */ | ||
| if (max > 0) | ||
| ret = select(max + 1, &rfds, &wfds, NULL, &tv); | ||
|
|
@@ -271,6 +274,11 @@ void xmpp_run_once(xmpp_ctx_t *ctx, unsigned long timeout) | |
| return; | ||
| } | ||
|
|
||
| #ifdef HAVE_CARES | ||
| if (ares_chan) | ||
| ares_process(ares_chan, &rfds, &wfds); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
| #endif | ||
|
|
||
| /* no events happened */ | ||
| if (ret == 0 && tls_read_bytes == 0) | ||
| return; | ||
|
|
@@ -292,11 +300,7 @@ void xmpp_run_once(xmpp_ctx_t *ctx, unsigned long timeout) | |
| /* connection failed */ | ||
| strophe_debug(ctx, "xmpp", "connection failed, error %d", | ||
| ret); | ||
| ret = _connect_next(conn); | ||
| if (ret != 0) { | ||
| conn->error = ret; | ||
| conn_disconnect(conn); | ||
| } | ||
| _connect_next(conn); | ||
| break; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this happens as part of
sock_newnow