📄 channel.h
字号:
comparison of the two objects, #EqualTo# for same,
#LessThan# for #obj# logically less than the
object and #GreaterThan# for #obj# logically
greater than the object.
*/
virtual Comparison Compare(
const PObject & obj ///< Other PString to compare against.
) const;
/**Calculate a hash value for use in sets and dictionaries.
The hash function for strings will produce a value based on the sum of
the first three characters of the string. This is a fairly basic
function and make no assumptions about the string contents. A user may
descend from PString and override the hash function if they can take
advantage of the types of strings being used, eg if all strings start
with the letter 'A' followed by 'B or 'C' then the current hash function
will not perform very well.
@return
hash value for string.
*/
virtual PINDEX HashFunction() const;
//@}
/**@name Information functions */
//@{
/** Determine if the channel is currently open.
This indicates that read and write operations can be executed on the
channel. For example, in the #PFile# class it returns if the file is
currently open.
@return TRUE if the channel is open.
*/
virtual BOOL IsOpen() const;
/** Get the platform and I/O channel type name of the channel. For example,
it would return the filename in #PFile# type channels.
@return the name of the channel.
*/
virtual PString GetName() const;
/** Get the integer operating system handle for the channel.
@return
standard OS descriptor integer.
*/
int GetHandle() const;
/** Get the base channel of channel indirection using PIndirectChannel.
This function returns the eventual base channel for reading of a series
of indirect channels provided by descendents of #PIndirectChannel#.
The behaviour for this function is to return "this".
@return
Pointer to base I/O channel for the indirect channel.
*/
virtual PChannel * GetBaseReadChannel() const;
/** Get the base channel of channel indirection using PIndirectChannel.
This function returns the eventual base channel for writing of a series
of indirect channels provided by descendents of #PIndirectChannel#.
The behaviour for this function is to return "this".
@return
Pointer to base I/O channel for the indirect channel.
*/
virtual PChannel * GetBaseWriteChannel() const;
//@}
/**@name Reading functions */
//@{
/** Set the timeout for read operations. This may be zero for immediate
return of data through to #PMaxTimeInterval# which will wait forever for
the read request to be filled.
Note that this function may not be available, or meaningfull, for all
channels. In that case it is set but ignored.
*/
void SetReadTimeout(
const PTimeInterval & time ///< The new time interval for read operations.
);
/** Get the timeout for read operations. Note that this function may not be
available, or meaningfull, for all channels. In that case it returns the
previously set value.
@return time interval for read operations.
*/
PTimeInterval GetReadTimeout() const;
/** Low level read from the channel. This function may block until the
requested number of characters were read or the read timeout was
reached. The GetLastReadCount() function returns the actual number
of bytes read.
The GetErrorCode() function should be consulted after Read() returns
FALSE to determine what caused the failure.
@return
TRUE indicates that at least one character was read from the channel.
FALSE means no bytes were read due to timeout or some other I/O error.
*/
virtual BOOL Read(
void * buf, ///< Pointer to a block of memory to receive the read bytes.
PINDEX len ///< Maximum number of bytes to read into the buffer.
);
/**Get the number of bytes read by the last Read() call. This will be from
0 to the maximum number of bytes as passed to the Read() call.
Note that the number of bytes read may often be less than that asked
for. Aside from the most common case of being at end of file, which the
applications semantics may regard as an exception, there are some cases
where this is normal. For example, if a PTextFile channel on the
MSDOS platform is read from, then the translation of CR/LF pairs to \n
characters will result in the number of bytes returned being less than
the size of the buffer supplied.
@return
the number of bytes read.
*/
virtual PINDEX GetLastReadCount() const;
/** Read a single 8 bit byte from the channel. If one was not available
within the read timeout period, or an I/O error occurred, then the
function gives with a -1 return value.
@return
byte read or -1 if no character could be read.
*/
virtual int ReadChar();
/** Read len bytes into the buffer from the channel. This function uses
Read(), so most remarks pertaining to that function also apply to this
one. The only difference being that this function will not return until
all of the bytes have been read, or an error occurs.
@return
TRUE if the read of #len# bytes was sucessfull.
*/
BOOL ReadBlock(
void * buf, ///< Pointer to a block of memory to receive the read bytes.
PINDEX len ///< Maximum number of bytes to read into the buffer.
);
/** Read #len# character into a string from the channel. This
function simply uses ReadBlock(), so all remarks pertaining to that
function also apply to this one.
@return
String that was read.
*/
PString ReadString(PINDEX len);
/** Begin an asynchronous read from channel. The read timeout is used as in
other read operations, in this case calling the OnReadComplete()
function.
Note that if the channel is not capable of asynchronous read then this
will do a sychronous read is in the Read() function with the addition
of calling the OnReadComplete() before returning.
@return
TRUE if the read was sucessfully queued.
*/
virtual BOOL ReadAsync(
void * buf, ///< Pointer to a block of memory to receive the read bytes.
PINDEX len ///< Maximum number of bytes to read into the buffer.
);
/** User callback function for when a #ReadAsync()# call has completed or
timed out. The original pointer to the buffer passed in ReadAsync() is
passed to the function.
*/
virtual void OnReadComplete(
void * buf, ///< Pointer to a block of memory that received the read bytes.
PINDEX len ///< Actual number of bytes to read into the buffer.
);
//@}
/**@name Writing functions */
//@{
/** Set the timeout for write operations to complete. This may be zero for
immediate return through to PMaxTimeInterval which will wait forever for
the write request to be completed.
Note that this function may not be available, or meaningfull, for all
channels. In this case the parameter is et but ignored.
*/
void SetWriteTimeout(
const PTimeInterval & time ///< The new time interval for write operations.
);
/** Get the timeout for write operations to complete. Note that this
function may not be available, or meaningfull, for all channels. In
that case it returns the previously set value.
@return
time interval for writing.
*/
PTimeInterval GetWriteTimeout() const;
/** Low level write to the channel. This function will block until the
requested number of characters are written or the write timeout is
reached. The GetLastWriteCount() function returns the actual number
of bytes written.
The GetErrorCode() function should be consulted after Write() returns
FALSE to determine what caused the failure.
@return
TRUE if at least len bytes were written to the channel.
*/
virtual BOOL Write(
const void * buf, ///< Pointer to a block of memory to write.
PINDEX len ///< Number of bytes to write.
);
/** Get the number of bytes written by the last Write() call.
Note that the number of bytes written may often be less, or even more,
than that asked for. A common case of it being less is where the disk
is full. An example of where the bytes written is more is as follows.
On a #PTextFile# channel on the MSDOS platform, there is
translation of \n to CR/LF pairs. This will result in the number of
bytes returned being more than that requested.
@return
the number of bytes written.
*/
virtual PINDEX GetLastWriteCount() const;
/** Write a single character to the channel. This function simply uses the
Write() function so all comments on that function also apply.
Note that this asserts if the value is not in the range 0..255.
@return
TRUE if the byte was successfully written.
*/
BOOL WriteChar(int c);
/** Write a string to the channel. This function simply uses the Write()
function so all comments on that function also apply.
@return
TRUE if the character written.
*/
BOOL WriteString(const PString & str);
/** Begin an asynchronous write from channel. The write timeout is used as
in other write operations, in this case calling the OnWriteComplete()
function. Note that if the channel is not capable of asynchronous write
then this will do a sychronous write as in the Write() function with
the addition of calling the OnWriteComplete() before returning.
@return
TRUE of the write operation was succesfully queued.
*/
virtual BOOL WriteAsync(
const void * buf, ///< Pointer to a block of memory to write.
PINDEX len ///< Number of bytes to write.
);
/** User callback function for when a WriteAsync() call has completed or
timed out. The original pointer to the buffer passed in WriteAsync() is
passed in here and the len parameter is the actual number of characters
written.
*/
virtual void OnWriteComplete(
const void * buf, ///< Pointer to a block of memory to write.
PINDEX len ///< Number of bytes to write.
);
//@}
/**@name Miscellaneous functions */
//@{
/** Close the channel, shutting down the link to the data source.
@return TRUE if the channel successfully closed.
*/
virtual BOOL Close();
enum ShutdownValue {
ShutdownRead = 0,
ShutdownWrite = 1,
ShutdownReadAndWrite = 2
};
/** Close one or both of the data streams associated with a channel.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -