persistent.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2018 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 __PERSISTENT_HPP__
  14. #define __PERSISTENT_HPP__
  15. #include "jlib.hpp"
  16. #include "jsocket.hpp"
  17. #define DEFAULT_MAX_PERSISTENT_IDLE_TIME 60
  18. #define DEFAULT_MAX_PERSISTENT_REQUESTS 100
  19. enum class PersistentLogLevel { PLogNone=0, PLogMin=1, PLogNormal=5, PLogMax=10};
  20. interface IPersistentHandler : implements IInterface
  21. {
  22. virtual void add(ISocket* sock, SocketEndpoint* ep = nullptr) = 0;
  23. virtual void remove(ISocket* sock) = 0;
  24. virtual void doneUsing(ISocket* sock, bool keep, unsigned usesOverOne = 0) = 0;
  25. virtual Linked<ISocket> getAvailable(SocketEndpoint* ep = nullptr) = 0;
  26. virtual void stop(bool wait) = 0;
  27. virtual bool inDoNotReuseList(SocketEndpoint* ep) = 0;
  28. };
  29. interface IPersistentSelectNotify
  30. {
  31. virtual bool notifySelected(ISocket *sock,unsigned selected, IPersistentHandler* handler) = 0;
  32. };
  33. IPersistentHandler* createPersistentHandler(IPersistentSelectNotify* notify, int maxIdleTime = DEFAULT_MAX_PERSISTENT_IDLE_TIME, int maxReqs = DEFAULT_MAX_PERSISTENT_REQUESTS, PersistentLogLevel loglevel=PersistentLogLevel::PLogMin, bool enableDoNotReuseList=false);
  34. #endif //__PERSISTENT_HPP__