aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-11-15 09:04:47 +0100
committerChristian Grothoff <christian@grothoff.org>2021-11-15 09:04:54 +0100
commit72d1c2620982a253ad5450d18cc79b3a2b7f21af (patch)
tree0823900b22bc53ccddcf2400365af5cbcda1b53a /src
parentd06c9fa38337c454e0144fccd892f7353c533eef (diff)
downloadgnunet-72d1c2620982a253ad5450d18cc79b3a2b7f21af.tar.gz
gnunet-72d1c2620982a253ad5450d18cc79b3a2b7f21af.zip
-indent
Diffstat (limited to 'src')
-rw-r--r--src/curl/curl.c118
1 files changed, 76 insertions, 42 deletions
diff --git a/src/curl/curl.c b/src/curl/curl.c
index 71672c780..30c2f8c01 100644
--- a/src/curl/curl.c
+++ b/src/curl/curl.c
@@ -368,7 +368,8 @@ download_cb (char *bufptr,
368 db->eno = ENOMEM; 368 db->eno = ENOMEM;
369 return 0; /* signals an error to curl */ 369 return 0; /* signals an error to curl */
370 } 370 }
371 db->buf = GNUNET_realloc (db->buf, db->buf_size + msize); 371 db->buf = GNUNET_realloc (db->buf,
372 db->buf_size + msize);
372 buf = db->buf + db->buf_size; 373 buf = db->buf + db->buf_size;
373 GNUNET_memcpy (buf, bufptr, msize); 374 GNUNET_memcpy (buf, bufptr, msize);
374 db->buf_size += msize; 375 db->buf_size += msize;
@@ -421,7 +422,8 @@ setup_job_headers (struct GNUNET_CURL_Context *ctx,
421 &scope.scope_id, 422 &scope.scope_id,
422 sizeof(struct GNUNET_AsyncScopeId)); 423 sizeof(struct GNUNET_AsyncScopeId));
423 GNUNET_assert (NULL != aid_header); 424 GNUNET_assert (NULL != aid_header);
424 GNUNET_assert (NULL != curl_slist_append (all_headers, aid_header)); 425 GNUNET_assert (NULL != curl_slist_append (all_headers,
426 aid_header));
425 GNUNET_free (aid_header); 427 GNUNET_free (aid_header);
426 } 428 }
427 } 429 }
@@ -455,12 +457,25 @@ setup_job (CURL *eh,
455 job = GNUNET_new (struct GNUNET_CURL_Job); 457 job = GNUNET_new (struct GNUNET_CURL_Job);
456 job->job_headers = all_headers; 458 job->job_headers = all_headers;
457 459
458 if ((CURLE_OK != curl_easy_setopt (eh, CURLOPT_PRIVATE, job)) || 460 if ( (CURLE_OK !=
459 (CURLE_OK != 461 curl_easy_setopt (eh,
460 curl_easy_setopt (eh, CURLOPT_WRITEFUNCTION, &download_cb)) || 462 CURLOPT_PRIVATE,
461 (CURLE_OK != curl_easy_setopt (eh, CURLOPT_WRITEDATA, &job->db)) || 463 job)) ||
462 (CURLE_OK != curl_easy_setopt (eh, CURLOPT_SHARE, ctx->share)) || 464 (CURLE_OK !=
463 (CURLM_OK != curl_multi_add_handle (ctx->multi, eh))) 465 curl_easy_setopt (eh,
466 CURLOPT_WRITEFUNCTION,
467 &download_cb)) ||
468 (CURLE_OK !=
469 curl_easy_setopt (eh,
470 CURLOPT_WRITEDATA,
471 &job->db)) ||
472 (CURLE_OK !=
473 curl_easy_setopt (eh,
474 CURLOPT_SHARE,
475 ctx->share)) ||
476 (CURLM_OK !=
477 curl_multi_add_handle (ctx->multi,
478 eh)) )
464 { 479 {
465 GNUNET_break (0); 480 GNUNET_break (0);
466 GNUNET_free (job); 481 GNUNET_free (job);
@@ -683,9 +698,12 @@ GNUNET_CURL_job_cancel (struct GNUNET_CURL_Job *job)
683{ 698{
684 struct GNUNET_CURL_Context *ctx = job->ctx; 699 struct GNUNET_CURL_Context *ctx = job->ctx;
685 700
686 GNUNET_CONTAINER_DLL_remove (ctx->jobs_head, ctx->jobs_tail, job); 701 GNUNET_CONTAINER_DLL_remove (ctx->jobs_head,
702 ctx->jobs_tail,
703 job);
687 GNUNET_break (CURLM_OK == 704 GNUNET_break (CURLM_OK ==
688 curl_multi_remove_handle (ctx->multi, job->easy_handle)); 705 curl_multi_remove_handle (ctx->multi,
706 job->easy_handle));
689 curl_easy_cleanup (job->easy_handle); 707 curl_easy_cleanup (job->easy_handle);
690 GNUNET_free (job->db.buf); 708 GNUNET_free (job->db.buf);
691 curl_slist_free_all (job->job_headers); 709 curl_slist_free_all (job->job_headers);
@@ -831,7 +849,8 @@ enum GNUNET_GenericReturnValue
831GNUNET_CURL_append_header (struct GNUNET_CURL_Context *ctx, 849GNUNET_CURL_append_header (struct GNUNET_CURL_Context *ctx,
832 const char *header) 850 const char *header)
833{ 851{
834 ctx->common_headers = curl_slist_append (ctx->common_headers, header); 852 ctx->common_headers = curl_slist_append (ctx->common_headers,
853 header);
835 if (NULL == ctx->common_headers) 854 if (NULL == ctx->common_headers)
836 return GNUNET_SYSERR; 855 return GNUNET_SYSERR;
837 856
@@ -854,40 +873,46 @@ do_benchmark (CURLMsg *cmsg)
854 uint64_t bytes_sent = 0; 873 uint64_t bytes_sent = 0;
855 uint64_t bytes_received = 0; 874 uint64_t bytes_received = 0;
856 875
857 GNUNET_break (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle, 876 GNUNET_break (CURLE_OK ==
858 CURLINFO_TOTAL_TIME, 877 curl_easy_getinfo (cmsg->easy_handle,
859 &total_as_double)); 878 CURLINFO_TOTAL_TIME,
879 &total_as_double));
860 total.rel_value_us = total_as_double * 1000 * 1000; 880 total.rel_value_us = total_as_double * 1000 * 1000;
861 881
862 GNUNET_break (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle, 882 GNUNET_break (CURLE_OK ==
863 CURLINFO_EFFECTIVE_URL, 883 curl_easy_getinfo (cmsg->easy_handle,
864 &url)); 884 CURLINFO_EFFECTIVE_URL,
885 &url));
865 886
866 /* HEADER_SIZE + SIZE_DOWNLOAD_T is hopefully the total 887 /* HEADER_SIZE + SIZE_DOWNLOAD_T is hopefully the total
867 number of bytes received, not clear from curl docs. */ 888 number of bytes received, not clear from curl docs. */
868 889
869 GNUNET_break (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle, 890 GNUNET_break (CURLE_OK ==
870 CURLINFO_HEADER_SIZE, 891 curl_easy_getinfo (cmsg->easy_handle,
871 &size_long)); 892 CURLINFO_HEADER_SIZE,
893 &size_long));
872 bytes_received += size_long; 894 bytes_received += size_long;
873 895
874 GNUNET_break (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle, 896 GNUNET_break (CURLE_OK ==
875 CURLINFO_SIZE_DOWNLOAD_T, 897 curl_easy_getinfo (cmsg->easy_handle,
876 &size_curl)); 898 CURLINFO_SIZE_DOWNLOAD_T,
899 &size_curl));
877 bytes_received += size_curl; 900 bytes_received += size_curl;
878 901
879 /* REQUEST_SIZE + SIZE_UPLOAD_T is hopefully the total number of bytes 902 /* REQUEST_SIZE + SIZE_UPLOAD_T is hopefully the total number of bytes
880 sent, again docs are not completely clear. */ 903 sent, again docs are not completely clear. */
881 904
882 GNUNET_break (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle, 905 GNUNET_break (CURLE_OK ==
883 CURLINFO_REQUEST_SIZE, 906 curl_easy_getinfo (cmsg->easy_handle,
884 &size_long)); 907 CURLINFO_REQUEST_SIZE,
908 &size_long));
885 bytes_sent += size_long; 909 bytes_sent += size_long;
886 910
887 /* We obtain this value to check an invariant, but never use it otherwise. */ 911 /* We obtain this value to check an invariant, but never use it otherwise. */
888 GNUNET_break (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle, 912 GNUNET_break (CURLE_OK ==
889 CURLINFO_SIZE_UPLOAD_T, 913 curl_easy_getinfo (cmsg->easy_handle,
890 &size_curl)); 914 CURLINFO_SIZE_UPLOAD_T,
915 &size_curl));
891 916
892 /* CURLINFO_SIZE_UPLOAD_T <= CURLINFO_REQUEST_SIZE should 917 /* CURLINFO_SIZE_UPLOAD_T <= CURLINFO_REQUEST_SIZE should
893 be an invariant. 918 be an invariant.
@@ -900,8 +925,10 @@ do_benchmark (CURLMsg *cmsg)
900 925
901 urd = get_url_benchmark_data (url, (unsigned int) response_code); 926 urd = get_url_benchmark_data (url, (unsigned int) response_code);
902 urd->count++; 927 urd->count++;
903 urd->time = GNUNET_TIME_relative_add (urd->time, total); 928 urd->time = GNUNET_TIME_relative_add (urd->time,
904 urd->time_max = GNUNET_TIME_relative_max (total, urd->time_max); 929 total);
930 urd->time_max = GNUNET_TIME_relative_max (total,
931 urd->time_max);
905 urd->bytes_sent += bytes_sent; 932 urd->bytes_sent += bytes_sent;
906 urd->bytes_received += bytes_received; 933 urd->bytes_received += bytes_received;
907} 934}
@@ -929,7 +956,8 @@ GNUNET_CURL_perform2 (struct GNUNET_CURL_Context *ctx,
929 956
930 (void) curl_multi_perform (ctx->multi, 957 (void) curl_multi_perform (ctx->multi,
931 &n_running); 958 &n_running);
932 while (NULL != (cmsg = curl_multi_info_read (ctx->multi, &n_completed))) 959 while (NULL != (cmsg = curl_multi_info_read (ctx->multi,
960 &n_completed)))
933 { 961 {
934 struct GNUNET_CURL_Job *job; 962 struct GNUNET_CURL_Job *job;
935 long response_code; 963 long response_code;
@@ -937,9 +965,10 @@ GNUNET_CURL_perform2 (struct GNUNET_CURL_Context *ctx,
937 965
938 /* Only documented return value is CURLMSG_DONE */ 966 /* Only documented return value is CURLMSG_DONE */
939 GNUNET_break (CURLMSG_DONE == cmsg->msg); 967 GNUNET_break (CURLMSG_DONE == cmsg->msg);
940 GNUNET_assert (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle, 968 GNUNET_assert (CURLE_OK ==
941 CURLINFO_PRIVATE, 969 curl_easy_getinfo (cmsg->easy_handle,
942 (char **) &job)); 970 CURLINFO_PRIVATE,
971 (char **) &job));
943 GNUNET_assert (job->ctx == ctx); 972 GNUNET_assert (job->ctx == ctx);
944 response_code = 0; 973 response_code = 0;
945 if (NULL != job->jcc_raw) 974 if (NULL != job->jcc_raw)
@@ -1027,14 +1056,17 @@ GNUNET_CURL_get_select_info (struct GNUNET_CURL_Context *ctx,
1027 int m; 1056 int m;
1028 1057
1029 m = -1; 1058 m = -1;
1030 GNUNET_assert (CURLM_OK == curl_multi_fdset (ctx->multi, 1059 GNUNET_assert (CURLM_OK ==
1031 read_fd_set, 1060 curl_multi_fdset (ctx->multi,
1032 write_fd_set, 1061 read_fd_set,
1033 except_fd_set, 1062 write_fd_set,
1034 &m)); 1063 except_fd_set,
1064 &m));
1035 to = *timeout; 1065 to = *timeout;
1036 *max_fd = GNUNET_MAX (m, *max_fd); 1066 *max_fd = GNUNET_MAX (m, *max_fd);
1037 GNUNET_assert (CURLM_OK == curl_multi_timeout (ctx->multi, &to)); 1067 GNUNET_assert (CURLM_OK ==
1068 curl_multi_timeout (ctx->multi,
1069 &to));
1038 1070
1039 /* Only if what we got back from curl is smaller than what we 1071 /* Only if what we got back from curl is smaller than what we
1040 already had (-1 == infinity!), then update timeout */ 1072 already had (-1 == infinity!), then update timeout */
@@ -1079,7 +1111,9 @@ GNUNET_CURL_constructor__ (void)
1079 1111
1080 if (CURLE_OK != (ret = curl_global_init (CURL_GLOBAL_DEFAULT))) 1112 if (CURLE_OK != (ret = curl_global_init (CURL_GLOBAL_DEFAULT)))
1081 { 1113 {
1082 CURL_STRERROR (GNUNET_ERROR_TYPE_ERROR, "curl_global_init", ret); 1114 CURL_STRERROR (GNUNET_ERROR_TYPE_ERROR,
1115 "curl_global_init",
1116 ret);
1083 curl_fail = 1; 1117 curl_fail = 1;
1084 } 1118 }
1085} 1119}