espthread.hpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #ifndef __ESPTHREAD_HPP__
  14. #define __ESPTHREAD_HPP__
  15. #define TERMINATE_EXITCODE -99 // the working process use it to tell the monitor to exit too.
  16. interface ISocketReturner
  17. {
  18. virtual void returnSocket() = 0;
  19. };
  20. class CEspProtocolThread: public Thread, implements ISocketReturner
  21. {
  22. protected:
  23. bool terminating;
  24. CriticalSection sect;
  25. Semaphore ticksem;
  26. Owned<ISocket> m_socket;
  27. StringAttr m_name;
  28. int run();
  29. bool keepAlive = false;
  30. bool m_socketReturned = false;
  31. public:
  32. IMPLEMENT_IINTERFACE;
  33. CEspProtocolThread(const char *name = "Unknown service type");
  34. CEspProtocolThread(ISocket *sock, const char *name = "Unknown service type");
  35. virtual ~CEspProtocolThread();
  36. virtual void start();
  37. void setSocket(ISocket *sock);
  38. void stop(bool wait);
  39. virtual const char *getServiceName();
  40. virtual bool onRequest();
  41. virtual void returnSocket();
  42. };
  43. #endif //__ESPTHREAD_HPP__