22 #ifndef STREAMCONNECTION_H_
23 #define STREAMCONNECTION_H_
30 #include <ibrcommon/thread/Mutex.h>
31 #include <ibrcommon/thread/MutexLock.h>
32 #include <ibrcommon/thread/Timer.h>
33 #include <ibrcommon/Exceptions.h>
34 #include <ibrcommon/thread/Queue.h>
60 : ibrcommon::IOException(
"Transmission was interrupted."),
_bundle(bundle),
_position(position)
214 class StreamBuffer :
public std::basic_streambuf<char, std::char_traits<char> >,
public ibrcommon::TimerCallback
231 virtual ~StreamBuffer();
238 const StreamContactHeader
handshake(
const StreamContactHeader &header);
272 size_t timeout(ibrcommon::Timer *timer);
282 virtual std::char_traits<char>::int_type overflow(std::char_traits<char>::int_type = std::char_traits<char>::eof());
283 virtual std::char_traits<char>::int_type underflow();
294 void __error()
const;
304 STREAM_FAILED = 1 << 0,
307 STREAM_HANDSHAKE = 1 << 3,
308 STREAM_SHUTDOWN = 1 << 4,
309 STREAM_CLOSED = 1 << 5,
310 STREAM_REJECT = 1 << 6,
311 STREAM_SKIP = 1 << 7,
312 STREAM_ACK_SUPPORT = 1 << 8,
313 STREAM_NACK_SUPPORT = 1 << 9,
314 STREAM_SOB = 1 << 10,
315 STREAM_TIMER_SUPPORT = 1 << 11
320 bool get(
const StateBits bit)
const;
321 void set(
const StateBits bit);
322 void unset(
const StateBits bit);
326 ibrcommon::Mutex _statelock;
332 std::vector<char> in_buf_;
335 std::vector<char> out_buf_;
337 ibrcommon::Mutex _sendlock;
339 std::iostream &_stream;
345 ibrcommon::Queue<StreamDataSegment> _segments;
346 std::queue<StreamDataSegment> _rejected_segments;
348 Length _underflow_data_remain;
349 State _underflow_state;
351 ibrcommon::Timer _idle_timer;
354 void connectionTimeout();
359 void eventBundleRefused();
360 void eventBundleForwarded();
362 StreamConnection::Callback &_callback;
366 StreamConnection::StreamBuffer _buf;
368 ibrcommon::Mutex _shutdown_reason_lock;
StreamShutdownException(string what="Shutdown message received.")
ibrcommon::socketstream * _conn
StreamClosedException(string what="The stream has been closed.")
TransmissionInterruptedException(const dtn::data::Bundle &bundle, const dtn::data::Length &position)
const dtn::data::Bundle _bundle
virtual void eventShutdown(StreamConnection::ConnectionShutdownCases csc)=0
StreamConnection(StreamConnection::Callback &cb, iostream &stream, const dtn::data::Length buffer_size=4096)
StreamErrorException(string what="StreamError")
virtual void eventConnectionUp(const StreamContactHeader &header)=0
virtual ~StreamConnection()
void handshake(const dtn::data::EID &eid, const dtn::data::Timeout &timeout, const dtn::data::Bitset< StreamContactHeader::HEADER_BITS > &flags)
void enableIdleTimeout(const dtn::data::Timeout &seconds)
void shutdown(ConnectionShutdownCases csc=CONNECTION_SHUTDOWN_SIMPLE_SHUTDOWN)
virtual void eventBundleAck(const dtn::data::Length &ack)=0
const dtn::data::Length _position
virtual ~TransmissionInterruptedException()
virtual void addTrafficIn(size_t)
virtual void eventTimeout()=0
virtual void eventConnectionDown()=0
virtual void eventError()=0
virtual void addTrafficOut(size_t)
virtual void eventBundleForwarded()=0
virtual void eventBundleRefused()=0