mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 15:48:19 +00:00
Remove timeouts from remote communication loop.
The select() now blocks until there's work to do instead of relying on a small timeout value which can cause unproductive use of cpu cycles.
This commit is contained in:
parent
73cc81f44a
commit
675fba3fde
21 changed files with 364 additions and 58 deletions
|
@ -210,6 +210,7 @@ bool ChunkedIOFd::WriteChunk(Chunk* chunk, bool partial)
|
|||
else
|
||||
pending_head = pending_tail = q;
|
||||
|
||||
write_flare.Fire();
|
||||
return Flush();
|
||||
}
|
||||
|
||||
|
@ -232,6 +233,7 @@ bool ChunkedIOFd::PutIntoWriteBuffer(Chunk* chunk)
|
|||
write_len += len;
|
||||
|
||||
delete chunk;
|
||||
write_flare.Fire();
|
||||
|
||||
if ( network_time - last_flush > 0.005 )
|
||||
FlushWriteBuffer();
|
||||
|
@ -269,6 +271,10 @@ bool ChunkedIOFd::FlushWriteBuffer()
|
|||
if ( unsigned(written) == len )
|
||||
{
|
||||
write_pos = write_len = 0;
|
||||
|
||||
if ( ! pending_head )
|
||||
write_flare.Extinguish();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -318,7 +324,12 @@ bool ChunkedIOFd::Flush()
|
|||
}
|
||||
}
|
||||
|
||||
return FlushWriteBuffer();
|
||||
bool rval = FlushWriteBuffer();
|
||||
|
||||
if ( ! pending_head && write_len == 0 )
|
||||
write_flare.Extinguish();
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
uint32 ChunkedIOFd::ChunkAvailable()
|
||||
|
@ -394,6 +405,9 @@ bool ChunkedIOFd::Read(Chunk** chunk, bool may_block)
|
|||
#ifdef DEBUG_COMMUNICATION
|
||||
AddToBuffer("<false:read-chunk>", true);
|
||||
#endif
|
||||
if ( ! ChunkAvailable() )
|
||||
read_flare.Extinguish();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -402,9 +416,15 @@ bool ChunkedIOFd::Read(Chunk** chunk, bool may_block)
|
|||
#ifdef DEBUG_COMMUNICATION
|
||||
AddToBuffer("<null:no-data>", true);
|
||||
#endif
|
||||
read_flare.Extinguish();
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( ChunkAvailable() )
|
||||
read_flare.Fire();
|
||||
else
|
||||
read_flare.Extinguish();
|
||||
|
||||
#ifdef DEBUG
|
||||
if ( *chunk )
|
||||
DBG_LOG(DBG_CHUNKEDIO, "read of size %d %s[%s]",
|
||||
|
@ -481,6 +501,9 @@ bool ChunkedIOFd::ReadChunk(Chunk** chunk, bool may_block)
|
|||
read_pos = 0;
|
||||
read_len = bytes_left;
|
||||
|
||||
if ( ! ChunkAvailable() )
|
||||
read_flare.Extinguish();
|
||||
|
||||
// If allowed, wait a bit for something to read.
|
||||
if ( may_block )
|
||||
{
|
||||
|
@ -607,6 +630,14 @@ bool ChunkedIOFd::IsFillingUp()
|
|||
return stats.pending > MAX_BUFFERED_CHUNKS_SOFT;
|
||||
}
|
||||
|
||||
std::vector<int> ChunkedIOFd::FdSupplements() const
|
||||
{
|
||||
std::vector<int> rval;
|
||||
rval.push_back(write_flare.FD());
|
||||
rval.push_back(read_flare.FD());
|
||||
return rval;
|
||||
}
|
||||
|
||||
void ChunkedIOFd::Clear()
|
||||
{
|
||||
while ( pending_head )
|
||||
|
@ -618,6 +649,9 @@ void ChunkedIOFd::Clear()
|
|||
}
|
||||
|
||||
pending_head = pending_tail = 0;
|
||||
|
||||
if ( write_len == 0 )
|
||||
write_flare.Extinguish();
|
||||
}
|
||||
|
||||
const char* ChunkedIOFd::Error()
|
||||
|
@ -830,6 +864,7 @@ bool ChunkedIOSSL::Write(Chunk* chunk)
|
|||
else
|
||||
write_head = write_tail = q;
|
||||
|
||||
write_flare.Fire();
|
||||
Flush();
|
||||
return true;
|
||||
}
|
||||
|
@ -935,6 +970,7 @@ bool ChunkedIOSSL::Flush()
|
|||
write_state = LEN;
|
||||
}
|
||||
|
||||
write_flare.Extinguish();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1104,6 +1140,13 @@ bool ChunkedIOSSL::IsFillingUp()
|
|||
return false;
|
||||
}
|
||||
|
||||
std::vector<int> ChunkedIOSSL::FdSupplements() const
|
||||
{
|
||||
std::vector<int> rval;
|
||||
rval.push_back(write_flare.FD());
|
||||
return rval;
|
||||
}
|
||||
|
||||
void ChunkedIOSSL::Clear()
|
||||
{
|
||||
while ( write_head )
|
||||
|
@ -1114,6 +1157,7 @@ void ChunkedIOSSL::Clear()
|
|||
write_head = next;
|
||||
}
|
||||
write_head = write_tail = 0;
|
||||
write_flare.Extinguish();
|
||||
}
|
||||
|
||||
const char* ChunkedIOSSL::Error()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue