Deskflow 1.22.0.197
Keyboard and mouse sharing utility
Loading...
Searching...
No Matches
TCPSocket Class Reference

TCP data socket. More...

#include <TCPSocket.h>

Inheritance diagram for TCPSocket:
Collaboration diagram for TCPSocket:

Public Member Functions

 TCPSocket (IEventQueue *events, SocketMultiplexer *socketMultiplexer, IArchNetwork::AddressFamily family=IArchNetwork::AddressFamily::INet)
 TCPSocket (IEventQueue *events, SocketMultiplexer *socketMultiplexer, ArchSocket socket)
 TCPSocket (TCPSocket const &)=delete
 TCPSocket (TCPSocket &&)=delete
 ~TCPSocket () override
TCPSocketoperator= (TCPSocket const &)=delete
TCPSocketoperator= (TCPSocket &&)=delete
void bind (const NetworkAddress &) override
 Bind socket to address.
void close () override
 Close socket.
void * getEventTarget () const override
 Get event target.
uint32_t read (void *buffer, uint32_t n) override
 Read from stream.
void write (const void *buffer, uint32_t n) override
 Write to stream.
void flush () override
 Flush the stream.
void shutdownInput () override
 Shutdown input.
void shutdownOutput () override
 Shutdown output.
bool isReady () const override
 Test if read() will succeed.
bool isFatal () const override
uint32_t getSize () const override
 Get bytes available to read.
void connect (const NetworkAddress &) override
 Connect socket.
virtual ISocketMultiplexerJobnewJob ()
Public Member Functions inherited from IDataSocket
 IDataSocket (const IEventQueue *events)
Public Member Functions inherited from ISocket
Public Member Functions inherited from IInterface
virtual ~IInterface ()=default
 Interface destructor does nothing.
Public Member Functions inherited from deskflow::IStream
 IStream ()=default

Protected Types

enum class  JobResult { Break = -1 , Retry , New }

Protected Member Functions

ArchSocket getSocket ()
IEventQueuegetEvents ()
virtual JobResult doRead ()
virtual JobResult doWrite ()
void setJob (ISocketMultiplexerJob *)
bool isConnected () const
void setConnected (bool connected)
bool isReadable () const
void setReadable (bool readable)
bool isWritable () const
void setWritable (bool canWrite)
MutexgetMutex ()
void sendEvent (EventTypes)
void discardWrittenData (int bytesWrote)

Protected Attributes

IEventQueuem_events
StreamBuffer m_inputBuffer
StreamBuffer m_outputBuffer

Detailed Description

TCP data socket.

A data socket using TCP.

Member Enumeration Documentation

◆ JobResult

enum class TCPSocket::JobResult
strongprotected
Enumerator
Break 

Break the Job chain.

Retry 

Retry the same job.

New 

Require a new job.

Constructor & Destructor Documentation

◆ TCPSocket() [1/4]

TCPSocket::TCPSocket ( IEventQueue * events,
SocketMultiplexer * socketMultiplexer,
IArchNetwork::AddressFamily family = IArchNetwork::AddressFamily::INet )

◆ TCPSocket() [2/4]

TCPSocket::TCPSocket ( IEventQueue * events,
SocketMultiplexer * socketMultiplexer,
ArchSocket socket )

◆ TCPSocket() [3/4]

TCPSocket::TCPSocket ( TCPSocket const & )
delete

◆ TCPSocket() [4/4]

TCPSocket::TCPSocket ( TCPSocket && )
delete

◆ ~TCPSocket()

TCPSocket::~TCPSocket ( )
override

Member Function Documentation

◆ bind()

void TCPSocket::bind ( const NetworkAddress & )
overridevirtual

Bind socket to address.

Binds the socket to a particular address.

Implements IDataSocket.

◆ close()

void TCPSocket::close ( )
overridevirtual

Close socket.

Closes the socket. This should flush the output stream.

Reimplemented from IDataSocket.

◆ connect()

void TCPSocket::connect ( const NetworkAddress & )
overridevirtual

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.

◆ discardWrittenData()

void TCPSocket::discardWrittenData ( int bytesWrote)
protected

◆ doRead()

TCPSocket::JobResult TCPSocket::doRead ( )
protectedvirtual

Reimplemented in SecureSocket.

◆ doWrite()

TCPSocket::JobResult TCPSocket::doWrite ( )
protectedvirtual

Reimplemented in SecureSocket.

◆ flush()

void TCPSocket::flush ( )
overridevirtual

Flush the stream.

Waits until all buffered data has been written to the stream.

Implements IDataSocket.

◆ getEvents()

IEventQueue * TCPSocket::getEvents ( )
inlineprotected

◆ getEventTarget()

void * TCPSocket::getEventTarget ( ) const
overridevirtual

Get event target.

Returns the event target for events generated by this socket.

Reimplemented from IDataSocket.

◆ getMutex()

Mutex & TCPSocket::getMutex ( )
inlineprotected

◆ getSize()

uint32_t TCPSocket::getSize ( ) const
overridevirtual

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.

◆ getSocket()

ArchSocket TCPSocket::getSocket ( )
inlineprotected

◆ isConnected()

bool TCPSocket::isConnected ( ) const
inlineprotected

◆ isFatal()

bool TCPSocket::isFatal ( ) const
overridevirtual

Implements IDataSocket.

◆ isReadable()

bool TCPSocket::isReadable ( ) const
inlineprotected

◆ isReady()

bool TCPSocket::isReady ( ) const
overridevirtual

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.

◆ isWritable()

bool TCPSocket::isWritable ( ) const
inlineprotected

◆ newJob()

ISocketMultiplexerJob * TCPSocket::newJob ( )
virtual

Reimplemented in SecureSocket.

◆ operator=() [1/2]

TCPSocket & TCPSocket::operator= ( TCPSocket && )
delete

◆ operator=() [2/2]

TCPSocket & TCPSocket::operator= ( TCPSocket const & )
delete

◆ read()

uint32_t TCPSocket::read ( void * buffer,
uint32_t n )
overridevirtual

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 nullptr in which case the data is discarded.

Implements IDataSocket.

◆ sendEvent()

void TCPSocket::sendEvent ( EventTypes type)
protected

◆ setConnected()

void TCPSocket::setConnected ( bool connected)
inlineprotected

◆ setJob()

void TCPSocket::setJob ( ISocketMultiplexerJob * job)
protected

◆ setReadable()

void TCPSocket::setReadable ( bool readable)
inlineprotected

◆ setWritable()

void TCPSocket::setWritable ( bool canWrite)
inlineprotected

◆ shutdownInput()

void TCPSocket::shutdownInput ( )
overridevirtual

Shutdown input.

Shutdown the input side of the stream. Any pending input data is discarded and further reads immediately return 0.

Implements IDataSocket.

◆ shutdownOutput()

void TCPSocket::shutdownOutput ( )
overridevirtual

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.

◆ write()

void TCPSocket::write ( const void * buffer,
uint32_t n )
overridevirtual

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.

Member Data Documentation

◆ m_events

IEventQueue* TCPSocket::m_events
protected

◆ m_inputBuffer

StreamBuffer TCPSocket::m_inputBuffer
protected

◆ m_outputBuffer

StreamBuffer TCPSocket::m_outputBuffer
protected

The documentation for this class was generated from the following files: