2
0

lib1522.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2019, 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.haxx.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 "testutil.h"
  25. #include "warnless.h"
  26. #include "memdebug.h"
  27. static char g_Data[40 * 1024]; /* POST 40KB */
  28. static int sockopt_callback(void *clientp, curl_socket_t curlfd,
  29. curlsocktype purpose)
  30. {
  31. #if defined(SOL_SOCKET) && defined(SO_SNDBUF)
  32. int sndbufsize = 4 * 1024; /* 4KB send buffer */
  33. (void) clientp;
  34. (void) purpose;
  35. setsockopt(curlfd, SOL_SOCKET, SO_SNDBUF,
  36. (const char *)&sndbufsize, sizeof(sndbufsize));
  37. #else
  38. (void)clientp;
  39. (void)curlfd;
  40. (void)purpose;
  41. #endif
  42. return CURL_SOCKOPT_OK;
  43. }
  44. int test(char *URL)
  45. {
  46. CURLcode code;
  47. struct curl_slist *pHeaderList = NULL;
  48. CURL *pCurl = curl_easy_init();
  49. memset(g_Data, 'A', sizeof(g_Data)); /* send As! */
  50. curl_easy_setopt(pCurl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
  51. curl_easy_setopt(pCurl, CURLOPT_URL, URL);
  52. curl_easy_setopt(pCurl, CURLOPT_POSTFIELDS, g_Data);
  53. curl_easy_setopt(pCurl, CURLOPT_POSTFIELDSIZE, (long)sizeof(g_Data));
  54. /* Remove "Expect: 100-continue" */
  55. pHeaderList = curl_slist_append(pHeaderList, "Expect:");
  56. curl_easy_setopt(pCurl, CURLOPT_HTTPHEADER, pHeaderList);
  57. code = curl_easy_perform(pCurl);
  58. if(code == CURLE_OK) {
  59. curl_off_t uploadSize;
  60. curl_easy_getinfo(pCurl, CURLINFO_SIZE_UPLOAD_T, &uploadSize);
  61. printf("uploadSize = %ld\n", (long)uploadSize);
  62. if((size_t) uploadSize == sizeof(g_Data)) {
  63. printf("!!!!!!!!!! PASS\n");
  64. }
  65. else {
  66. printf("!!!!!!!!!! FAIL\n");
  67. }
  68. }
  69. else {
  70. printf("curl_easy_perform() failed. e = %d\n", code);
  71. }
  72. curl_slist_free_all(pHeaderList);
  73. curl_easy_cleanup(pCurl);
  74. curl_global_cleanup();
  75. return 0;
  76. }