#include <CTCPSocket.h>
Inherits IDataSocket.
Inheritance diagram for CTCPSocket:
Public Member Functions | |
CTCPSocket () | |
CTCPSocket (CArchSocket) | |
~CTCPSocket () | |
virtual void | bind (const CNetworkAddress &) |
Bind socket to address. | |
virtual void | close () |
Close the stream. | |
virtual void * | getEventTarget () const |
Get event target. | |
virtual UInt32 | read (void *buffer, UInt32 n) |
Read from stream. | |
virtual void | write (const void *buffer, UInt32 n) |
Write to stream. | |
virtual void | flush () |
Flush the stream. | |
virtual void | shutdownInput () |
Shutdown input. | |
virtual void | shutdownOutput () |
Shutdown output. | |
virtual bool | isReady () const |
Test if read() will succeed. | |
virtual UInt32 | getSize () const |
Get bytes available to read. | |
virtual void | connect (const CNetworkAddress &) |
Connect socket. |
A data socket using TCP.
Definition at line 32 of file CTCPSocket.h.
void CTCPSocket::bind | ( | const CNetworkAddress & | ) | [virtual] |
Bind socket to address.
Binds the socket to a particular address.
Implements IDataSocket.
Definition at line 72 of file CTCPSocket.cpp.
References CNetworkAddress::getAddress(), and XArch::what().
void CTCPSocket::close | ( | ) | [virtual] |
Close the stream.
Closes the stream. Pending input data and buffered output data are discarded. Use flush()
before close()
to send buffered output data. Attempts to read()
after a close return 0, attempts to write()
generate output error events, and attempts to flush()
return immediately.
Reimplemented from IDataSocket.
Definition at line 86 of file CTCPSocket.cpp.
References ISocket::getDisconnectedEvent(), and XArch::what().
Referenced by ~CTCPSocket().
void CTCPSocket::connect | ( | const CNetworkAddress & | ) | [virtual] |
Connect socket.
Attempt to connect to a remote endpoint. This returns immediately and sends a connected event when successful or a connection failed event when it fails. The stream acts as if shutdown for input and output until the stream connects.
Implements IDataSocket.
Definition at line 252 of file CTCPSocket.cpp.
References CNetworkAddress::getAddress(), IDataSocket::getConnectedEvent(), and XArch::what().
void CTCPSocket::flush | ( | ) | [virtual] |
Flush the stream.
Waits until all buffered data has been written to the stream.
Implements IDataSocket.
Definition at line 175 of file CTCPSocket.cpp.
References CCondVarBase::wait().
void * CTCPSocket::getEventTarget | ( | ) | const [virtual] |
Get event target.
Returns the event target for events generated by this stream. It should be the source stream in a chain of stream filters.
Reimplemented from IDataSocket.
Definition at line 114 of file CTCPSocket.cpp.
UInt32 CTCPSocket::getSize | ( | ) | const [virtual] |
Get bytes available to read.
Returns a conservative estimate of the available bytes to read (i.e. a number not greater than the actual number of bytes). Some streams may not be able to determine this and will always return zero.
Implements IDataSocket.
Definition at line 245 of file CTCPSocket.cpp.
References CStreamBuffer::getSize().
bool CTCPSocket::isReady | ( | ) | const [virtual] |
Test if read()
will succeed.
Returns true iff an immediate read()
will return data. This may or may not be the same as getSize()
> 0, depending on the stream type.
Implements IDataSocket.
Definition at line 238 of file CTCPSocket.cpp.
References CStreamBuffer::getSize().
UInt32 CTCPSocket::read | ( | void * | buffer, | |
UInt32 | n | |||
) | [virtual] |
Read from stream.
Read up to n
bytes into buffer
, returning the number read (zero if no data is available or input is shutdown). buffer
may be NULL in which case the data is discarded.
Implements IDataSocket.
Definition at line 120 of file CTCPSocket.cpp.
References ISocket::getDisconnectedEvent(), CStreamBuffer::getSize(), CStreamBuffer::peek(), and CStreamBuffer::pop().
void CTCPSocket::shutdownInput | ( | ) | [virtual] |
Shutdown input.
Shutdown the input side of the stream. Any pending input data is discarded and further reads immediately return 0.
Implements IDataSocket.
Definition at line 184 of file CTCPSocket.cpp.
References IStream::getInputShutdownEvent().
void CTCPSocket::shutdownOutput | ( | ) | [virtual] |
Shutdown output.
Shutdown the output side of the stream. Any buffered output data is discarded and further writes generate output error events. Use flush()
before shutdownOutput()
to send buffered output data.
Implements IDataSocket.
Definition at line 211 of file CTCPSocket.cpp.
References IStream::getOutputShutdownEvent().
void CTCPSocket::write | ( | const void * | buffer, | |
UInt32 | n | |||
) | [virtual] |
Write to stream.
Write n
bytes from buffer
to the stream. If this can't complete immediately it will block. Data may be buffered in order to return more quickly. A output error event is generated when writing fails.
Implements IDataSocket.
Definition at line 143 of file CTCPSocket.cpp.
References IStream::getOutputErrorEvent(), CStreamBuffer::getSize(), and CStreamBuffer::write().