诸暨麻将添加redis
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

168 lines
4.5 KiB

  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2013, 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 http://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. #include "testutil.h"
  24. #include "warnless.h"
  25. #include "memdebug.h"
  26. /*
  27. * This is the list of basic details you need to tweak to get things right.
  28. */
  29. #define USERNAME "user@example.com"
  30. #define PASSWORD "123qwerty"
  31. #define RECIPIENT "<1507-recipient@example.com>"
  32. #define MAILFROM "<1507-realuser@example.com>"
  33. #define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000
  34. static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
  35. {
  36. (void)ptr;
  37. (void)size;
  38. (void)nmemb;
  39. (void)userp;
  40. return CURL_READFUNC_ABORT;
  41. }
  42. static struct timeval tvnow(void)
  43. {
  44. /*
  45. ** time() returns the value of time in seconds since the Epoch.
  46. */
  47. struct timeval now;
  48. now.tv_sec = (long)time(NULL);
  49. now.tv_usec = 0;
  50. return now;
  51. }
  52. static long tvdiff(struct timeval newer, struct timeval older)
  53. {
  54. return (newer.tv_sec-older.tv_sec)*1000+
  55. (newer.tv_usec-older.tv_usec)/1000;
  56. }
  57. int test(char *URL)
  58. {
  59. CURL *curl;
  60. CURLM *mcurl;
  61. int still_running = 1;
  62. struct timeval mp_start;
  63. struct curl_slist* rcpt_list = NULL;
  64. curl_global_init(CURL_GLOBAL_DEFAULT);
  65. curl = curl_easy_init();
  66. if(!curl)
  67. return 1;
  68. mcurl = curl_multi_init();
  69. if(!mcurl)
  70. return 2;
  71. rcpt_list = curl_slist_append(rcpt_list, RECIPIENT);
  72. /* more addresses can be added here
  73. rcpt_list = curl_slist_append(rcpt_list, "<others@example.com>");
  74. */
  75. curl_easy_setopt(curl, CURLOPT_URL, URL);
  76. #if 0
  77. curl_easy_setopt(curl, CURLOPT_USERNAME, USERNAME);
  78. curl_easy_setopt(curl, CURLOPT_PASSWORD, PASSWORD);
  79. #endif
  80. curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
  81. curl_easy_setopt(curl, CURLOPT_MAIL_FROM, MAILFROM);
  82. curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, rcpt_list);
  83. curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
  84. curl_multi_add_handle(mcurl, curl);
  85. mp_start = tvnow();
  86. /* we start some action by calling perform right away */
  87. curl_multi_perform(mcurl, &still_running);
  88. while(still_running) {
  89. struct timeval timeout;
  90. int rc; /* select() return code */
  91. fd_set fdread;
  92. fd_set fdwrite;
  93. fd_set fdexcep;
  94. int maxfd = -1;
  95. long curl_timeo = -1;
  96. FD_ZERO(&fdread);
  97. FD_ZERO(&fdwrite);
  98. FD_ZERO(&fdexcep);
  99. /* set a suitable timeout to play around with */
  100. timeout.tv_sec = 1;
  101. timeout.tv_usec = 0;
  102. curl_multi_timeout(mcurl, &curl_timeo);
  103. if(curl_timeo >= 0) {
  104. timeout.tv_sec = curl_timeo / 1000;
  105. if(timeout.tv_sec > 1)
  106. timeout.tv_sec = 1;
  107. else
  108. timeout.tv_usec = (curl_timeo % 1000) * 1000;
  109. }
  110. /* get file descriptors from the transfers */
  111. curl_multi_fdset(mcurl, &fdread, &fdwrite, &fdexcep, &maxfd);
  112. /* In a real-world program you OF COURSE check the return code of the
  113. function calls. On success, the value of maxfd is guaranteed to be
  114. greater or equal than -1. We call select(maxfd + 1, ...), specially in
  115. case of (maxfd == -1), we call select(0, ...), which is basically equal
  116. to sleep. */
  117. rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
  118. if (tvdiff(tvnow(), mp_start) > MULTI_PERFORM_HANG_TIMEOUT) {
  119. fprintf(stderr, "ABORTING TEST, since it seems "
  120. "that it would have run forever.\n");
  121. break;
  122. }
  123. switch(rc) {
  124. case -1:
  125. /* select error */
  126. break;
  127. case 0: /* timeout */
  128. default: /* action */
  129. curl_multi_perform(mcurl, &still_running);
  130. break;
  131. }
  132. }
  133. curl_slist_free_all(rcpt_list);
  134. curl_multi_remove_handle(mcurl, curl);
  135. curl_multi_cleanup(mcurl);
  136. curl_easy_cleanup(curl);
  137. curl_global_cleanup();
  138. return 0;
  139. }