bufferConnection.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "bufferConnection.h"
00019
00020 #include <string.h>
00021
00022 using namespace std;
00023
00024 namespace eq
00025 {
00026 namespace net
00027 {
00028 BufferConnection::BufferConnection()
00029 {
00030 _state = STATE_CONNECTED;
00031 EQVERB << "New BufferConnection @" << (void*)this << endl;
00032 }
00033
00034 BufferConnection::~BufferConnection()
00035 {
00036 if( !_buffer.isEmpty( ))
00037 EQWARN << "Deleting BufferConnection with buffered data" << endl;
00038 }
00039
00040 int64_t BufferConnection::write( const void* buffer, const uint64_t bytes )
00041 {
00042 _buffer.append( reinterpret_cast< const uint8_t* >( buffer ), bytes );
00043 return bytes;
00044 }
00045
00046 void BufferConnection::sendBuffer( ConnectionPtr connection )
00047 {
00048 if( _buffer.isEmpty( ))
00049 return;
00050
00051 if( !connection )
00052 {
00053 EQWARN << "NULL connection during buffer write" << endl;
00054 return;
00055 }
00056
00057 EQCHECK( connection->send( _buffer.getData(), _buffer.getSize() ));
00058 _buffer.setSize( 0 );
00059 }
00060 }
00061 }