Drizzled Public API Documentation

write_buffer.h
Go to the documentation of this file.
00001 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2010 Jay Pipes <jaypipes@gmail.com>
00005  *
00006  *  Authors:
00007  *
00008  *  Jay Pipes <jaypipes@gmail.com>
00009  *
00010  *  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU General Public License for more details.
00019  *
00020  *  You should have received a copy of the GNU General Public License
00021  *  along with this program; if not, write to the Free Software
00022  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00023  */
00024 
00031 #pragma once
00032 
00033 #include <boost/noncopyable.hpp>
00034 #include <stdint.h>
00035 #include <vector>
00036 #include <pthread.h>
00037 
00038 class WriteBuffer : boost::noncopyable
00039 {
00040 public:
00041   static const size_t DEFAULT_WRITE_BUFFER_SIZE= 1024; /* Many GPB messages are < 1 KB... */
00045   WriteBuffer();
00046   ~WriteBuffer();
00050   void lock()
00051   {
00052     pthread_mutex_lock(&latch);
00053   }
00057   void unlock()
00058   {
00059     pthread_mutex_unlock(&latch);
00060   }
00066   void resize(size_t new_size);
00070   uint8_t *getRawBytes()
00071   {
00072     return &buffer[0];
00073   }
00077   size_t getCapacity()
00078   {
00079     return buffer.size();
00080   }
00081 private:
00082   std::vector<uint8_t> buffer; 
00083   pthread_mutex_t latch; 
00084 };
00085