Merge remote-tracking branch 'origin/topic/robin/log-threads' into topic/bernhard/log-threads

This commit is contained in:
Bernhard Amann 2012-02-13 02:30:24 -08:00
commit 8a6dfee00c
36 changed files with 414 additions and 304 deletions

View file

@ -1165,6 +1165,15 @@ bool Manager::Flush(EnumVal* id)
return true;
}
void Manager::Terminate()
{
for ( vector<Stream *>::iterator s = streams.begin(); s != streams.end(); ++s )
{
if ( *s )
Flush((*s)->id);
}
}
void Manager::Error(WriterFrontend* writer, const char* msg)
{
reporter->Error("error with writer for %s: %s",

View file

@ -139,6 +139,12 @@ public:
*/
bool Flush(EnumVal* id);
/**
* Prepares the log manager to terminate. This will flush all log
* stream.
*/
void Terminate();
protected:
friend class WriterFrontend;
friend class RotationFinishedMessage;
@ -146,7 +152,7 @@ protected:
friend class ::RotationTimer;
// Instantiates a new WriterBackend of the given type (note that
// doing so creates a new thread!).
// doing so creates a new thread!).
WriterBackend* CreateBackend(WriterFrontend* frontend, bro_int_t type);
//// Function also used by the RemoteSerializer.

View file

@ -61,7 +61,7 @@ using namespace logging;
WriterBackend::WriterBackend(WriterFrontend* arg_frontend) : MsgThread()
{
path = "<not set>";
path = "<path not yet set>";
num_fields = 0;
fields = 0;
buffering = true;
@ -113,7 +113,9 @@ bool WriterBackend::Init(string arg_path, int arg_num_fields, const Field* const
num_fields = arg_num_fields;
fields = arg_fields;
SetName(frontend->Name());
string name = Fmt("%s/%s", path.c_str(), frontend->Name().c_str());
SetName(name);
if ( ! DoInit(arg_path, arg_num_fields, arg_fields) )
{
@ -233,6 +235,8 @@ bool WriterBackend::Finish()
bool WriterBackend::DoHeartbeat(double network_time, double current_time)
{
MsgThread::DoHeartbeat(network_time, current_time);
SendOut(new FlushWriteBufferMessage(frontend));
return true;

View file

@ -1,4 +1,6 @@
#include "Net.h"
#include "WriterFrontend.h"
#include "WriterBackend.h"
#include "../threading/SerializationTypes.h"
@ -159,8 +161,8 @@ void WriterFrontend::Write(int num_fields, Value** vals)
write_buffer[write_buffer_pos++] = vals;
if ( write_buffer_pos >= WRITER_BUFFER_SIZE || ! buf )
// Buffer full (or no bufferin desired).
if ( write_buffer_pos >= WRITER_BUFFER_SIZE || ! buf || terminating )
// Buffer full (or no bufferin desired or termiating).
FlushWriteBuffer();
}

View file

@ -30,9 +30,6 @@ public:
* frontend will internally instantiate a WriterBackend of the
* corresponding type.
*
* name: A descriptive name for the backend wroter type (e.g., \c
* Ascii).
*
* Frontends must only be instantiated by the main thread.
*/
WriterFrontend(bro_int_t type);

View file

@ -177,14 +177,34 @@ bool Ascii::DoWriteOne(ODesc* desc, Value* val, const Field* field)
break;
case TYPE_SUBNET:
desc->Add(dotted_addr(val->val.subnet_val.net));
{
// FIXME: This will be replaced with string(addr) once the
// IPV6 branch is merged in.
uint32_t addr = ntohl(val->val.subnet_val.net);
char buf[32];
snprintf(buf, sizeof(buf), "%d.%d.%d.%d",
addr >> 24, (addr >> 16) & 0xff,
(addr >> 8) & 0xff, addr & 0xff);
desc->Add(buf);
desc->Add("/");
desc->Add(val->val.subnet_val.width);
break;
}
case TYPE_ADDR:
desc->Add(dotted_addr(val->val.addr_val));
{
// FIXME: This will be replaced with string(addr) once the
// IPV6 branch is merged in.
uint32_t addr = ntohl(*val->val.addr_val);
char buf[32];
snprintf(buf, sizeof(buf), "%d.%d.%d.%d",
addr >> 24, (addr >> 16) & 0xff,
(addr >> 8) & 0xff, addr & 0xff);
desc->Add(buf);
break;
}
case TYPE_TIME:
case TYPE_INTERVAL: