1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-15 04:42:04 +00:00
srs/trunk/src/protocol/srs_protocol_io.hpp

152 lines
4.8 KiB
C++
Raw Normal View History

/*
The MIT License (MIT)
2016-12-16 03:57:25 +00:00
Copyright (c) 2013-2017 SRS(ossrs)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
2015-09-22 01:07:07 +00:00
#ifndef SRS_PROTOCOL_IO_HPP
#define SRS_PROTOCOL_IO_HPP
/*
2015-09-22 01:07:07 +00:00
#include <srs_protocol_io.hpp>
*/
#include <srs_core.hpp>
#include <srs_kernel_io.hpp>
/**
* the system io reader/writer architecture:
2017-01-30 11:59:59 +00:00
+---------------+ +---------------+
| IStreamWriter | | IVectorWriter |
+---------------+ +---------------+
| + write() | | + writev() |
+-------------+-+ ++--------------+
+----------+ +--------------------+ /\ /\
| IReader | | IStatistic | \ /
+----------+ +--------------------+ V
| + read() | | + get_recv_bytes() | +------+----+
+------+---+ | + get_send_bytes() | | IWriter |
/ \ +---+--------------+-+ +-------+---+
| / \ / \ / \
| | | |
+------+-------------+------+ ++---------------------+--+
| IProtocolReader | | IProtocolWriter |
+---------------------------+ +-------------------------+
| + readfully() | | + set_send_timeout() |
| + set_recv_timeout() | +-------+-----------------+
+------------+--------------+ / \
/ \ |
| |
+--+-----------------------------+-+
| IProtocolReaderWriter |
+----------------------------------+
| + is_never_timeout() |
+----------------------------------+
*/
/**
* get the statistic of channel.
*/
class ISrsProtocolStatistic
{
public:
ISrsProtocolStatistic();
virtual ~ISrsProtocolStatistic();
// for protocol
public:
2014-07-06 10:44:44 +00:00
/**
* get the total recv bytes over underlay fd.
*/
virtual int64_t get_recv_bytes() = 0;
2014-07-06 10:44:44 +00:00
/**
* get the total send bytes over underlay fd.
*/
virtual int64_t get_send_bytes() = 0;
};
/**
* the reader for the protocol to read from whatever channel.
*/
2017-01-30 11:59:59 +00:00
class ISrsProtocolReader : public virtual ISrsReader, public virtual ISrsProtocolStatistic
{
public:
2014-03-18 03:32:58 +00:00
ISrsProtocolReader();
virtual ~ISrsProtocolReader();
// for protocol
public:
2014-07-06 10:44:44 +00:00
/**
* Set the timeout tm in ms for recv bytes from peer.
2017-02-05 01:15:46 +00:00
* @remark Use SRS_CONSTS_NO_TMMS to never timeout.
*/
virtual void set_recv_timeout(int64_t tm) = 0;
2014-07-06 10:44:44 +00:00
/**
* Get the timeout in ms for recv bytes from peer.
2014-07-06 10:44:44 +00:00
*/
2014-03-18 03:32:58 +00:00
virtual int64_t get_recv_timeout() = 0;
// for handshake.
public:
/**
* read specified size bytes of data
* @param nread, the actually read size, NULL to ignore.
*/
virtual int read_fully(void* buf, size_t size, ssize_t* nread) = 0;
};
/**
* the writer for the protocol to write to whatever channel.
*/
2017-01-30 11:59:59 +00:00
class ISrsProtocolWriter : public virtual ISrsWriter, public virtual ISrsProtocolStatistic
{
public:
2014-03-18 03:32:58 +00:00
ISrsProtocolWriter();
virtual ~ISrsProtocolWriter();
// for protocol
public:
2014-07-06 10:44:44 +00:00
/**
* Set the timeout tm in ms for send bytes to peer.
2017-02-05 01:15:46 +00:00
* @remark Use SRS_CONSTS_NO_TMMS to never timeout.
*/
virtual void set_send_timeout(int64_t tm) = 0;
2014-07-06 10:44:44 +00:00
/**
* Get the timeout in ms for send bytes to peer.
*/
2014-03-18 03:32:58 +00:00
virtual int64_t get_send_timeout() = 0;
};
/**
* the reader and writer.
*/
class ISrsProtocolReaderWriter : public virtual ISrsProtocolReader, public virtual ISrsProtocolWriter
{
public:
2014-03-18 03:32:58 +00:00
ISrsProtocolReaderWriter();
virtual ~ISrsProtocolReaderWriter();
// for protocol
public:
2014-03-18 03:32:58 +00:00
/**
* Whether the specified tm in ms is never timeout.
*/
virtual bool is_never_timeout(int64_t tm) = 0;
};
#endif
2014-08-02 14:18:39 +00:00