Hi All,

I am trying out the Boost iostreams library to build a sink, text sent to this sink is split up in to lines of text and each line is then being send over to our logging server (the function I'm calling to do this is static).   

So far I've built the write method as mentioned in the documentation for my sink, and push all the characters I receive in a buffer inside my sink class.  Then I look for the end of line characters and figure out the lines of text.  The problem I'm having is when there is no end of line character and the stream gets closed.

Is there a way to get notified when the stream gets closed?  Is there a better way to do this?

Here is the code I have:

class logging_sink
{
public:
     typedef char char_type;
     typedef boost::iostreams::sink_tag category;

     std::streamsize write(const char* s, std::streamsize n)
     {
          buffer_.append(s, n);
          // loop over buffer and find end of lines, send them to logging service
     }

     void close()
     {
          // close is never called
          if (!buffer_.empty())
              log_message(buffer_);
     }

private:
     std::string buffer_;

};

class logging_stream   : public boost::iostreams::stream<logging_sink>
{
public:
        logging_stream()
              : boost::iostreams::stream<logging_sink>(logging_sink())
        {}
};

logging_stream s;
s << "Hello World";
s.close();


Thank you for your help,

bob