yate学习--yateclass.h--class YATE_API Stream

转载说明:

yate中所有基于流操作的基类:

/**
 * Base class for encapsulating system dependent stream capable objects
 * 封装能够基于系统的流对象的基类
 * @short An abstract stream class capable of reading and writing
 * @short 能够读和写的抽象类
 */
class YATE_API Stream
{
public:
    /**
     * Enumerate seek start position
     * 开寻找位置的枚举
     */
    enum SeekPos {
	SeekBegin,                       // Seek from start of stream
	SeekEnd,                         // Seek from stream end
	SeekCurrent                      // Seek from current position
    };

    /**
     * Destructor, terminates the stream
     * 析构函数,结束流
     */
    virtual ~Stream();

    /**
     * Get the error code of the last operation on this stream
     * 获取最近操作这个流的错误码
     * @return Error code generated by the last operation on this stream
     * @返回最近操作这个流产生的错误码
     */
    inline int error() const
	{ return m_error; }

    /**
     * Closes the stream
     * 关闭这个流
     * @return True if the stream was (already) closed, false if an error occured
     * @返回true,如果流被关闭了(已经被关闭了),false,发生了错误
     */
    virtual bool terminate() = 0;

    /**
     * Check if the last error code indicates a retryable condition
     * 检查最近的错误码,表明一个可重操作的条件
     * @return True if error was temporary and operation should be retried
     * @返回true,如果错误是临时的并且可重新操作的
     */
    virtual bool canRetry() const;

    /**
     * Check if the last error code indicates a non blocking operation in progress
     * 核查最近的错误码,表明一个正在进行的非阻塞操作
     * @return True if a non blocking operation is in progress
     * @返回true,如果正在进行一个非阻塞的操作
     */
    virtual bool inProgress() const;

    /**
     * Check if this stream is valid
     * 检查该流是否为有效的
     * @return True if the stream is valid, false if it's invalid or closed
     * @返回为true,如果该流有效,false,该流无效或者已经关闭
     */
    virtual bool valid() const = 0;

    /**
     * Set the blocking or non-blocking operation mode of the stream
     * 设置该流阻塞或者非阻塞模式
     * @param block True if I/O operations should block, false for non-blocking
     * @参数blcok,为true,如果I/O操作是阻塞,false,非阻塞
     * @return True if operation was successfull, false if an error occured
     * @返回true, 如果操作成功, false,发生了错误
     */
    virtual bool setBlocking(bool block = true);

    /**
     * Write data to a connected stream
     * 写数据到一个已经连接的流
     * @param buffer Buffer for data transfer
     * @参数buffer,数据传输的缓冲区
     * @param length Length of the buffer
     * @参数length,缓冲区的长度
     * @return Number of bytes transferred, negative if an error occurred
     * @返回已经传输的字节,负数,发生了错误
     */
    virtual int writeData(const void* buffer, int length) = 0;

    /**
     * Write a C string to a connected stream
     * 写入一个C的字符串到已经连接的流
     * @param str String to send over the stream
     * @参数str,要发送的字符串
     * @return Number of bytes transferred, negative if an error occurred
     * @返回已经传输的字节,负数,发生了错误
     */
    int writeData(const char* str);

    /**
     * Write a String to a connected stream
     * 写字符串到一个已经连接的流
     * @param str String to send over the stream
     * @参数str,要发送的字符串
     * @return Number of bytes transferred, negative if an error occurred
     * @返回已经传输的字节,负数,发生了错误
     */
    inline int writeData(const String& str)
	{ return writeData(str.c_str(), str.length()); }

    /**
     * Write a Data block to a connected stream
     * 写数据块到一个已经连接的流
     * @param buf DataBlock to send over the stream
     * @参数buf,要发送的数据块
     * @return Number of bytes transferred, negative if an error occurred
     * @返回已经传输的字节,负数,发生了错误
     */
    inline int writeData(const DataBlock& buf)
	{ return writeData(buf.data(), buf.length()); }

    /**
     * Receive data from a connected stream
     * 从一个连接的流中接收数据
     * @param buffer Buffer for data transfer
     * @参数buffer,数据传输的缓冲区
     * @param length Length of the buffer
     * @参数length,缓冲区的长度
     * @return Number of bytes transferred, negative if an error occurred
     * @返回已经传输的字节,负数,发生了错误
     */
    virtual int readData(void* buffer, int length) = 0;

    /**
     * Find the length of the stream if it has one
     * 如果流存在,找到该流的长度
     * @return Length of the stream or zero if length is not defined
     * @返回该流的长度,为 0 如果该流的长度没有定义
     */
    virtual int64_t length();

    /**
     * Set the stream read/write pointer
     * 设置该流的读/写指针
     * @param pos The seek start as enumeration
     * @参数pos,enumeration 中开始跳转的地址
     * @param offset The number of bytes to move the pointer from starting position
     * @参数offset, 从开始地址移动的指针的字节数
     * @return The new position of the stream read/write pointer. Negative on failure
     * @返回读/写指针的新位置,负数为失败
     */
    virtual int64_t seek(SeekPos pos, int64_t offset = 0);

    /**
     * Set the read/write pointer from begin of stream
     * 设置该流的读/写指针从流开始的位置
     * @param offset The position in stream to move the pointer
     * @参数offset, 从开始地址移动的指针的字节数
     * @return The new position of the stream read/write pointer. Negative on failure
     * @返回读/写指针的新位置,负数为失败
     */
    inline int64_t seek(int64_t offset)
	{ return seek(SeekBegin,offset); }

