Guest User

Untitled

a guest
Feb 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. #include <thread>
  2. #include <chrono>
  3. #include "soapH.h"
  4. #include "ns1.nsmap"
  5. #include "httpget.h"
  6.  
  7. #define TIME_OUT 90 //very high timeout
  8.  
  9. static bool keep_running;
  10. static struct soap *soapInstance;
  11.  
  12. void connection()
  13. {
  14. const char * endPoint = "http://example.com/";
  15. while (keep_running)
  16. {
  17. //if this call gets blocked, it is not unblocked by a soap_done call, when it should be
  18. if (soap_get_connect(soapInstance, endPoint, NULL))
  19. {
  20. printf("Error en soap_get_connect: %dn", soapInstance->error);
  21. return;
  22. }
  23.  
  24. if (soap_begin_recv(soapInstance) != SOAP_OK)
  25. {
  26. printf("Error en soap_begin_recv: %dn", soapInstance->error);
  27. return;
  28. }
  29.  
  30. soap_end_recv(soapInstance);
  31. std::this_thread::sleep_for(std::chrono::milliseconds(1500));
  32. }
  33. }
  34.  
  35. int main()
  36. {
  37. char input[10];
  38. memset(input, 0, sizeof input);
  39.  
  40. soapInstance = soap_new();
  41. soapInstance->recv_timeout = TIME_OUT;
  42. soapInstance->send_timeout = TIME_OUT;
  43. soapInstance->connect_timeout = TIME_OUT;
  44. soap_mode(soapInstance, SOAP_XML_IGNORENS | SOAP_C_UTFSTRING);
  45. soap_register_plugin(soapInstance, ::http_get);
  46.  
  47. keep_running = true;
  48. std::thread runConnectionThread(connection);
  49.  
  50. while (strcmp(input, "quit") != 0)
  51. {
  52. scanf("%s", input);
  53. }
  54.  
  55. std::cout << "Stopping gsoap connections" << std::endl;
  56. soap_done(soapInstance);//this should end gsoap connections, but it is not working
  57. keep_running = false;
  58. runConnectionThread.join();
  59.  
  60. soap_destroy(soapInstance);
  61. soap_end(soapInstance);
  62. soap_free(soapInstance);
  63.  
  64. return 0;
  65. }
Add Comment
Please, Sign In to add comment