BufferedMessageWriter

BufferedMessageWriter allows for arbitrary buffering of messages in memory before they are sent using a MultiplexedMsgConnection.

An implementation of IMessageWriter uses a BufferedMessageWriter to provide a basis for implementing the GetNextMessage() and WritePayload() methods.

BufferedMessageWriter represents a single producer single consumer (SPSC) queue supporting concurrency between the producer and consumer.

This means concurrency is permitted between an Iocp thread that calls GetNextMessage()/WritePayload() and the producer that writes new messages using an Archive.

A single "producer" thread is assumed to


class BufferedMessageWriter
{
public:
    BufferedMessageWriter(MultiplexedMsgConnection* c);
    void Close();
    Archive& GetWriteArchive();
    void Flush();
    void WaitProducer(ssize_t bufferSize);
    void EndMessage(MessageId id);
    ssize_t GetNextMessage(MessageId& id);
    void WritePayload(octet_t* payload, ssize_t payloadSize);

private:
    [ implementation ]
};


BufferedMessageWriter(MultiplexedMsgConnection* c)


void Close()


Archive& GetWriteArchive()

Gets an archive to be used to write messages by the "producer". The messages are written to a forward linked list of pages in memory, that can grow without limit.

This is done without any mutex and without any blocking on I/O. Any amount of writes can be buffered.


void Flush()

Ensure all messages written so far will be written to the MultiplexedMsgConnection in a timely manner.

Flush() is asynchronous. It doesn't block - i.e. wait for messages to be sent - it just ensures that the framework proceeds to send the messages. Without Flush() the framework may delay the sending of messages indefinitely.

Flush() cannot be called concurrently with calls to EndMessage() or with writes to the archive.


void WaitProducer(ssize_t bufferSize)


void EndMessage(MessageId id)

EndMessage() must be called by the producer after writing each message (and before writing the next message begins).


ssize_t GetNextMessage(MessageId& id)

Intended to provide a basis for an implementation of IMessageWriter


void WritePayload(octet_t* payload, ssize_t payloadSize)

Intended to provide a basis for an implementation of IMessageWriter