mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
binpac: Add FlowBuffer policy mechanisms
This allows for tunability of the following behaviors: * Minimum flowbuffer capacity to use when parsing a new unit * Threshold at which flowbuffer capacity is contracted back to the minimum after parsing a complete unit and before parsing the next * Maximum flowbuffer capacity to allow when parsing a given unit Failed flowbuffer allocations due to reaching maximum capacity or any other reason now throw ExceptionFlowBufferAlloc.
This commit is contained in:
parent
7e6e24a4d8
commit
b4b229acf7
4 changed files with 73 additions and 13 deletions
|
@ -8,6 +8,12 @@ namespace binpac {
|
|||
|
||||
class FlowBuffer {
|
||||
public:
|
||||
struct Policy {
|
||||
int max_capacity;
|
||||
int min_capacity;
|
||||
int contract_threshold;
|
||||
};
|
||||
|
||||
enum LineBreakStyle {
|
||||
CR_OR_LF, // CR or LF or CRLF
|
||||
STRICT_CRLF, // CR followed by LF
|
||||
|
@ -95,6 +101,9 @@ public:
|
|||
|
||||
bool have_pending_request() const { return have_pending_request_; }
|
||||
|
||||
static void init(Policy p)
|
||||
{ policy = p; }
|
||||
|
||||
protected:
|
||||
// Reset the buffer for a new message
|
||||
void NewMessage();
|
||||
|
@ -106,6 +115,13 @@ protected:
|
|||
// buffer.
|
||||
void ExpandBuffer(int length);
|
||||
|
||||
// Contract the buffer to some minimum capacity.
|
||||
// Existing contents in the buffer are preserved (but only usage
|
||||
// at the time of creation this function is when the contents
|
||||
// are being discarded due to parsing exception or have already been
|
||||
// copied out after parsing a complete unit).
|
||||
void ContractBuffer();
|
||||
|
||||
// Reset line state when transit from frame mode to line mode.
|
||||
void ResetLineState();
|
||||
|
||||
|
@ -153,6 +169,8 @@ protected:
|
|||
int data_seq_at_orig_data_end_;
|
||||
bool eof_;
|
||||
bool have_pending_request_;
|
||||
|
||||
static Policy policy;
|
||||
};
|
||||
|
||||
typedef FlowBuffer *flow_buffer_t;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue