lib1522.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at https://curl.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. ***************************************************************************/
  22. #include "test.h"
  23. /* test case and code based on https://github.com/curl/curl/issues/2847 */
  24. #include "testtrace.h"
  25. #include "testutil.h"
  26. #include "warnless.h"
  27. #include "memdebug.h"
  28. static char g_Data[40 * 1024]; /* POST 40KB */
  29. static int sockopt_callback(void *clientp, curl_socket_t curlfd,
  30. curlsocktype purpose)
  31. {
  32. #if defined(SOL_SOCKET) && defined(SO_SNDBUF)
  33. int sndbufsize = 4 * 1024; /* 4KB send buffer */
  34. (void) clientp;
  35. (void) purpose;
  36. setsockopt(curlfd, SOL_SOCKET, SO_SNDBUF,
  37. (const char *)&sndbufsize, sizeof(sndbufsize));
  38. #else
  39. (void)clientp;
  40. (void)curlfd;
  41. (void)purpose;
  42. #endif
  43. return CURL_SOCKOPT_OK;
  44. }
  45. int test(char *URL)
  46. {
  47. CURLcode code;
  48. CURLcode res;
  49. struct curl_slist *pHeaderList = NULL;
  50. CURL *curl = curl_easy_init();
  51. memset(g_Data, 'A', sizeof(g_Data)); /* send As! */
  52. curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
  53. curl_easy_setopt(curl, CURLOPT_URL, URL);
  54. curl_easy_setopt(curl, CURLOPT_POSTFIELDS, g_Data);
  55. curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)sizeof(g_Data));
  56. libtest_debug_config.nohex = 1;
  57. libtest_debug_config.tracetime = 1;
  58. test_setopt(curl, CURLOPT_DEBUGDATA, &libtest_debug_config);
  59. test_setopt(curl, CURLOPT_DEBUGFUNCTION, libtest_debug_cb);
  60. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  61. /* Remove "Expect: 100-continue" */
  62. pHeaderList = curl_slist_append(pHeaderList, "Expect:");
  63. curl_easy_setopt(curl, CURLOPT_HTTPHEADER, pHeaderList);
  64. code = curl_easy_perform(curl);
  65. if(code == CURLE_OK) {
  66. curl_off_t uploadSize;
  67. curl_easy_getinfo(curl, CURLINFO_SIZE_UPLOAD_T, &uploadSize);
  68. printf("uploadSize = %ld\n", (long)uploadSize);
  69. if((size_t) uploadSize == sizeof(g_Data)) {
  70. printf("!!!!!!!!!! PASS\n");
  71. }
  72. else {
  73. printf("sent %d, libcurl says %d\n",
  74. (int)sizeof(g_Data), (int)uploadSize);
  75. }
  76. }
  77. else {
  78. printf("curl_easy_perform() failed. e = %d\n", code);
  79. }
  80. test_cleanup:
  81. curl_slist_free_all(pHeaderList);
  82. curl_easy_cleanup(curl);
  83. curl_global_cleanup();
  84. return 0;
  85. }