2017-03-25 09:21:39 +00:00
|
|
|
/**
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
2019-01-01 13:37:28 +00:00
|
|
|
* Copyright (c) 2013-2019 Winlin
|
2017-03-25 09:21:39 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2014-03-01 04:43:04 +00:00
|
|
|
|
2015-09-22 01:07:07 +00:00
|
|
|
#ifndef SRS_PROTOCOL_IO_HPP
|
|
|
|
#define SRS_PROTOCOL_IO_HPP
|
2014-03-01 04:43:04 +00:00
|
|
|
|
|
|
|
#include <srs_core.hpp>
|
|
|
|
|
2017-01-30 11:35:04 +00:00
|
|
|
#include <srs_kernel_io.hpp>
|
2014-03-01 04:43:04 +00:00
|
|
|
|
2014-06-19 02:34:10 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* the system io reader/writer architecture:
|
|
|
|
* +---------------+ +---------------+
|
|
|
|
* | IStreamWriter | | IVectorWriter |
|
|
|
|
* +---------------+ +---------------+
|
|
|
|
* | + write() | | + writev() |
|
|
|
|
* +-------------+-+ ++--------------+
|
|
|
|
* +----------+ +--------------------+ /\ /\
|
|
|
|
* | IReader | | IStatistic | \ /
|
|
|
|
* +----------+ +--------------------+ V
|
|
|
|
* | + read() | | + get_recv_bytes() | +------+----+
|
|
|
|
* +------+---+ | + get_send_bytes() | | IWriter |
|
|
|
|
* / \ +---+--------------+-+ +-------+---+
|
|
|
|
* | / \ / \ / \
|
|
|
|
* | | | |
|
|
|
|
* +------+-------------+------+ ++---------------------+--+
|
|
|
|
* | IProtocolReader | | IProtocolWriter |
|
|
|
|
* +---------------------------+ +-------------------------+
|
|
|
|
* | + readfully() | | + set_send_timeout() |
|
|
|
|
* | + set_recv_timeout() | +-------+-----------------+
|
|
|
|
* +------------+--------------+ / \
|
|
|
|
* / \ |
|
|
|
|
* | |
|
|
|
|
* +--+-----------------------------+-+
|
2018-12-23 12:08:04 +00:00
|
|
|
* | IProtocolReadWriter |
|
2017-03-25 09:21:39 +00:00
|
|
|
* +----------------------------------+
|
|
|
|
* | + is_never_timeout() |
|
|
|
|
* +----------------------------------+
|
|
|
|
*/
|
2014-06-19 02:34:10 +00:00
|
|
|
|
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* get the statistic of channel.
|
|
|
|
*/
|
2014-06-19 02:34:10 +00:00
|
|
|
class ISrsProtocolStatistic
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ISrsProtocolStatistic();
|
|
|
|
virtual ~ISrsProtocolStatistic();
|
2018-12-23 12:08:04 +00:00
|
|
|
// for protocol
|
2014-06-19 02:34:10 +00:00
|
|
|
public:
|
2014-07-06 10:44:44 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* get the total recv bytes over underlay fd.
|
|
|
|
*/
|
2014-06-19 02:34:10 +00:00
|
|
|
virtual int64_t get_recv_bytes() = 0;
|
2014-07-06 10:44:44 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* get the total send bytes over underlay fd.
|
|
|
|
*/
|
2014-06-19 02:34:10 +00:00
|
|
|
virtual int64_t get_send_bytes() = 0;
|
|
|
|
};
|
|
|
|
|
2014-03-01 04:43:04 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* the reader for the protocol to read from whatever channel.
|
|
|
|
*/
|
2018-12-23 11:54:08 +00:00
|
|
|
class ISrsProtocolReader : virtual public ISrsReader, virtual public ISrsProtocolStatistic
|
2014-03-01 04:43:04 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
ISrsProtocolReader();
|
|
|
|
virtual ~ISrsProtocolReader();
|
2018-12-23 12:08:04 +00:00
|
|
|
// for protocol
|
2014-03-01 04:43:04 +00:00
|
|
|
public:
|
2014-07-06 10:44:44 +00:00
|
|
|
/**
|
2017-01-17 04:25:30 +00:00
|
|
|
* Set the timeout tm in ms for recv bytes from peer.
|
2019-04-11 01:33:26 +00:00
|
|
|
* @remark Use SRS_UTIME_NO_TIMEOUT to never timeout.
|
2017-01-17 04:25:30 +00:00
|
|
|
*/
|
|
|
|
virtual void set_recv_timeout(int64_t tm) = 0;
|
2014-07-06 10:44:44 +00:00
|
|
|
/**
|
2017-01-17 04:25:30 +00:00
|
|
|
* Get the timeout in ms for recv bytes from peer.
|
2017-03-25 09:21:39 +00:00
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
virtual int64_t get_recv_timeout() = 0;
|
2018-12-23 12:08:04 +00:00
|
|
|
// for handshake.
|
2014-12-02 14:26:20 +00:00
|
|
|
public:
|
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* read specified size bytes of data
|
|
|
|
* @param nread, the actually read size, NULL to ignore.
|
|
|
|
*/
|
2017-12-31 12:52:04 +00:00
|
|
|
virtual srs_error_t read_fully(void* buf, size_t size, ssize_t* nread) = 0;
|
2014-03-01 04:43:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* the writer for the protocol to write to whatever channel.
|
|
|
|
*/
|
2018-12-23 11:54:08 +00:00
|
|
|
class ISrsProtocolWriter : virtual public ISrsWriter, virtual public ISrsProtocolStatistic
|
2014-03-01 04:43:04 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
ISrsProtocolWriter();
|
|
|
|
virtual ~ISrsProtocolWriter();
|
2018-12-23 12:08:04 +00:00
|
|
|
// for protocol
|
2014-03-01 04:43:04 +00:00
|
|
|
public:
|
2014-07-06 10:44:44 +00:00
|
|
|
/**
|
2017-01-17 04:25:30 +00:00
|
|
|
* Set the timeout tm in ms for send bytes to peer.
|
2019-04-11 01:33:26 +00:00
|
|
|
* @remark Use SRS_UTIME_NO_TIMEOUT to never timeout.
|
2017-01-17 04:25:30 +00:00
|
|
|
*/
|
|
|
|
virtual void set_send_timeout(int64_t tm) = 0;
|
2014-07-06 10:44:44 +00:00
|
|
|
/**
|
2017-01-17 04:25:30 +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;
|
2014-03-01 04:43:04 +00:00
|
|
|
};
|
|
|
|
|
2014-06-19 02:34:10 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* the reader and writer.
|
|
|
|
*/
|
2018-12-23 12:08:04 +00:00
|
|
|
class ISrsProtocolReadWriter : virtual public ISrsProtocolReader, virtual public ISrsProtocolWriter
|
2014-03-01 04:43:04 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-12-23 12:08:04 +00:00
|
|
|
ISrsProtocolReadWriter();
|
|
|
|
virtual ~ISrsProtocolReadWriter();
|
|
|
|
// for protocol
|
2014-03-01 04:43:04 +00:00
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
/**
|
2017-01-17 04:25:30 +00:00
|
|
|
* Whether the specified tm in ms is never timeout.
|
|
|
|
*/
|
|
|
|
virtual bool is_never_timeout(int64_t tm) = 0;
|
2014-03-01 04:43:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
2014-08-02 14:18:39 +00:00
|
|
|
|