2021-05-31 05:42:20 +00:00
|
|
|
//
|
|
|
|
// Copyright (c) 2013-2021 Winlin
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
//
|
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
|
|
|
/**
|
2019-04-17 00:23:15 +00:00
|
|
|
* The system io reader/writer architecture:
|
2017-03-25 09:21:39 +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() | +-------+-----------------+
|
|
|
|
* +------------+--------------+ / \
|
|
|
|
* / \ |
|
|
|
|
* | |
|
|
|
|
* +--+-----------------------------+-+
|
2018-12-23 12:08:04 +00:00
|
|
|
* | IProtocolReadWriter |
|
2017-03-25 09:21:39 +00:00
|
|
|
* +----------------------------------+
|
|
|
|
*/
|
2014-06-19 02:34:10 +00:00
|
|
|
|
|
|
|
/**
|
2019-04-17 00:23:15 +00:00
|
|
|
* Get the statistic of channel.
|
2017-03-25 09:21:39 +00:00
|
|
|
*/
|
2014-06-19 02:34:10 +00:00
|
|
|
class ISrsProtocolStatistic
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ISrsProtocolStatistic();
|
|
|
|
virtual ~ISrsProtocolStatistic();
|
2019-04-17 00:23:15 +00:00
|
|
|
// For protocol
|
2014-06-19 02:34:10 +00:00
|
|
|
public:
|
2019-04-17 00:23:15 +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;
|
2019-04-17 00:23:15 +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.
|
|
|
|
*/
|
2021-05-14 10:17:42 +00:00
|
|
|
class ISrsProtocolReader : 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:
|
2019-04-17 00:31:53 +00:00
|
|
|
// Set the timeout tm in srs_utime_t for recv bytes from peer.
|
2019-04-17 00:23:15 +00:00
|
|
|
// @remark Use SRS_UTIME_NO_TIMEOUT to never timeout.
|
2019-04-17 00:31:53 +00:00
|
|
|
virtual void set_recv_timeout(srs_utime_t tm) = 0;
|
2019-04-18 00:50:43 +00:00
|
|
|
// Get the timeout in srs_utime_t for recv bytes from peer.
|
2019-04-17 00:38:34 +00:00
|
|
|
virtual srs_utime_t get_recv_timeout() = 0;
|
2019-04-17 00:23:15 +00:00
|
|
|
// For handshake.
|
2014-12-02 14:26:20 +00:00
|
|
|
public:
|
2019-04-17 00:23:15 +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.
|
|
|
|
*/
|
2021-05-14 10:17:42 +00:00
|
|
|
class ISrsProtocolWriter : 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();
|
2019-04-17 00:23:15 +00:00
|
|
|
// For protocol
|
2014-03-01 04:43:04 +00:00
|
|
|
public:
|
2019-04-17 00:23:15 +00:00
|
|
|
// Set the timeout tm in srs_utime_t for send bytes to peer.
|
|
|
|
// @remark Use SRS_UTIME_NO_TIMEOUT to never timeout.
|
2019-04-17 00:18:37 +00:00
|
|
|
virtual void set_send_timeout(srs_utime_t tm) = 0;
|
2019-04-17 00:23:15 +00:00
|
|
|
// Get the timeout in srs_utime_t for send bytes to peer.
|
|
|
|
virtual srs_utime_t get_send_timeout() = 0;
|
2014-03-01 04:43:04 +00:00
|
|
|
};
|
|
|
|
|
2014-06-19 02:34:10 +00:00
|
|
|
/**
|
2019-04-17 00:23:15 +00:00
|
|
|
* The reader and writer.
|
2017-03-25 09:21:39 +00:00
|
|
|
*/
|
2021-05-14 10:17:42 +00:00
|
|
|
class ISrsProtocolReadWriter : public ISrsProtocolReader, public ISrsProtocolWriter
|
2014-03-01 04:43:04 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-12-23 12:08:04 +00:00
|
|
|
ISrsProtocolReadWriter();
|
|
|
|
virtual ~ISrsProtocolReadWriter();
|
2014-03-01 04:43:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
2014-08-02 14:18:39 +00:00
|
|
|
|