mirror of
https://github.com/debauchee/barrier.git
synced 2026-02-12 14:45:21 +08:00
Reorganized source tree. Moved client.cpp into cmd/synergy as
synergy.cpp and server.cpp into cmd/synergyd as synergyd.cpp. Moved and renamed related files. Moved remaining source files into lib/.... Modified and added makefiles as appropriate. Result is that library files are under lib with each library in its own directory and program files are under cmd with each command in its own directory.
This commit is contained in:
83
lib/io/CBufferedOutputStream.cpp
Normal file
83
lib/io/CBufferedOutputStream.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
#include "CBufferedOutputStream.h"
|
||||
#include "XIO.h"
|
||||
#include "CLock.h"
|
||||
#include "CMutex.h"
|
||||
#include "CThread.h"
|
||||
#include "IJob.h"
|
||||
|
||||
//
|
||||
// CBufferedOutputStream
|
||||
//
|
||||
|
||||
CBufferedOutputStream::CBufferedOutputStream(
|
||||
CMutex* mutex, IJob* adoptedCloseCB) :
|
||||
m_mutex(mutex),
|
||||
m_closeCB(adoptedCloseCB),
|
||||
m_empty(mutex, true),
|
||||
m_closed(false)
|
||||
{
|
||||
assert(m_mutex != NULL);
|
||||
}
|
||||
|
||||
CBufferedOutputStream::~CBufferedOutputStream()
|
||||
{
|
||||
delete m_closeCB;
|
||||
}
|
||||
|
||||
const void*
|
||||
CBufferedOutputStream::peek(UInt32 n)
|
||||
{
|
||||
return m_buffer.peek(n);
|
||||
}
|
||||
|
||||
void
|
||||
CBufferedOutputStream::pop(UInt32 n)
|
||||
{
|
||||
m_buffer.pop(n);
|
||||
if (m_buffer.getSize() == 0) {
|
||||
m_empty.broadcast();
|
||||
}
|
||||
}
|
||||
|
||||
UInt32
|
||||
CBufferedOutputStream::getSize() const
|
||||
{
|
||||
return m_buffer.getSize();
|
||||
}
|
||||
|
||||
void
|
||||
CBufferedOutputStream::close()
|
||||
{
|
||||
CLock lock(m_mutex);
|
||||
if (m_closed) {
|
||||
throw XIOClosed();
|
||||
}
|
||||
|
||||
m_closed = true;
|
||||
m_buffer.pop(m_buffer.getSize());
|
||||
if (m_closeCB != NULL) {
|
||||
m_closeCB->run();
|
||||
}
|
||||
}
|
||||
|
||||
UInt32
|
||||
CBufferedOutputStream::write(const void* buffer, UInt32 n)
|
||||
{
|
||||
CLock lock(m_mutex);
|
||||
if (m_closed) {
|
||||
throw XIOClosed();
|
||||
}
|
||||
|
||||
m_buffer.write(buffer, n);
|
||||
return n;
|
||||
}
|
||||
|
||||
void
|
||||
CBufferedOutputStream::flush()
|
||||
{
|
||||
// wait until all data is written
|
||||
CLock lock(m_mutex);
|
||||
while (m_buffer.getSize() > 0) {
|
||||
m_empty.wait();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user