espplugin.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #define USING_SCM_WITH_STL
  14. #include "jlib.hpp"
  15. #include "jlog.hpp"
  16. #include "jiface.hpp"
  17. #include "jstring.hpp"
  18. #include "jexcept.hpp"
  19. #include "jthread.hpp"
  20. #include "jsocket.hpp"
  21. #include "jptree.hpp"
  22. //#include "IAEsp.hpp"
  23. //#include "IAEsc.hpp"
  24. #include "espthread.hpp"
  25. #include <iostream>
  26. using namespace std;
  27. #include <conio.h>
  28. CEspServiceThread::CEspServiceThread(const char *name)
  29. : Thread("CEspServiceThread"), m_name(name)
  30. {
  31. terminating = false;
  32. }
  33. CEspServiceThread::CEspServiceThread(ISocket *sock, const char *name)
  34. : Thread("CEspServiceThread"), m_name(name)
  35. {
  36. terminating = false;
  37. setSocket(sock);
  38. }
  39. CEspServiceThread::~CEspServiceThread()
  40. {
  41. }
  42. const char *CEspServiceThread::getServiceName()
  43. {
  44. return m_name.get();
  45. }
  46. bool CEspServiceThread::onRequest()
  47. {
  48. return false;
  49. }
  50. void CEspServiceThread::setSocket(ISocket *sock)
  51. {
  52. CriticalBlock block(sect);
  53. m_socket.set(sock);
  54. DBGLOG("%s -- serving socket(%d):", this->getServiceName(), sock->OShandle());
  55. char xname[256]={0};
  56. m_socket->name(xname, 256);
  57. DBGLOG("... on net address(%s)", xname);
  58. m_socket->peer_name(xname, 256);
  59. DBGLOG("... from net address(%s)", xname);
  60. ticksem.signal();
  61. }
  62. void CEspServiceThread::stop(bool wait)
  63. {
  64. terminating = true;
  65. ticksem.signal();
  66. if (wait)
  67. join();
  68. }
  69. int CEspServiceThread::run()
  70. {
  71. Link();
  72. try
  73. {
  74. while(onRequest());
  75. }
  76. catch (IException *e)
  77. {
  78. StringBuffer estr;
  79. IERRLOG("Exception(%d, %s) socket(%d).", e->errorCode(), e->errorMessage(estr).str(), m_socket->OShandle());
  80. e->Release();
  81. }
  82. DBGLOG("Closing Socket(%d)", m_socket->OShandle());
  83. m_socket->shutdown();
  84. m_socket->close();
  85. Release();
  86. return 0;
  87. }