Jpp
|
Socket input channel. More...
#include <JSocketChannel.hh>
Public Types | |
enum | JStatus_t { IO_RESET = -1, IO_READY = 0, IO_BUSY = +1 } |
enum | JType { IO_PREFIX = 1, IO_DATA = 2 } |
Public Member Functions | |
JSocketInputChannel (JSocket &socket) | |
Constructor. More... | |
JStatus_t | read () |
Interruptable read method. More... | |
void | reset () |
Reset channel. More... | |
virtual int | read (char *buffer, const int length) |
Read data from socket. More... | |
int | shutdown () |
Shut down socket. More... | |
void | setNonBlocking (const bool on) |
Set non-blocking of I/O. More... | |
bool | getNonBlocking () const |
Get non-blocking of I/O. More... | |
void | setKeepAlive (const bool on) |
Set keep alive of socket. More... | |
bool | getKeepAlive () const |
Get keep alive of socket. More... | |
void | setKeepIdle (const int t_s) |
Set the TCP idle time. More... | |
void | setKeepCnt (const int count) |
Set the TCP idle count. More... | |
void | setKeepIntvl (const int t_s) |
Set the TCP interval time. More... | |
void | setReuseAddress (const bool on) |
Set reuse address. More... | |
bool | getReuseAddress () const |
Get reuse address. More... | |
void | setTcpNoDelay (const bool on) |
Set TCP no-delay. More... | |
bool | getTcpNoDelay () const |
Get TCP no-delay. More... | |
void | setReceiveBufferSize (const int size) |
Set receive buffer size. More... | |
int | getReceiveBufferSize () const |
Set receive buffer size. More... | |
void | setSendBufferSize (const int size) |
Set send buffer size. More... | |
int | getSendBufferSize () const |
Get send buffer size. More... | |
virtual int | write (const char *buffer, const int length) |
Write data to socket. More... | |
void | accept (const int server) |
Accept connection from a server. More... | |
void | connect (const int port) |
Connect to port on local host. More... | |
void | connect (const std::string &host_name, const int port) |
Connect to port on specified host. More... | |
void | connect (const int ip_number, const int port) |
Connect to port on specified host. More... | |
void | close () |
Close file. More... | |
bool | in_avail (JTimeval timeout=JTimeval::min()) const |
Check availability of input. More... | |
bool | out_avail (JTimeval timeout=JTimeval::min()) const |
Check availability of output. More... | |
virtual bool | good () const |
Check status. More... | |
virtual bool | fail () const |
Check status. More... | |
virtual bool | bad () const |
Check status. More... | |
virtual bool | eof () const |
Check end of file. More... | |
bool | less (const JAbstractFile &file) const |
Less than operation. More... | |
int | getFileDescriptor () const |
Get file descriptor. More... | |
bool | is_open () const |
Get open status. More... | |
const sockaddr * | getSockaddr () const |
Get sockaddr. More... | |
sockaddr * | getSockaddr () |
Get sockaddr. More... | |
int | getFamily () const |
Get family. More... | |
void | setFamily (const int family) |
Set family. More... | |
std::string | getHostname () const |
Get host name. More... | |
int | getIPnumber () const |
Get IP number. More... | |
void | setIPnumber (const int ip_number) |
Set IP number. More... | |
void | setIPnumber () |
Set any IP number. More... | |
int | getPort () const |
Get port number. More... | |
void | setPort (const int port) |
Set port number. More... | |
int | getSize () const |
Get size of pending data. More... | |
void | set (const JSocketBuffer< JElement_t > &buffer) |
Initialise buffer. More... | |
void | set (JElement_t *buffer, const int length) |
Initialise buffer. More... | |
JStatus_t | getStatus () const |
Get status of I/O. More... | |
bool | isReset () const |
Check reset status. More... | |
bool | isBusy () const |
Check busy status. More... | |
bool | isReady () const |
Check ready status. More... | |
int | getCounter () const |
Get number of I/O attempts. More... | |
int | size () const |
Get size. More... | |
const char * | data () const |
Get data. More... | |
int | getRemainingSize () const |
Get remaining size. More... | |
const char * | getRemainingData () const |
Get remaining data. More... | |
int | tellg () const |
Get read position. More... | |
void | seekg (const int pos) |
Set read position. More... | |
virtual bool | getStatus () const |
Status of reader. More... | |
virtual int | read (char *buffer, const int length) |
Read byte array. More... | |
virtual void | clear () |
Clear status of reader. More... | |
JReader & | operator>> (JSerialisable &object) |
Read serialisable data object. More... | |
JReader & | operator>> (bool &value) |
JReader & | operator>> (char &value) |
JReader & | operator>> (unsigned char &value) |
JReader & | operator>> (short &value) |
JReader & | operator>> (unsigned short &value) |
JReader & | operator>> (int &value) |
JReader & | operator>> (unsigned int &value) |
JReader & | operator>> (long int &value) |
JReader & | operator>> (long long int &value) |
JReader & | operator>> (unsigned long long int &value) |
JReader & | operator>> (float &value) |
JReader & | operator>> (double &value) |
JReader & | operator>> (long double &value) |
JReader & | load (JSerialisable &object) |
Read object. More... | |
template<class T > | |
JReader & | load (T &object) |
Read object. More... | |
operator bool () const | |
Type conversion operator. More... | |
bool | operator! () const |
Negated status of this object. More... | |
Static Public Member Functions | |
static int | sizeOf () |
Get size of object. More... | |
Public Attributes | |
JPrefix_t | prefix |
Static Public Attributes | |
static const int | FILE_CLOSED = -1 |
Protected Member Functions | |
template<class T > | |
void | setOption (const int level, const int option, const T value) |
Set socket option. More... | |
template<class T > | |
T | getOption (const int level, const int option) const |
Get socket option. More... | |
void | setStatus (const JStatus_t status) |
Set status of I/O. More... | |
Protected Attributes | |
int | fileDescriptor |
JElement_t * | __data |
int | __size |
JStatus_t | status |
int | counter |
JType | type |
const char * | __data |
int | __size |
int | __pos |
Private Attributes | |
std::vector< char > | buffer |
Socket input channel.
This class can be used to read a data packet from a socket without blocking and to buffer these data for subsequent user read operations.
The template argument corresponds to a header that precedes any data. This header acts as a protocol specifier that is used to determine the size of the data packet. To this end, the method getSizeOfPacket() should be implemented for each header type.
The reading from the socket may be non-blocking (depending on the configuration of the socket). The status of this object should be checked for completion of the data packet. The method reset() should be called before reading the next data packet.
Definition at line 86 of file JSocketChannel.hh.
|
inherited |
Enumerator | |
---|---|
IO_RESET | |
IO_READY | |
IO_BUSY |
Definition at line 26 of file JSocketStatus.hh.
|
inherited |
|
inline |
Constructor.
socket | socket |
Definition at line 102 of file JSocketChannel.hh.
|
inline |
Interruptable read method.
Definition at line 116 of file JSocketChannel.hh.
|
inline |
Reset channel.
After a reset, the socket channel is ready to receive a new data packet.
Definition at line 162 of file JSocketChannel.hh.
|
inlinevirtualinherited |
Read data from socket.
This method handles I/O errors in such a way that:
buffer | buffer |
length | number of bytes to read |
Reimplemented from JLANG::JFile.
Reimplemented in JNET::JSocketBlocking.
Definition at line 300 of file JSocket.hh.
|
inlineinherited |
Shut down socket.
Definition at line 94 of file JSocket.hh.
|
inlineinherited |
Set non-blocking of I/O.
on | true to enable non-blocking; false to disable |
Definition at line 109 of file JSocket.hh.
|
inlineinherited |
Get non-blocking of I/O.
Definition at line 133 of file JSocket.hh.
|
inlineinherited |
Set keep alive of socket.
on | true to enable keep alive; false to disable |
Definition at line 151 of file JSocket.hh.
|
inlineinherited |
Get keep alive of socket.
Definition at line 162 of file JSocket.hh.
|
inlineinherited |
Set the TCP idle time.
t_s | time [s] |
Definition at line 173 of file JSocket.hh.
|
inlineinherited |
Set the TCP idle count.
count | count |
Definition at line 184 of file JSocket.hh.
|
inlineinherited |
Set the TCP interval time.
t_s | time [s] |
Definition at line 195 of file JSocket.hh.
|
inlineinherited |
Set reuse address.
on | true to enable reuse address; false to disable |
Definition at line 206 of file JSocket.hh.
|
inlineinherited |
Get reuse address.
Definition at line 217 of file JSocket.hh.
|
inlineinherited |
Set TCP no-delay.
on | true to set TCP no-delay; false to disable |
Definition at line 228 of file JSocket.hh.
|
inlineinherited |
Get TCP no-delay.
Definition at line 239 of file JSocket.hh.
|
inlineinherited |
Set receive buffer size.
size | number of bytes |
Definition at line 250 of file JSocket.hh.
|
inlineinherited |
|
inlineinherited |
Set send buffer size.
size | number of bytes |
Definition at line 272 of file JSocket.hh.
|
inlineinherited |
|
inlinevirtualinherited |
Write data to socket.
This method handles I/O errors in such a way that:
buffer | buffer |
length | number of bytes to write |
Reimplemented from JLANG::JFile.
Reimplemented in JNET::JSocketBlocking.
Definition at line 339 of file JSocket.hh.
|
inlineinherited |
Accept connection from a server.
server | file descriptor of server socket |
Definition at line 372 of file JSocket.hh.
|
inlineinherited |
Connect to port on local host.
port | port number |
Definition at line 384 of file JSocket.hh.
|
inlineinherited |
Connect to port on specified host.
host_name | host name |
port | port number |
Definition at line 396 of file JSocket.hh.
|
inlineinherited |
Connect to port on specified host.
ip_number | IP number |
port | port number |
Definition at line 408 of file JSocket.hh.
|
inlineprotectedinherited |
Set socket option.
level | level |
option | option |
value | value |
Definition at line 428 of file JSocket.hh.
|
inlineprotectedinherited |
Get socket option.
level | level |
option | option |
Definition at line 446 of file JSocket.hh.
|
inlineinherited |
Check availability of input.
This method returns true if at least one byte can be read without blocking.
timeout | timeout |
Definition at line 100 of file JFile.hh.
|
inlineinherited |
Check availability of output.
This method returns true if at least one byte can be written without blocking.
timeout | timeout |
Definition at line 113 of file JFile.hh.
|
inlinevirtualinherited |
|
inlinevirtualinherited |
Check status.
|
inlinevirtualinherited |
|
inlinevirtualinherited |
Check end of file.
|
inlineinherited |
Less than operation.
file | JAbstractFile to be compared |
Definition at line 64 of file JAbstractFile.hh.
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
Get host name.
Definition at line 88 of file JSocketAddress.hh.
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
Set any IP number.
Definition at line 119 of file JSocketAddress.hh.
|
inlineinherited |
|
inlineinherited |
|
inlinestaticinherited |
|
inlineinherited |
Get size of pending data.
Definition at line 55 of file JSocketNonblocking.hh.
|
inlineinherited |
Initialise buffer.
buffer | buffer |
Definition at line 66 of file JSocketNonblocking.hh.
|
inlineinherited |
Initialise buffer.
buffer | I/O data |
length | number of bytes |
Definition at line 78 of file JSocketNonblocking.hh.
|
inlineinherited |
|
inlineinherited |
Check reset status.
Definition at line 54 of file JSocketStatus.hh.
|
inlineinherited |
Check busy status.
Definition at line 65 of file JSocketStatus.hh.
|
inlineinherited |
Check ready status.
Definition at line 76 of file JSocketStatus.hh.
|
inlineinherited |
Get number of I/O attempts.
Definition at line 87 of file JSocketStatus.hh.
|
inlineprotectedinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlinevirtualinherited |
Status of reader.
Implements JLANG::JAbstractObjectStatus.
Definition at line 123 of file JByteArrayIO.hh.
|
inlinevirtualinherited |
Read byte array.
buffer | pointer to byte array |
length | number of bytes |
Implements JLANG::JBinaryInput.
Definition at line 136 of file JByteArrayIO.hh.
|
inlinevirtualinherited |
Clear status of reader.
Reimplemented in JIO::JBufferedReader, and JIO::JStreamReader.
Definition at line 70 of file JSerialisable.hh.
|
inlineinherited |
Read serialisable data object.
object | serialisable data object |
Definition at line 80 of file JSerialisable.hh.
|
inlineinherited |
Definition at line 86 of file JSerialisable.hh.
|
inlineinherited |
Definition at line 87 of file JSerialisable.hh.
|
inlineinherited |
Definition at line 88 of file JSerialisable.hh.
|
inlineinherited |
Definition at line 89 of file JSerialisable.hh.
|
inlineinherited |
Definition at line 90 of file JSerialisable.hh.
|
inlineinherited |
Definition at line 91 of file JSerialisable.hh.
|
inlineinherited |
Definition at line 92 of file JSerialisable.hh.
|
inlineinherited |
Definition at line 93 of file JSerialisable.hh.
|
inlineinherited |
Definition at line 94 of file JSerialisable.hh.
|
inlineinherited |
Definition at line 95 of file JSerialisable.hh.
|
inlineinherited |
Definition at line 96 of file JSerialisable.hh.
|
inlineinherited |
Definition at line 97 of file JSerialisable.hh.
|
inlineinherited |
Definition at line 98 of file JSerialisable.hh.
|
inlineinherited |
Read object.
object | object |
Definition at line 107 of file JSerialisable.hh.
|
inlineinherited |
Read object.
object | object |
Definition at line 120 of file JSerialisable.hh.
|
inlineinherited |
Type conversion operator.
Definition at line 33 of file JAbstractObjectStatus.hh.
|
inlineinherited |
Negated status of this object.
Definition at line 44 of file JAbstractObjectStatus.hh.
JPrefix_t JNET::JSocketInputChannel< JPrefix_t >::prefix |
Definition at line 171 of file JSocketChannel.hh.
|
private |
Definition at line 174 of file JSocketChannel.hh.
|
staticinherited |
Definition at line 27 of file JAbstractFile.hh.
|
protectedinherited |
Definition at line 91 of file JAbstractFile.hh.
|
protectedinherited |
Definition at line 104 of file JSocketNonblocking.hh.
|
protectedinherited |
Definition at line 105 of file JSocketNonblocking.hh.
|
protectedinherited |
Definition at line 115 of file JSocketStatus.hh.
|
protectedinherited |
Definition at line 116 of file JSocketStatus.hh.
|
protectedinherited |
Definition at line 67 of file JSocketChannel.hh.
|
protectedinherited |
Definition at line 147 of file JByteArrayIO.hh.
|
protectedinherited |
Definition at line 148 of file JByteArrayIO.hh.
|
protectedinherited |
Definition at line 149 of file JByteArrayIO.hh.