    /**
     * Allocate a new pair of unidirectionally pipe connected streams
     * 分配流一对新的单向的管道
     * @param reader Reference of a pointer receiving the newly allocated reading side of the pipe
     * @参数reader,读取的指针
     * @param writer Reference of a pointer receiving the newly allocated writing side of the pipe
     * @参数writer,写入的指针
     * @return True is the stream pipe was created successfully
     * @返回true,流管道创建成功
     */
    static bool allocPipe(Stream*& reader, Stream*& writer);

    /**
     * Allocate a new pair of bidirectionally connected streams
     * 分配流一对新的双向
     * @param str1 Reference of a pointer receiving the newly allocated 1st end of the pair
     * @参数str1,第头端的接收引用指针
     * @param str2 Reference of a pointer receiving the newly allocated 2nd end of the pair
     * @参数str2,第尾端的接收引用指针
     * @return True is the stream pair was created successfully
     * @返回true,流创建成功
     */
    static bool allocPair(Stream*& str1, Stream*& str2);

    /**
     * Check if operating system supports unidirectional stream pairs
     * 检查操作系统是否支持单向的流
     * @return True if unidirectional pipes can be created
     * @返回true,如果单向管道被创建
     */
    static bool supportsPipes();

    /**
     * Check if operating system supports bidirectional stream pairs
     * 检查操作系统是否支持双向的流
     * @return True if bidirectional pairs can be created
     */
    static bool supportsPairs();

protected:
    /**
     * Default constructor
     * 默认的构造函数
     */
    inline Stream()
	: m_error(0)
	{ }

    /**
     * Clear the last error code
     * 清除最后的错误码
     */
    inline void clearError()
	{ m_error = 0; }

    int m_error;
};
时间: 2024-11-05 19:30:55

yate学习--yateclass.h--class YATE_API Stream的相关文章

yate学习--yateclass.h--class YATE_API Socket : public Stream

请声明出处: Socket,网络套接字的类,包括创建.绑定.监听.接受.发送.接收等操作: /** * This class encapsulates a system dependent socket in a system independent abstraction * 这个类封装了一个依赖于系统的套接字系统独立的抽象 * @short A generic socket class * @short 一般的套接字的类 */ class YATE_API Socket : public S

yate学习--yateclass.h--class YATE_API DebugEnabler

请声明转载出: DebugEnabler,这个类用于保存和修改调试级别,也就是日志的打印级别: /** * Holds a local debugging level that can be modified separately from the * global debugging * 保留本地的调试级别,这个级别能被个别的全局调试修改 * @short A holder for a debug level * @short 保存一个调试级别 */ class YATE_API DebugE

yate学习--yateclass.h--class YATE_API NamedCounter : public String

请声明出处: NamedCounter,对象命名的计数器: /** * An atomic counter with an associated name * 关联名的原子计数器 * @short Atomic counter with name * @short 名字的原子计数器 */ class YATE_API NamedCounter : public String { YNOCOPY(NamedCounter); // no automatic copies please public

yate学习--yateclass.h--class YATE_API RefObject : public GenObject

请声明出处: 对象的引用计数的类,基本大部分的类都继承了该类: /** * A reference counted object. * 引用计数的对象 * Whenever using multiple inheritance you should inherit this class virtually. * 使用多重继承,一般都会继承这个类 */ class YATE_API RefObject : public GenObject { YNOCOPY(RefObject); // no a

How to use VideoToolbox to decompress H.264 video stream

来源:http://stackoverflow.com/questions/29525000/how-to-use-videotoolbox-to-decompress-h-264-video-stream/ How to use VideoToolbox to decompress H.264 video stream up vote 15 down vote favorite 12 I had a lot of trouble figuring out how to use Apple's

C#学习(八)之Stream

这一周章老师讲了有关Stream的知识,本次学习记录就围绕着Stream展开. 首先先介绍C#中一些有关文件操作的知识. 先看下面的代码: 1 //从环境变量"SystemRoot"中得到特定字符串的值,“SystemRoot”代表Windows系统启动目录 2 string theDirectory = Environment.GetEnvironmentVariable("SystemRoot"); 3 Console.WriteLine(theDirector

yate学习--./yate/packingyate.logrotate

上一篇文章记录了yate学习--./yate/tools/log_rotate.sh: 今天继续看和日志部分的脚本./yate/packingyate.logrotate,先看看脚本源码. # Have to rotate the log and CDR files before each reaches 2GB in size /var/log/yate /var/log/yate-cdr.tsv { size=100M rotate 5 missingok sharedscripts not

JAVA8学习——从使用角度深入Stream流(学习过程)

Stream 流 初识Stream流 简单认识一下Stream:Stream类中的官方介绍: /** * A sequence of elements supporting sequential and parallel aggregate * operations. The following example illustrates an aggregate operation using * {@link Stream} and {@link IntStream}: * * <pre>{@

yate学习--yatengine.h--class YATE_API MessageReceiver : public GenObject

请声明出处: MessageReceiver,这个类是一个消息接受的基类: /** * A multiple message receiver to be invoked by a message relay * 多个消息接收器调用消息传递 * @short A multiple message receiver * @short 多个消息接收器 */ class YATE_API MessageReceiver : public GenObject { public: /** * This m