thorport.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*##############################################################################
  2. Copyright (C) 2011 HPCC Systems.
  3. All rights reserved. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ############################################################################## */
  14. #ifndef __THORPORT__
  15. #define __THORPORT__
  16. #include "jarray.hpp"
  17. #include "jutil.hpp"
  18. #include "jsocket.hpp"
  19. #ifdef _WIN32
  20. #ifdef COMMONEXT_EXPORTS
  21. #define thcommonext_decl __declspec(dllexport)
  22. #else
  23. #define thcommonext_decl __declspec(dllimport)
  24. #endif
  25. #else
  26. #define thcommonext_decl
  27. #endif
  28. enum ThorPortKind
  29. {
  30. TPORT_watchdog,
  31. TPORT_mp
  32. };
  33. thcommonext_decl unsigned short getFixedPort(ThorPortKind category);
  34. thcommonext_decl unsigned short getFixedPort(unsigned short base, ThorPortKind category);
  35. thcommonext_decl unsigned short getExternalFixedPort(unsigned short masterbase, unsigned short machinebase, ThorPortKind category);
  36. thcommonext_decl unsigned short allocPort(unsigned num=1);
  37. thcommonext_decl void freePort(unsigned short,unsigned num=1);
  38. thcommonext_decl void setMachinePortBase(unsigned short base);
  39. thcommonext_decl void setMasterPortBase(unsigned short base);
  40. thcommonext_decl unsigned short getMasterPortBase();
  41. thcommonext_decl unsigned short getMachinePortBase();
  42. typedef UnsignedShortArray PortArray;
  43. class CPortGroup
  44. {
  45. public:
  46. unsigned short allocPort(unsigned n=1)
  47. {
  48. unsigned short p=::allocPort(n);
  49. while (n--)
  50. portsinuse.append(p+n);
  51. return p;
  52. }
  53. void freePort(unsigned short p,unsigned n=1)
  54. {
  55. unsigned i;
  56. for (i=0;i<n;i++)
  57. portsinuse.zap(p+i);
  58. ::freePort(p,n);
  59. }
  60. virtual ~CPortGroup()
  61. {
  62. ForEachItemIn(i,portsinuse) {
  63. freePort(portsinuse.item(i));
  64. }
  65. }
  66. protected:
  67. PortArray portsinuse;
  68. };
  69. #endif