removed obsolete files.
This commit is contained in:
parent
f536e1cece
commit
c8737de4ad
|
@ -1,93 +0,0 @@
|
|||
#include "CSocketInputStream.h"
|
||||
#include "CLock.h"
|
||||
#include "CMutex.h"
|
||||
#include "CThread.h"
|
||||
#include "IJob.h"
|
||||
#include "XIO.h"
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
//
|
||||
// CSocketInputStream
|
||||
//
|
||||
|
||||
CSocketInputStream::CSocketInputStream(CMutex* mutex, IJob* closeCB) :
|
||||
m_mutex(mutex),
|
||||
m_empty(mutex, true),
|
||||
m_closeCB(closeCB),
|
||||
m_closed(false),
|
||||
m_hungup(false)
|
||||
{
|
||||
assert(m_mutex != NULL);
|
||||
}
|
||||
|
||||
CSocketInputStream::~CSocketInputStream()
|
||||
{
|
||||
delete m_closeCB;
|
||||
}
|
||||
|
||||
void CSocketInputStream::write(
|
||||
const void* data, UInt32 n)
|
||||
{
|
||||
if (!m_hungup && n > 0) {
|
||||
m_buffer.write(data, n);
|
||||
m_empty = (m_buffer.getSize() == 0);
|
||||
m_empty.broadcast();
|
||||
}
|
||||
}
|
||||
|
||||
void CSocketInputStream::hangup()
|
||||
{
|
||||
m_hungup = true;
|
||||
m_empty.broadcast();
|
||||
}
|
||||
|
||||
void CSocketInputStream::close()
|
||||
{
|
||||
CLock lock(m_mutex);
|
||||
if (m_closed) {
|
||||
throw XIOClosed();
|
||||
}
|
||||
|
||||
m_closed = true;
|
||||
if (m_closeCB) {
|
||||
m_closeCB->run();
|
||||
}
|
||||
}
|
||||
|
||||
UInt32 CSocketInputStream::read(
|
||||
void* dst, UInt32 n)
|
||||
{
|
||||
CLock lock(m_mutex);
|
||||
if (m_closed) {
|
||||
throw XIOClosed();
|
||||
}
|
||||
|
||||
// wait for data (or hangup)
|
||||
while (!m_hungup && m_empty == true) {
|
||||
m_empty.wait();
|
||||
}
|
||||
|
||||
// read data
|
||||
const UInt32 count = m_buffer.getSize();
|
||||
if (n > count) {
|
||||
n = count;
|
||||
}
|
||||
if (n > 0) {
|
||||
memcpy(dst, m_buffer.peek(n), n);
|
||||
m_buffer.pop(n);
|
||||
}
|
||||
|
||||
// update empty state
|
||||
if (m_buffer.getSize() == 0) {
|
||||
m_empty = true;
|
||||
m_empty.broadcast();
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
UInt32 CSocketInputStream::getSize() const
|
||||
{
|
||||
CLock lock(m_mutex);
|
||||
return m_buffer.getSize();
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
#ifndef CSOCKETINPUTSTREAM_H
|
||||
#define CSOCKETINPUTSTREAM_H
|
||||
|
||||
#include "CSocketStreamBuffer.h"
|
||||
#include "CCondVar.h"
|
||||
#include "IInputStream.h"
|
||||
|
||||
class CMutex;
|
||||
class IJob;
|
||||
|
||||
class CSocketInputStream : public IInputStream {
|
||||
public:
|
||||
CSocketInputStream(CMutex*, IJob* adoptedCloseCB);
|
||||
~CSocketInputStream();
|
||||
|
||||
// manipulators
|
||||
|
||||
// write() appends n bytes to the buffer
|
||||
void write(const void*, UInt32 n);
|
||||
|
||||
// causes read() to always return immediately. if there is no
|
||||
// more data then it returns 0. further writes are discarded.
|
||||
void hangup();
|
||||
|
||||
// accessors
|
||||
|
||||
// IInputStream overrides
|
||||
// these all lock the mutex for their duration
|
||||
virtual void close();
|
||||
virtual UInt32 read(void*, UInt32 count);
|
||||
virtual UInt32 getSize() const;
|
||||
|
||||
private:
|
||||
CMutex* m_mutex;
|
||||
CCondVar<bool> m_empty;
|
||||
IJob* m_closeCB;
|
||||
CSocketStreamBuffer m_buffer;
|
||||
bool m_closed;
|
||||
bool m_hungup;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,78 +0,0 @@
|
|||
#include "CSocketOutputStream.h"
|
||||
#include "CLock.h"
|
||||
#include "CMutex.h"
|
||||
#include "CThread.h"
|
||||
#include "IJob.h"
|
||||
#include "XIO.h"
|
||||
#include <assert.h>
|
||||
|
||||
//
|
||||
// CSocketOutputStream
|
||||
//
|
||||
|
||||
CSocketOutputStream::CSocketOutputStream(CMutex* mutex, IJob* closeCB) :
|
||||
m_mutex(mutex),
|
||||
m_closeCB(closeCB),
|
||||
m_closed(false)
|
||||
{
|
||||
assert(m_mutex != NULL);
|
||||
}
|
||||
|
||||
CSocketOutputStream::~CSocketOutputStream()
|
||||
{
|
||||
delete m_closeCB;
|
||||
}
|
||||
|
||||
const void* CSocketOutputStream::peek(UInt32 n)
|
||||
{
|
||||
return m_buffer.peek(n);
|
||||
}
|
||||
|
||||
void CSocketOutputStream::pop(UInt32 n)
|
||||
{
|
||||
m_buffer.pop(n);
|
||||
}
|
||||
|
||||
UInt32 CSocketOutputStream::getSize() const
|
||||
{
|
||||
return m_buffer.getSize();
|
||||
}
|
||||
|
||||
void CSocketOutputStream::close()
|
||||
{
|
||||
CLock lock(m_mutex);
|
||||
if (m_closed) {
|
||||
throw XIOClosed();
|
||||
}
|
||||
|
||||
m_closed = true;
|
||||
if (m_closeCB) {
|
||||
m_closeCB->run();
|
||||
}
|
||||
}
|
||||
|
||||
UInt32 CSocketOutputStream::write(
|
||||
const void* data, UInt32 n)
|
||||
{
|
||||
CLock lock(m_mutex);
|
||||
if (m_closed) {
|
||||
throw XIOClosed();
|
||||
}
|
||||
|
||||
m_buffer.write(data, n);
|
||||
return n;
|
||||
}
|
||||
|
||||
void CSocketOutputStream::flush()
|
||||
{
|
||||
// wait until all data is written
|
||||
while (getSizeWithLock() > 0) {
|
||||
CThread::sleep(0.05);
|
||||
}
|
||||
}
|
||||
|
||||
UInt32 CSocketOutputStream::getSizeWithLock() const
|
||||
{
|
||||
CLock lock(m_mutex);
|
||||
return m_buffer.getSize();
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
#ifndef CSOCKETOUTPUTSTREAM_H
|
||||
#define CSOCKETOUTPUTSTREAM_H
|
||||
|
||||
#include "CSocketStreamBuffer.h"
|
||||
#include "IOutputStream.h"
|
||||
|
||||
class CMutex;
|
||||
class IJob;
|
||||
|
||||
class CSocketOutputStream : public IOutputStream {
|
||||
public:
|
||||
CSocketOutputStream(CMutex*, IJob* adoptedCloseCB);
|
||||
~CSocketOutputStream();
|
||||
|
||||
// manipulators
|
||||
|
||||
// peek() returns a buffer of n bytes (which must be <= getSize()).
|
||||
// pop() discards the next n bytes.
|
||||
const void* peek(UInt32 n);
|
||||
void pop(UInt32 n);
|
||||
|
||||
// accessors
|
||||
|
||||
// return the number of bytes in the buffer
|
||||
UInt32 getSize() const;
|
||||
|
||||
// IOutputStream overrides
|
||||
// these all lock the mutex for their duration
|
||||
virtual void close();
|
||||
virtual UInt32 write(const void*, UInt32 count);
|
||||
virtual void flush();
|
||||
|
||||
private:
|
||||
UInt32 getSizeWithLock() const;
|
||||
|
||||
private:
|
||||
CMutex* m_mutex;
|
||||
IJob* m_closeCB;
|
||||
CSocketStreamBuffer m_buffer;
|
||||
bool m_closed;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,106 +0,0 @@
|
|||
#include "CSocketStreamBuffer.h"
|
||||
#include <assert.h>
|
||||
|
||||
//
|
||||
// CSocketStreamBuffer
|
||||
//
|
||||
|
||||
const UInt32 CSocketStreamBuffer::kChunkSize = 4096;
|
||||
|
||||
CSocketStreamBuffer::CSocketStreamBuffer() : m_size(0)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
CSocketStreamBuffer::~CSocketStreamBuffer()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
const void* CSocketStreamBuffer::peek(UInt32 n)
|
||||
{
|
||||
assert(n <= m_size);
|
||||
|
||||
// reserve space in first chunk
|
||||
ChunkList::iterator head = m_chunks.begin();
|
||||
head->reserve(n);
|
||||
|
||||
// consolidate chunks into the first chunk until it has n bytes
|
||||
ChunkList::iterator scan = head;
|
||||
++scan;
|
||||
while (head->size() < n && scan != m_chunks.end()) {
|
||||
head->insert(head->end(), scan->begin(), scan->end());
|
||||
scan = m_chunks.erase(scan);
|
||||
}
|
||||
|
||||
return reinterpret_cast<const void*>(head->begin());
|
||||
}
|
||||
|
||||
void CSocketStreamBuffer::pop(UInt32 n)
|
||||
{
|
||||
m_size -= n;
|
||||
|
||||
// discard chunks until more than n bytes would've been discarded
|
||||
ChunkList::iterator scan = m_chunks.begin();
|
||||
while (scan->size() <= n && scan != m_chunks.end()) {
|
||||
n -= scan->size();
|
||||
scan = m_chunks.erase(scan);
|
||||
}
|
||||
|
||||
// if there's anything left over then remove it from the head chunk.
|
||||
// if there's no head chunk then we're already empty.
|
||||
if (scan == m_chunks.end()) {
|
||||
m_size = 0;
|
||||
}
|
||||
else if (n > 0) {
|
||||
scan->erase(scan->begin(), scan->begin() + n);
|
||||
}
|
||||
}
|
||||
|
||||
void CSocketStreamBuffer::write(
|
||||
const void* vdata, UInt32 n)
|
||||
{
|
||||
assert(vdata != NULL);
|
||||
|
||||
if (n == 0) {
|
||||
return;
|
||||
}
|
||||
m_size += n;
|
||||
|
||||
// cast data to bytes
|
||||
const UInt8* data = reinterpret_cast<const UInt8*>(vdata);
|
||||
|
||||
// point to last chunk if it has space, otherwise append an empty chunk
|
||||
ChunkList::iterator scan = m_chunks.end();
|
||||
if (scan != m_chunks.begin()) {
|
||||
--scan;
|
||||
if (scan->size() >= kChunkSize)
|
||||
++scan;
|
||||
}
|
||||
if (scan == m_chunks.end()) {
|
||||
scan = m_chunks.insert(scan);
|
||||
}
|
||||
|
||||
// append data in chunks
|
||||
while (n > 0) {
|
||||
// choose number of bytes for next chunk
|
||||
UInt32 count = kChunkSize - scan->size();
|
||||
if (count > n)
|
||||
count = n;
|
||||
|
||||
// transfer data
|
||||
scan->insert(scan->end(), data, data + count);
|
||||
n -= count;
|
||||
data += count;
|
||||
|
||||
// append another empty chunk if we're not done yet
|
||||
if (n > 0) {
|
||||
scan = m_chunks.insert(scan);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UInt32 CSocketStreamBuffer::getSize() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
#ifndef CSOCKETSTREAMBUFFER_H
|
||||
#define CSOCKETSTREAMBUFFER_H
|
||||
|
||||
#include "BasicTypes.h"
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
class CSocketStreamBuffer {
|
||||
public:
|
||||
CSocketStreamBuffer();
|
||||
~CSocketStreamBuffer();
|
||||
|
||||
// manipulators
|
||||
|
||||
// peek() returns a buffer of n bytes (which must be <= getSize()).
|
||||
// pop() discards the next n bytes.
|
||||
const void* peek(UInt32 n);
|
||||
void pop(UInt32 n);
|
||||
|
||||
// write() appends n bytes to the buffer
|
||||
void write(const void*, UInt32 n);
|
||||
|
||||
// accessors
|
||||
|
||||
// return the number of bytes in the buffer
|
||||
UInt32 getSize() const;
|
||||
|
||||
private:
|
||||
static const UInt32 kChunkSize;
|
||||
|
||||
typedef std::vector<UInt8> Chunk;
|
||||
typedef std::list<Chunk> ChunkList;
|
||||
|
||||
ChunkList m_chunks;
|
||||
UInt32 m_size;
|
||||
};
|
||||
|
||||
#endif
|
24
net/net.dsp
24
net/net.dsp
|
@ -95,18 +95,6 @@ SOURCE=.\CNetworkAddress.cpp
|
|||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CSocketInputStream.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CSocketOutputStream.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CSocketStreamBuffer.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CTCPListenSocket.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
@ -135,18 +123,6 @@ SOURCE=.\CNetworkAddress.h
|
|||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CSocketInputStream.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CSocketOutputStream.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CSocketStreamBuffer.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CTCPListenSocket.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
|
Loading…
Reference in New Issue