/common/commonext/thorport.hpp

http://github.com/hpcc-systems/HPCC-Platform · C++ Header · 81 lines · 56 code · 9 blank · 16 comment · 2 complexity · e0b51c83dba97578c78ee50b4a26cfaa MD5 · raw file

  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 __THORPORT__
  14. #define __THORPORT__
  15. #include "jarray.hpp"
  16. #include "jutil.hpp"
  17. #include "jsocket.hpp"
  18. #ifdef _WIN32
  19. #ifdef COMMONEXT_EXPORTS
  20. #define thcommonext_decl __declspec(dllexport)
  21. #else
  22. #define thcommonext_decl __declspec(dllimport)
  23. #endif
  24. #else
  25. #define thcommonext_decl
  26. #endif
  27. enum ThorPortKind
  28. {
  29. TPORT_watchdog,
  30. TPORT_mp
  31. };
  32. thcommonext_decl unsigned short getFixedPort(ThorPortKind category);
  33. thcommonext_decl unsigned short getFixedPort(unsigned short base, ThorPortKind category);
  34. thcommonext_decl unsigned short getExternalFixedPort(unsigned short masterbase, unsigned short machinebase, ThorPortKind category);
  35. thcommonext_decl unsigned short allocPort(unsigned num=1);
  36. thcommonext_decl void freePort(unsigned short,unsigned num=1);
  37. thcommonext_decl void setMachinePortBase(unsigned short base);
  38. thcommonext_decl void setMasterPortBase(unsigned short base);
  39. thcommonext_decl unsigned short getMasterPortBase();
  40. thcommonext_decl unsigned short getMachinePortBase();
  41. typedef UnsignedShortArray PortArray;
  42. class CPortGroup
  43. {
  44. public:
  45. unsigned short allocPort(unsigned n=1)
  46. {
  47. unsigned short p=::allocPort(n);
  48. while (n--)
  49. portsinuse.append(p+n);
  50. return p;
  51. }
  52. void freePort(unsigned short p,unsigned n=1)
  53. {
  54. unsigned i;
  55. for (i=0;i<n;i++)
  56. portsinuse.zap(p+i);
  57. ::freePort(p,n);
  58. }
  59. virtual ~CPortGroup()
  60. {
  61. ForEachItemIn(i,portsinuse) {
  62. freePort(portsinuse.item(i));
  63. }
  64. }
  65. protected:
  66. PortArray portsinuse;
  67. };
  68. #endif