udplib.hpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 UDPMSGPK_INCL
  14. #define UDPMSGPK_INCL
  15. #include "jiface.hpp"
  16. #include "jstring.hpp"
  17. #include "jisem.hpp"
  18. #include "jsocket.hpp"
  19. #include "roxiemem.hpp"
  20. #ifdef UDPLIB_EXPORTS
  21. #define UDPLIB_API DECL_EXPORT
  22. #else
  23. #define UDPLIB_API DECL_IMPORT
  24. #endif
  25. typedef unsigned ruid_t; // at 1000/sec recycle every 49 days
  26. #define RUIDF "0x%.8x"
  27. #define RUID_PING 0
  28. #define RUID_DISCARD 1
  29. #define RUID_FIRST 2
  30. typedef unsigned RecordLengthType;
  31. #define MAX_RECORD_LENGTH 0xffffffff
  32. interface IMessagePacker : extends IInterface
  33. {
  34. virtual void *getBuffer(unsigned len, bool variable) = 0;
  35. virtual void putBuffer(const void *buf, unsigned len, bool variable) = 0;
  36. virtual void flush(bool last_message = false) = 0;
  37. virtual bool dataQueued() = 0;
  38. virtual void sendMetaInfo(const void *buf, unsigned len) = 0;
  39. virtual unsigned size() const = 0; // Total amount written via putBuffer plus any overhead from record length prefixes
  40. // Notes:
  41. // 1. Parameters to putBuffer must have been returned from getBuffer.
  42. // 2 putBuffer must me called before any call to flush
  43. // 3. There is an implicit abort if is released without final flush
  44. // 4 This interface is single threaded
  45. // 5. call to getbuffer, without call to makes the previous call to getBuffer and NULL operation
  46. // 6. if flush has been called with last_message true, then any calls to getBuffer or putBuffer is undefined.
  47. };
  48. interface IException;
  49. interface IMessageUnpackCursor : extends IInterface
  50. {
  51. virtual const void *getNext(int length) = 0;
  52. virtual bool atEOF() const = 0;
  53. virtual bool isSerialized() const = 0;
  54. // if one tries to read past the last record then NULL will be returned,
  55. // if one asks for more data than available then throws exception.
  56. };
  57. interface IMessageResult : extends IInterface
  58. {
  59. virtual IMessageUnpackCursor *getCursor(roxiemem::IRowManager *rowMgr) const = 0;
  60. virtual const void *getMessageHeader(unsigned &length) const = 0;
  61. virtual const void *getMessageMetadata(unsigned &length) const = 0;
  62. virtual void discard() const = 0;
  63. };
  64. interface IMessageCollator : extends IInterface
  65. {
  66. virtual IMessageResult *getNextResult(unsigned time_out, bool &anyActivity) = 0;
  67. virtual void interrupt(IException *E = NULL) = 0;
  68. virtual ruid_t queryRUID() const = 0;
  69. virtual unsigned queryBytesReceived() const = 0;
  70. virtual bool add_package(roxiemem::DataBuffer *dataBuff) = 0;
  71. };
  72. interface IReceiveManager : extends IInterface
  73. {
  74. virtual IMessageCollator *createMessageCollator(roxiemem::IRowManager *rowManager, ruid_t ruid) = 0;
  75. virtual void detachCollator(const IMessageCollator *collator) = 0;
  76. virtual void setDefaultCollator(IMessageCollator *collator) = 0;
  77. };
  78. interface ISendManager : extends IInterface
  79. {
  80. virtual IMessagePacker *createMessagePacker(ruid_t id, unsigned sequence, const void *messageHeader, unsigned headerSize, unsigned destNodeIndex, int queue) = 0;
  81. virtual bool dataQueued(ruid_t ruid, unsigned sequence, unsigned destNodeIndex) = 0;
  82. virtual bool abortData(ruid_t ruid, unsigned sequence, unsigned destNodeIndex) = 0;
  83. virtual bool allDone() = 0;
  84. virtual void writeOwn(unsigned destNodeIndex, roxiemem::DataBuffer *buffer, unsigned len, unsigned queue) = 0; // NOTE: takes ownership of the DataBuffer
  85. };
  86. extern UDPLIB_API IReceiveManager *createReceiveManager(int server_flow_port, int data_port, int client_flow_port, int sniffer_port, const IpAddress &sniffer_multicast_ip, int queue_size, unsigned maxSlotsPerSender, unsigned myNodeIndex);
  87. extern UDPLIB_API ISendManager *createSendManager(int server_flow_port, int data_port, int client_flow_port, int sniffer_port, const IpAddress &sniffer_multicast_ip, int queue_size_pr_server, int queues_pr_server, TokenBucket *rateLimiter, unsigned myNodeIndex);
  88. extern UDPLIB_API IMessagePacker *createMessagePacker(ruid_t ruid, unsigned msgId, const void *messageHeader, unsigned headerSize, ISendManager &_parent, unsigned _destNode, unsigned _sourceNode, unsigned _msgSeq, unsigned _queue);
  89. extern UDPLIB_API const IpAddress &getNodeAddress(unsigned index);
  90. extern UDPLIB_API unsigned addRoxieNode(const char *ipString);
  91. extern UDPLIB_API unsigned getNumNodes();
  92. extern UDPLIB_API atomic_t unwantedDiscarded;
  93. extern UDPLIB_API unsigned udpTraceLevel;
  94. extern UDPLIB_API unsigned udpTraceCategories;
  95. extern UDPLIB_API unsigned udpOutQsPriority;
  96. extern UDPLIB_API void queryMemoryPoolStats(StringBuffer &memStats);
  97. extern UDPLIB_API unsigned multicastTTL;
  98. #ifdef __linux__
  99. extern UDPLIB_API void setLinuxThreadPriority(int level);
  100. #endif
  101. extern UDPLIB_API unsigned udpFlowSocketsSize;
  102. extern UDPLIB_API unsigned udpLocalWriteSocketSize;
  103. extern UDPLIB_API unsigned udpMaxRetryTimedoutReqs;
  104. extern UDPLIB_API unsigned udpRequestToSendTimeout;
  105. extern UDPLIB_API unsigned udpRetryBusySenders;
  106. extern UDPLIB_API unsigned udpInlineCollationPacketLimit;
  107. extern UDPLIB_API bool udpInlineCollation;
  108. extern UDPLIB_API bool udpSnifferEnabled;
  109. extern UDPLIB_API unsigned udpSnifferReadThreadPriority;
  110. extern UDPLIB_API unsigned udpSnifferSendThreadPriority;
  111. #endif