summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubomir Rintel <lkundrak@v3.sk>2017-03-22 15:36:50 +0100
committerLubomir Rintel <lkundrak@v3.sk>2017-03-22 18:52:56 +0000
commitd7e470b0aa651695034219a07dd39364e0ddb602 (patch)
tree6c1e1a8d4376c4a1306bf03209df72fdc36aa61f
parentac0f454cfb69cfc7c8709a8c66bf7b517f377793 (diff)
downloadNetworkManager-d7e470b0aa651695034219a07dd39364e0ddb602.tar.gz
connectivity: conclude the check as soon as we see enough bytes
No need to read the full response into memory.
-rw-r--r--src/nm-connectivity.c40
1 files changed, 23 insertions, 17 deletions
diff --git a/src/nm-connectivity.c b/src/nm-connectivity.c
index 11659acdf1..0e70e249ca 100644
--- a/src/nm-connectivity.c
+++ b/src/nm-connectivity.c
@@ -246,7 +246,6 @@ finish_cb_data (ConCheckCbData *cb_data, NMConnectivityState new_state)
static void
curl_check_connectivity (CURLM *mhandle, CURLMcode ret)
{
- NMConnectivityState new_state = NM_CONNECTIVITY_UNKNOWN;
ConCheckCbData *cb_data;
CURLMsg *msg;
CURLcode eret;
@@ -269,24 +268,18 @@ curl_check_connectivity (CURLM *mhandle, CURLMcode ret)
}
if (cb_data) {
- if (msg->data.result != CURLE_OK) {
+ /* If cb_data is still there this message hasn't been
+ * taken care of. Do so now. */
+ if (msg->data.result == CURLE_OK) {
+ /* If we get here, it means that easy_write_cb() didn't read enough
+ * bytes to be able to do a match. */
+ _LOGI ("Check for uri '%s' returned a shorter response than expected '%s'; assuming captive portal.",
+ cb_data->uri, cb_data->response);
+ finish_cb_data (cb_data, NM_CONNECTIVITY_PORTAL);
+ } else {
_LOGD ("Check for uri '%s' failed", cb_data->uri);
- new_state = NM_CONNECTIVITY_LIMITED;
- goto cleanup;
+ finish_cb_data (cb_data, NM_CONNECTIVITY_LIMITED);
}
-
- /* Check response */
- if (cb_data->msg && g_str_has_prefix (cb_data->msg, cb_data->response)) {
- _LOGD ("Check for uri '%s' successful.", cb_data->uri);
- new_state = NM_CONNECTIVITY_FULL;
- goto cleanup;
- }
-
- _LOGI ("Check for uri '%s' did not match expected response '%s'; assuming captive portal.",
- cb_data->uri, cb_data->response);
- new_state = NM_CONNECTIVITY_PORTAL;
-cleanup:
- finish_cb_data (cb_data, new_state);
}
curl_multi_remove_handle (mhandle, msg->easy_handle);
@@ -427,6 +420,19 @@ easy_write_cb (void *buffer, size_t size, size_t nmemb, void *userdata)
memcpy (cb_data->msg + cb_data->msg_size, buffer, len);
cb_data->msg_size += len;
+ if (cb_data->msg_size >= strlen (cb_data->response)) {
+ /* We already have enough data -- check response */
+ if (g_str_has_prefix (cb_data->msg, cb_data->response)) {
+ _LOGD ("Check for uri '%s' successful.", cb_data->uri);
+ finish_cb_data (cb_data, NM_CONNECTIVITY_FULL);
+ } else {
+ _LOGI ("Check for uri '%s' did not match expected response '%s'; assuming captive portal.",
+ cb_data->uri, cb_data->response);
+ finish_cb_data (cb_data, NM_CONNECTIVITY_PORTAL);
+ }
+ return 0;
+ }
+
return len;
}
#endif