Jpp  19.1.0
the software that should make you happy
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
JNET::JSocketInputChannel< JPrefix_t > Class Template Reference

Socket input channel. More...

#include <JSocketChannel.hh>

Inheritance diagram for JNET::JSocketInputChannel< JPrefix_t >:
JNET::JSocketNonblockingReader JNET::JSocketChannel JIO::JByteArrayReader JNET::JTCPSocket JNET::JSocketBuffer< JElement_t > JIO::JReader JNET::JSocket JNET::JSocketStatus JLANG::JBinaryInput JLANG::JAbstractObjectStatus JLANG::JFile JNET::JSocketAddress JLANG::JAbstractFile JLANG::JBinaryInput JLANG::JBinaryOutput JLANG::JComparable< JAbstractFile >

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 (JTCPSocket &socket)
 Constructor. More...
 
JStatus_t read ()
 Interruptable read method. More...
 
void reset ()
 Reset channel. More...
 
virtual int read (char *buffer, const int length) override
 Read byte array. More...
 
virtual int read (char *buffer, const int length) override
 Read data from 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 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 setTcpNoDelay (const bool on)
 Set TCP no-delay. More...
 
bool getTcpNoDelay () const
 Get TCP no-delay. 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 JHostname &hostname)
 Connect to port on specified host. More...
 
void connect (const std::string &hostname, 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...
 
int shutdown ()
 Shut down socket. More...
 
void setKeepAlive (const bool on)
 Set keep alive of socket. More...
 
bool getKeepAlive () const
 Get keep alive of socket. More...
 
void setReuseAddress (const bool on)
 Set reuse address. More...
 
bool getReuseAddress () const
 Get reuse address. 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) override
 Write data to socket. More...
 
int 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...
 
void setFileDescriptor (const int file)
 Set 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 override
 Status of reader. More...
 
virtual int read (char *buffer, const int length) override
 Read byte array. More...
 
virtual void clear ()
 Clear status of reader. More...
 
JReaderoperator>> (JSerialisable &object)
 Read serialisable data object. More...
 
JReaderoperator>> (bool &value)
 
JReaderoperator>> (char &value)
 
JReaderoperator>> (unsigned char &value)
 
JReaderoperator>> (short &value)
 
JReaderoperator>> (unsigned short &value)
 
JReaderoperator>> (int &value)
 
JReaderoperator>> (unsigned int &value)
 
JReaderoperator>> (long int &value)
 
JReaderoperator>> (unsigned long int &value)
 
JReaderoperator>> (long long int &value)
 
JReaderoperator>> (unsigned long long int &value)
 
JReaderoperator>> (float &value)
 
JReaderoperator>> (double &value)
 
JReaderoperator>> (long double &value)
 
JReaderoperator>> (JLANG::JObjectID &value)
 
JReaderload (JSerialisable &object)
 Read object. More...
 
template<class T >
JReaderload (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 const int getDefaultBufferSize ()
 Default socket buffer size to be used on this system. More...
 
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 >
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
 
int result
 

Detailed Description

template<class JPrefix_t>
class JNET::JSocketInputChannel< JPrefix_t >

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.

Member Enumeration Documentation

◆ JStatus_t

Enumerator
IO_RESET 
IO_READY 
IO_BUSY 

Definition at line 26 of file JSocketStatus.hh.

◆ JType

Enumerator
IO_PREFIX 
IO_DATA 

Definition at line 54 of file JSocketChannel.hh.

Constructor & Destructor Documentation

◆ JSocketInputChannel()

template<class JPrefix_t >
JNET::JSocketInputChannel< JPrefix_t >::JSocketInputChannel ( JTCPSocket socket)
inline

Constructor.

Parameters
socketsocket

Definition at line 102 of file JSocketChannel.hh.

102  :
103  JSocketNonblockingReader(socket),
104  JSocketChannel(),
106  {
107  reset();
108  }
JByteArrayReader()
Default constructor.
Definition: JByteArrayIO.hh:32
Auxiliary class for socket channel.
void reset()
Reset channel.
JSocketNonblockingReader(const JTCPSocket &socket)
Constructor.

Member Function Documentation

◆ read() [1/4]

template<class JPrefix_t >
JStatus_t JNET::JSocketInputChannel< JPrefix_t >::read ( )
inline

Interruptable read method.

Returns
status

Definition at line 116 of file JSocketChannel.hh.

117  {
118  if (type == IO_PREFIX) {
119 
120  if (isReset()) {
121  set((char*) &prefix, sizeof(JPrefix_t));
122  }
123 
124  if (isBusy()) {
126  }
127 
128  if (isReady()) {
129 
130  buffer.clear();
131 
132  buffer.resize(getSizeOfPacket(prefix));
133 
134  memcpy(buffer.data(), &prefix, sizeof(JPrefix_t));
135 
136  set(buffer.data() + sizeof(JPrefix_t),
137  buffer.size() - sizeof(JPrefix_t));
138 
139  type = IO_DATA;
140  }
141  }
142 
143  if (type == IO_DATA) {
144 
145  if (isBusy()) {
147  }
148 
149  if (isReady()) {
150  static_cast<JByteArrayReader&>(*this) = JByteArrayReader(buffer.data(), buffer.size());
151  }
152  }
153 
154  return JSocketStatus::getStatus();
155  }
Byte array binary input.
Definition: JByteArrayIO.hh:27
ControlHost prefix.
Definition: JPrefix.hh:33
void set(const JSocketBuffer< JElement_t > &buffer)
Initialise buffer.
std::vector< char > buffer
JStatus_t read()
Continuation of non-blocking read method.
JStatus_t getStatus() const
Get status of I/O.
bool isReady() const
Check ready status.
bool isBusy() const
Check busy status.
bool isReset() const
Check reset status.
int getSizeOfPacket(const KM3NETDAQ::JDAQAbstractPreamble &preamble)
Get size of packeet.
Definition: JDataFilter.cc:82

◆ reset()

template<class JPrefix_t >
void JNET::JSocketInputChannel< JPrefix_t >::reset ( )
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.

163  {
166 
167  buffer.clear();
168  }
void reset()
Reset channel.

◆ read() [2/4]

template<class JPrefix_t >
virtual int JIO::JByteArrayReader::read
inlineoverride

Read byte array.

Parameters
bufferpointer to byte array
lengthnumber of bytes
Returns
number of bytes

Definition at line 136 of file JByteArrayIO.hh.

137  {
138  memcpy(buffer, __data + __pos, length);
139 
140  __pos += length;
141 
142  return length;
143  }

◆ read() [3/4]

virtual int JNET::JSocket::read ( char *  buffer,
const int  length 
)
inlineoverridevirtualinherited

Read data from socket.

This method handles I/O errors in such a way that:

  1. the return value is set to zero if no data are read;
  2. an exception is thrown in case of a fatal error;
Parameters
bufferbuffer
lengthnumber of bytes to read
Returns
number of bytes actually read

Reimplemented from JLANG::JFile.

Reimplemented in JNET::JUDPSocket, and JNET::JSocketBlocking.

Definition at line 198 of file JSocket.hh.

199  {
200  int pos = JFile::read(buffer, length);
201 
202  if (pos == 0) {
203 
204  THROW(JSocketException, "Socket read failed " << getFileDescriptor() << ' ' << errno);
205 
206  } else if (pos < 0) {
207 
208  switch (errno) {
209 
210  case EINTR:
211  case EWOULDBLOCK:
212  //case EAGAIN:
213  break;
214 
215  default:
216  THROW(JSocketException, "Socket read error " << getFileDescriptor() << ' ' << errno);
217  }
218 
219  pos = 0;
220  }
221 
222  return pos;
223  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
int getFileDescriptor() const
Get file descriptor.
virtual int read(char *buffer, const int length)
Read data from file.
Definition: JFile.hh:80
Exception for socket.
Definition: JException.hh:468

◆ setNonBlocking()

void JNET::JTCPSocket::setNonBlocking ( const bool  on)
inlineinherited

Set non-blocking of I/O.

Parameters
ontrue to enable non-blocking; false to disable

Definition at line 56 of file JTCPSocket.hh.

57  {
58  const int flags = fcntl(getFileDescriptor(), F_GETFL, -1);
59  const int mask = FNDELAY;
60 
61  if (flags == -1) {
62  THROW(JSocketException, "Get socket option failed " << errno);
63  }
64 
65  if (((flags & mask) != mask && on) ||
66  ((flags & mask) != 0 && !on) ) {
67 
68  if (fcntl(getFileDescriptor(), F_SETFL, flags ^ mask) < 0) {
69  THROW(JSocketException, "Set socket option failed " << errno);
70  }
71  }
72  }

◆ getNonBlocking()

bool JNET::JTCPSocket::getNonBlocking ( ) const
inlineinherited

Get non-blocking of I/O.

Returns
true if enabled non-blocking; else false

Definition at line 80 of file JTCPSocket.hh.

81  {
82  const int flags = fcntl(getFileDescriptor(), F_GETFL, -1);
83  const int mask = FNDELAY;
84 
85  if (flags == -1) {
86  THROW(JSocketException, "Get socket option failed " << errno);
87  }
88 
89  return ((flags & mask) != 0);
90  }

◆ setKeepIdle()

void JNET::JTCPSocket::setKeepIdle ( const int  t_s)
inlineinherited

Set the TCP idle time.

Parameters
t_stime [s]

Definition at line 98 of file JTCPSocket.hh.

99  {
100  setOption(IPROTO_TCP, TCP_KEEPIDLE, t_s);
101  }
#define IPROTO_TCP
Definition: JTCPSocket.hh:11
void setOption(const int level, const int option, const T value)
Set socket option.
Definition: JSocket.hh:274

◆ setKeepCnt()

void JNET::JTCPSocket::setKeepCnt ( const int  count)
inlineinherited

Set the TCP idle count.

Parameters
countcount

Definition at line 109 of file JTCPSocket.hh.

110  {
111  setOption(IPROTO_TCP, TCP_KEEPCNT, count);
112  }

◆ setKeepIntvl()

void JNET::JTCPSocket::setKeepIntvl ( const int  t_s)
inlineinherited

Set the TCP interval time.

Parameters
t_stime [s]

Definition at line 120 of file JTCPSocket.hh.

121  {
122  setOption(IPROTO_TCP, TCP_KEEPINTVL, t_s);
123  }

◆ setTcpNoDelay()

void JNET::JTCPSocket::setTcpNoDelay ( const bool  on)
inlineinherited

Set TCP no-delay.

Parameters
ontrue to set TCP no-delay; false to disable

Definition at line 131 of file JTCPSocket.hh.

132  {
133  setOption(IPPROTO_TCP, TCP_NODELAY, int(on ? 1 : 0));
134  }

◆ getTcpNoDelay()

bool JNET::JTCPSocket::getTcpNoDelay ( ) const
inlineinherited

Get TCP no-delay.

Returns
true if TCP no-delay; else false

Definition at line 142 of file JTCPSocket.hh.

143  {
144  return (getOption<int>(IPPROTO_TCP, TCP_NODELAY) == 1);
145  }

◆ accept()

void JNET::JTCPSocket::accept ( const int  server)
inlineinherited

Accept connection from a server.

Parameters
serverfile descriptor of TCP server socket

Definition at line 153 of file JTCPSocket.hh.

154  {
155  socklen_t size = sizeof(sockaddr_in);
156 
157  fileDescriptor = ::accept(server, getSockaddr(), &size);
158  }
const sockaddr * getSockaddr() const
Get sockaddr.
void accept(const int server)
Accept connection from a server.
Definition: JTCPSocket.hh:153

◆ connect() [1/4]

void JNET::JTCPSocket::connect ( const int  port)
inlineinherited

Connect to port on local host.

Parameters
portport number

Definition at line 166 of file JTCPSocket.hh.

167  {
168  connect(INADDR_ANY, port);
169  }
void connect(const int port)
Connect to port on local host.
Definition: JTCPSocket.hh:166

◆ connect() [2/4]

void JNET::JTCPSocket::connect ( const JHostname hostname)
inlineinherited

Connect to port on specified host.

Parameters
hostnamehost name

Definition at line 177 of file JTCPSocket.hh.

178  {
179  connect(hostname.hostname, hostname.port);
180  }
std::string hostname
Definition: JHostname.hh:171

◆ connect() [3/4]

void JNET::JTCPSocket::connect ( const std::string &  hostname,
const int  port 
)
inlineinherited

Connect to port on specified host.

Parameters
hostnamehost name
portport number

Definition at line 189 of file JTCPSocket.hh.

190  {
191  connect(JSYSTEM::getIPnumber(hostname), port);
192  }
int getIPnumber(const std::string &host_name)
Get IP number.
Definition: JNetwork.hh:117

◆ connect() [4/4]

void JNET::JTCPSocket::connect ( const int  ip_number,
const int  port 
)
inlineinherited

Connect to port on specified host.

Parameters
ip_numberIP number
portport number

Definition at line 201 of file JTCPSocket.hh.

202  {
203  setIPnumber(ip_number);
204  setPort(port);
205 
206  if (::connect(getFileDescriptor(), getSockaddr(), sizeof(sockaddr_in)) < 0) {
207  THROW(JSocketException, "Socket connection failed " << JSYSTEM::getIPaddress(ip_number) << ":" << port << " / " << getFileDescriptor() << " " << errno);
208  }
209  }
void setIPnumber()
Set any IP number.
void setPort(const int port)
Set port number.
std::string getIPaddress(const int ip)
Get IP address (decimal-dot notation).
Definition: JNetwork.hh:154

◆ getDefaultBufferSize()

static const int JNET::JSocket::getDefaultBufferSize ( )
inlinestaticinherited

Default socket buffer size to be used on this system.

Returns
number of bytes

Definition at line 75 of file JSocket.hh.

76  {
77 #if __APPLE__
78  return JMATH::MEGABYTE;
79 #else
80  return JMATH::GIGABYTE;
81 #endif
82  }
static const long long int GIGABYTE
Number of bytes in a mega-byte.
static const long long int MEGABYTE
Number of bytes in a kilo-byte.

◆ shutdown()

int JNET::JSocket::shutdown ( )
inlineinherited

Shut down socket.

Returns
return value

Definition at line 89 of file JSocket.hh.

90  {
91  const int value = ::shutdown(getFileDescriptor(), SHUT_RDWR);
92 
93  close();
94 
95  return value;
96  }
int close()
Close file.
Definition: JFile.hh:57
int shutdown()
Shut down socket.
Definition: JSocket.hh:89

◆ setKeepAlive()

void JNET::JSocket::setKeepAlive ( const bool  on)
inlineinherited

Set keep alive of socket.

Parameters
ontrue to enable keep alive; false to disable

Definition at line 104 of file JSocket.hh.

105  {
106  setOption(SOL_SOCKET, SO_KEEPALIVE, int(on ? 1 : 0));
107  }

◆ getKeepAlive()

bool JNET::JSocket::getKeepAlive ( ) const
inlineinherited

Get keep alive of socket.

Returns
true if keep alive; else false

Definition at line 115 of file JSocket.hh.

116  {
117  return (getOption<int>(SOL_SOCKET, SO_KEEPALIVE) == 1);
118  }

◆ setReuseAddress()

void JNET::JSocket::setReuseAddress ( const bool  on)
inlineinherited

Set reuse address.

Parameters
ontrue to enable reuse address; false to disable

Definition at line 126 of file JSocket.hh.

127  {
128  setOption(SOL_SOCKET, SO_REUSEADDR, int(on ? 1 : 0));
129  }

◆ getReuseAddress()

bool JNET::JSocket::getReuseAddress ( ) const
inlineinherited

Get reuse address.

Returns
true if enable reuse address; else false

Definition at line 137 of file JSocket.hh.

138  {
139  return (getOption<int>(SOL_SOCKET, SO_REUSEADDR) == 1);
140  }

◆ setReceiveBufferSize()

void JNET::JSocket::setReceiveBufferSize ( const int  size)
inlineinherited

Set receive buffer size.

Parameters
sizenumber of bytes

Definition at line 148 of file JSocket.hh.

149  {
150  setOption(SOL_SOCKET, SO_RCVBUF, int(size));
151  }

◆ getReceiveBufferSize()

int JNET::JSocket::getReceiveBufferSize ( ) const
inlineinherited

Set receive buffer size.

Returns
number of bytes

Definition at line 159 of file JSocket.hh.

160  {
161  return getOption<int>(SOL_SOCKET, SO_RCVBUF);
162  }

◆ setSendBufferSize()

void JNET::JSocket::setSendBufferSize ( const int  size)
inlineinherited

Set send buffer size.

Parameters
sizenumber of bytes

Definition at line 170 of file JSocket.hh.

171  {
172  setOption(SOL_SOCKET, SO_SNDBUF, int(size));
173  }

◆ getSendBufferSize()

int JNET::JSocket::getSendBufferSize ( ) const
inlineinherited

Get send buffer size.

Returns
number of bytes

Definition at line 181 of file JSocket.hh.

182  {
183  return getOption<int>(SOL_SOCKET, SO_SNDBUF);
184  }

◆ write()

virtual int JNET::JSocket::write ( const char *  buffer,
const int  length 
)
inlineoverridevirtualinherited

Write data to socket.

This method handles I/O errors in such a way that:

  1. the return value is set to zero if no data are written;
  2. an exception is thrown in case of a fatal error;
Parameters
bufferbuffer
lengthnumber of bytes to write
Returns
number of bytes actually written

Reimplemented from JLANG::JFile.

Reimplemented in JNET::JUDPSocket, and JNET::JSocketBlocking.

Definition at line 237 of file JSocket.hh.

238  {
239  int pos = JFile::write(buffer, length);
240 
241  if (pos == 0) {
242 
243  THROW(JSocketException, "Socket write failed " << getFileDescriptor() << ' ' << errno);
244 
245  } else if (pos < 0) {
246 
247  switch (errno) {
248 
249  case EINTR:
250  case EWOULDBLOCK:
251  //case EAGAIN:
252  break;
253 
254  default:
255  THROW(JSocketException, "Socket write error " << getFileDescriptor() << ' ' << errno);
256  }
257 
258  pos = 0;
259  }
260 
261  return pos;
262  }
virtual int write(const char *buffer, const int length)
Write data to file.
Definition: JFile.hh:93

◆ setOption()

template<class T >
void JNET::JSocket::setOption ( const int  level,
const int  option,
const T  value 
)
inlineprotectedinherited

Set socket option.

Parameters
levellevel
optionoption
valuevalue

Definition at line 274 of file JSocket.hh.

275  {
276  socklen_t size = sizeof(T);
277 
278  if (setsockopt(getFileDescriptor(), level, option, &value, size) < 0) {
279  THROW(JSocketException, "Set socket option failed " << errno);
280  }
281  }

◆ getOption()

template<class T >
T JNET::JSocket::getOption ( const int  level,
const int  option 
) const
inlineprotectedinherited

Get socket option.

Parameters
levellevel
optionoption
Returns
value

Definition at line 292 of file JSocket.hh.

293  {
294  T value;
295  socklen_t size = sizeof(T);
296 
297  if (getsockopt(getFileDescriptor(), level, option, &value, &size) < 0) {
298  THROW(JSocketException, "Get socket option failed " << errno);
299  }
300 
301  return value;
302  }

◆ close()

int JLANG::JFile::close ( )
inlineinherited

Close file.

Returns
return value

Definition at line 57 of file JFile.hh.

58  {
59  int value = -1;
60 
61  if (fileDescriptor != FILE_CLOSED) {
62 
63  value = ::close(fileDescriptor);
64 
66  result = 0;
67  }
68 
69  return value;
70  }
static const int FILE_CLOSED
int result
Definition: JFile.hh:170

◆ in_avail()

bool JLANG::JFile::in_avail ( JTimeval  timeout = JTimeval::min()) const
inlineinherited

Check availability of input.

This method returns true if at least one byte can be read without blocking.

Parameters
timeouttimeout
Returns
true if ready to read; else false

Definition at line 106 of file JFile.hh.

107  {
108  return JFileDescriptorMask(*this).in_avail(timeout);
109  }
Auxiliary class for method select.
bool in_avail(JTimeval timeout=JTimeval::min())
Check availability of input.

◆ out_avail()

bool JLANG::JFile::out_avail ( JTimeval  timeout = JTimeval::min()) const
inlineinherited

Check availability of output.

This method returns true if at least one byte can be written without blocking.

Parameters
timeouttimeout
Returns
true if ready to write; else false

Definition at line 119 of file JFile.hh.

120  {
121  return JFileDescriptorMask(*this).out_avail(timeout);
122  }
bool out_avail(JTimeval timeout=JTimeval::min())
Check availability of output.

◆ good()

virtual bool JLANG::JFile::good ( ) const
inlinevirtualinherited

Check status.

Returns
true if last I/O operation successful; else false

Definition at line 130 of file JFile.hh.

131  {
132  return is_open() && !eof() && !bad();
133  }
bool is_open() const
Get open status.
virtual bool bad() const
Check status.
Definition: JFile.hh:152
virtual bool eof() const
Check end of file.
Definition: JFile.hh:163

◆ fail()

virtual bool JLANG::JFile::fail ( ) const
inlinevirtualinherited

Check status.

Returns
true if last I/O operation caused logical error; else false

Definition at line 141 of file JFile.hh.

142  {
143  return result == 0;
144  }

◆ bad()

virtual bool JLANG::JFile::bad ( ) const
inlinevirtualinherited

Check status.

Returns
true if last I/O operation caused read/write error; else false

Definition at line 152 of file JFile.hh.

153  {
154  return fail();
155  }
virtual bool fail() const
Check status.
Definition: JFile.hh:141

◆ eof()

virtual bool JLANG::JFile::eof ( ) const
inlinevirtualinherited

Check end of file.

Returns
true if end of file; else false

Definition at line 163 of file JFile.hh.

164  {
165  return result == EOF;
166  }

◆ less()

bool JLANG::JAbstractFile::less ( const JAbstractFile file) const
inlineinherited

Less than operation.

Parameters
fileJAbstractFile to be compared
Returns
true if this file descriptor is less; else false

Definition at line 64 of file JAbstractFile.hh.

65  {
66  return getFileDescriptor() < file.getFileDescriptor();
67  }

◆ getFileDescriptor()

int JLANG::JAbstractFile::getFileDescriptor ( ) const
inlineinherited

Get file descriptor.

Returns
file descriptor

Definition at line 75 of file JAbstractFile.hh.

76  {
77  return fileDescriptor;
78  }

◆ setFileDescriptor()

void JLANG::JAbstractFile::setFileDescriptor ( const int  file)
inlineinherited

Set file descriptor.

Parameters
filefile descriptor

Definition at line 86 of file JAbstractFile.hh.

87  {
88  fileDescriptor = file;
89  }

◆ is_open()

bool JLANG::JAbstractFile::is_open ( ) const
inlineinherited

Get open status.

Definition at line 95 of file JAbstractFile.hh.

96  {
97  return fileDescriptor != FILE_CLOSED;
98  }

◆ getSockaddr() [1/2]

const sockaddr* JNET::JSocketAddress::getSockaddr ( ) const
inlineinherited

Get sockaddr.

Returns
pointer to sockaddr structure

Definition at line 44 of file JSocketAddress.hh.

45  {
46  return (const sockaddr*) static_cast<const sockaddr_in*>(this);
47  }

◆ getSockaddr() [2/2]

sockaddr* JNET::JSocketAddress::getSockaddr ( )
inlineinherited

Get sockaddr.

Returns
pointer to sockaddr structure

Definition at line 55 of file JSocketAddress.hh.

56  {
57  return (sockaddr*) static_cast<sockaddr_in*>(this);
58  }

◆ getFamily()

int JNET::JSocketAddress::getFamily ( ) const
inlineinherited

Get family.

Returns
family

Definition at line 66 of file JSocketAddress.hh.

67  {
68  return sin_family;
69  }

◆ setFamily()

void JNET::JSocketAddress::setFamily ( const int  family)
inlineinherited

Set family.

Parameters
familyfamily

Definition at line 77 of file JSocketAddress.hh.

78  {
79  sin_family = family;
80  }

◆ getHostname()

std::string JNET::JSocketAddress::getHostname ( ) const
inlineinherited

Get host name.

Returns
host name

Definition at line 88 of file JSocketAddress.hh.

89  {
90  return JSYSTEM::getHostname(this->getIPnumber());
91  }
int getIPnumber() const
Get IP number.
std::string getHostname()
Get host name.
Definition: JNetwork.hh:77

◆ getIPnumber()

int JNET::JSocketAddress::getIPnumber ( ) const
inlineinherited

Get IP number.

Returns
IP number

Definition at line 99 of file JSocketAddress.hh.

100  {
101  return sin_addr.s_addr;
102  }

◆ setIPnumber() [1/2]

void JNET::JSocketAddress::setIPnumber ( const int  ip_number)
inlineinherited

Set IP number.

Parameters
ip_numberIP number

Definition at line 110 of file JSocketAddress.hh.

111  {
112  sin_addr.s_addr = ip_number;
113  }

◆ setIPnumber() [2/2]

void JNET::JSocketAddress::setIPnumber ( )
inlineinherited

Set any IP number.

Definition at line 119 of file JSocketAddress.hh.

120  {
121  sin_addr.s_addr = htonl(INADDR_ANY);
122  }

◆ getPort()

int JNET::JSocketAddress::getPort ( ) const
inlineinherited

Get port number.

Returns
port number

Definition at line 130 of file JSocketAddress.hh.

131  {
132  return ntohs(this->sin_port);
133  }

◆ setPort()

void JNET::JSocketAddress::setPort ( const int  port)
inlineinherited

Set port number.

Parameters
portport number

Definition at line 141 of file JSocketAddress.hh.

142  {
143  if (port >= 0 && port <= std::numeric_limits<u_short>::max())
144  sin_port = htons((u_short) port);
145  else
146  THROW(JCastException, "JSocketAddress::setPort() illegal value.");
147  }
Exception for cast operation.
Definition: JException.hh:252

◆ sizeOf()

static int JNET::JSocketAddress::sizeOf ( )
inlinestaticinherited

Get size of object.

Returns
number of bytes

Definition at line 155 of file JSocketAddress.hh.

156  {
157  return sizeof(sockaddr_in);
158  }

◆ getSize()

template<class JElement_t >
int JNET::JSocketBuffer< JElement_t >::getSize ( ) const
inlineinherited

Get size of pending data.

Returns
number of bytes

Definition at line 55 of file JSocketNonblocking.hh.

56  {
57  return __size;
58  }

◆ set() [1/2]

template<class JElement_t >
void JNET::JSocketBuffer< JElement_t >::set ( const JSocketBuffer< JElement_t > &  buffer)
inlineinherited

Initialise buffer.

Parameters
bufferbuffer

Definition at line 66 of file JSocketNonblocking.hh.

67  {
68  set(buffer.__data, buffer.__size);
69  }

◆ set() [2/2]

template<class JElement_t >
void JNET::JSocketBuffer< JElement_t >::set ( JElement_t *  buffer,
const int  length 
)
inlineinherited

Initialise buffer.

Parameters
bufferI/O data
lengthnumber of bytes

Definition at line 78 of file JSocketNonblocking.hh.

79  {
80  if (status == IO_BUSY) {
81  THROW(JSocketException, "Set socket buffer I/O while busy.");
82  }
83 
84  status = (length != 0 ? IO_BUSY : IO_READY);
85  counter = 0;
86  __data = buffer;
87  __size = length;
88  }

◆ getStatus() [1/2]

JStatus_t JNET::JSocketStatus::getStatus ( ) const
inlineinherited

Get status of I/O.

Returns
status

Definition at line 43 of file JSocketStatus.hh.

44  {
45  return status;
46  }

◆ isReset()

bool JNET::JSocketStatus::isReset ( ) const
inlineinherited

Check reset status.

Returns
true if reset; else false

Definition at line 54 of file JSocketStatus.hh.

55  {
56  return status == IO_RESET;
57  }

◆ isBusy()

bool JNET::JSocketStatus::isBusy ( ) const
inlineinherited

Check busy status.

Returns
true if busy; else false

Definition at line 65 of file JSocketStatus.hh.

66  {
67  return status == IO_BUSY;
68  }

◆ isReady()

bool JNET::JSocketStatus::isReady ( ) const
inlineinherited

Check ready status.

Returns
true if ready; else false

Definition at line 76 of file JSocketStatus.hh.

77  {
78  return status == IO_READY;
79  }

◆ getCounter()

int JNET::JSocketStatus::getCounter ( ) const
inlineinherited

Get number of I/O attempts.

Returns
number of I/O attempts

Definition at line 87 of file JSocketStatus.hh.

88  {
89  return counter;
90  }

◆ setStatus()

void JNET::JSocketStatus::setStatus ( const JStatus_t  status)
inlineprotectedinherited

Set status of I/O.

Parameters
statusstatus

Definition at line 109 of file JSocketStatus.hh.

110  {
111  this->status = status;
112  }

◆ size()

int JIO::JByteArrayReader::size ( ) const
inlineinherited

Get size.

Returns
number of bytes

Definition at line 57 of file JByteArrayIO.hh.

58  {
59  return __size;
60  }

◆ data()

const char* JIO::JByteArrayReader::data ( ) const
inlineinherited

Get data.

Returns
pointer to data

Definition at line 68 of file JByteArrayIO.hh.

69  {
70  return __data;
71  }

◆ getRemainingSize()

int JIO::JByteArrayReader::getRemainingSize ( ) const
inlineinherited

Get remaining size.

Returns
number of bytes

Definition at line 79 of file JByteArrayIO.hh.

80  {
81  return __size - __pos;
82  }

◆ getRemainingData()

const char* JIO::JByteArrayReader::getRemainingData ( ) const
inlineinherited

Get remaining data.

Returns
pointer to remaining data

Definition at line 90 of file JByteArrayIO.hh.

91  {
92  return __data + __pos;
93  }

◆ tellg()

int JIO::JByteArrayReader::tellg ( ) const
inlineinherited

Get read position.

Returns
read position

Definition at line 101 of file JByteArrayIO.hh.

102  {
103  return __pos;
104  }

◆ seekg()

void JIO::JByteArrayReader::seekg ( const int  pos)
inlineinherited

Set read position.

Parameters
posread position

Definition at line 112 of file JByteArrayIO.hh.

113  {
114  __pos = pos;
115  }

◆ getStatus() [2/2]

virtual bool JIO::JByteArrayReader::getStatus ( ) const
inlineoverridevirtualinherited

Status of reader.

Returns
status of this reader

Implements JLANG::JAbstractObjectStatus.

Definition at line 123 of file JByteArrayIO.hh.

124  {
125  return __size - __pos >= 0;
126  }

◆ read() [4/4]

virtual int JIO::JByteArrayReader::read ( char *  buffer,
const int  length 
)
inlineoverridevirtualinherited

Read byte array.

Parameters
bufferpointer to byte array
lengthnumber of bytes
Returns
number of bytes

Implements JLANG::JBinaryInput.

Definition at line 136 of file JByteArrayIO.hh.

137  {
138  memcpy(buffer, __data + __pos, length);
139 
140  __pos += length;
141 
142  return length;
143  }

◆ clear()

virtual void JIO::JReader::clear ( )
inlinevirtualinherited

Clear status of reader.

Reimplemented in JIO::JStreamReader, JIO::JFileStreamReader, and JIO::JBufferedReader.

Definition at line 71 of file JSerialisable.hh.

72  {}

◆ operator>>() [1/16]

JReader& JIO::JReader::operator>> ( JSerialisable object)
inlineinherited

Read serialisable data object.

Parameters
objectserialisable data object
Returns
JReader

Definition at line 81 of file JSerialisable.hh.

82  {
83  return object.read(*this);
84  }

◆ operator>>() [2/16]

JReader& JIO::JReader::operator>> ( bool &  value)
inlineinherited

Definition at line 87 of file JSerialisable.hh.

87 { read((char*) &value, sizeof(bool)); return *this; }
virtual int read(char *buffer, const int length)=0
Read byte array.

◆ operator>>() [3/16]

JReader& JIO::JReader::operator>> ( char &  value)
inlineinherited

Definition at line 88 of file JSerialisable.hh.

88 { read((char*) &value, sizeof(char)); return *this; }

◆ operator>>() [4/16]

JReader& JIO::JReader::operator>> ( unsigned char &  value)
inlineinherited

Definition at line 89 of file JSerialisable.hh.

89 { read((char*) &value, sizeof(unsigned char)); return *this; }

◆ operator>>() [5/16]

JReader& JIO::JReader::operator>> ( short &  value)
inlineinherited

Definition at line 90 of file JSerialisable.hh.

90 { read((char*) &value, sizeof(short)); return *this; }

◆ operator>>() [6/16]

JReader& JIO::JReader::operator>> ( unsigned short &  value)
inlineinherited

Definition at line 91 of file JSerialisable.hh.

91 { read((char*) &value, sizeof(unsigned short)); return *this; }

◆ operator>>() [7/16]

JReader& JIO::JReader::operator>> ( int &  value)
inlineinherited

Definition at line 92 of file JSerialisable.hh.

92 { read((char*) &value, sizeof(int)); return *this; }

◆ operator>>() [8/16]

JReader& JIO::JReader::operator>> ( unsigned int &  value)
inlineinherited

Definition at line 93 of file JSerialisable.hh.

93 { read((char*) &value, sizeof(unsigned int)); return *this; }

◆ operator>>() [9/16]

JReader& JIO::JReader::operator>> ( long int &  value)
inlineinherited

Definition at line 94 of file JSerialisable.hh.

94 { read((char*) &value, sizeof(long int)); return *this; }

◆ operator>>() [10/16]

JReader& JIO::JReader::operator>> ( unsigned long int &  value)
inlineinherited

Definition at line 95 of file JSerialisable.hh.

95 { read((char*) &value, sizeof(unsigned long int)); return *this; }

◆ operator>>() [11/16]

JReader& JIO::JReader::operator>> ( long long int &  value)
inlineinherited

Definition at line 96 of file JSerialisable.hh.

96 { read((char*) &value, sizeof(long long int)); return *this; }

◆ operator>>() [12/16]

JReader& JIO::JReader::operator>> ( unsigned long long int &  value)
inlineinherited

Definition at line 97 of file JSerialisable.hh.

97 { read((char*) &value, sizeof(unsigned long long int)); return *this; }

◆ operator>>() [13/16]

JReader& JIO::JReader::operator>> ( float &  value)
inlineinherited

Definition at line 98 of file JSerialisable.hh.

98 { read((char*) &value, sizeof(float)); return *this; }

◆ operator>>() [14/16]

JReader& JIO::JReader::operator>> ( double &  value)
inlineinherited

Definition at line 99 of file JSerialisable.hh.

99 { read((char*) &value, sizeof(double)); return *this; }

◆ operator>>() [15/16]

JReader& JIO::JReader::operator>> ( long double &  value)
inlineinherited

Definition at line 100 of file JSerialisable.hh.

100 { read((char*) &value, sizeof(long double)); return *this; }

◆ operator>>() [16/16]

JReader& JIO::JReader::operator>> ( JLANG::JObjectID value)
inlineinherited

Definition at line 101 of file JSerialisable.hh.

101 { return (*this) >> value.getID(); }
int getID() const
Get identifier.
Definition: JObjectID.hh:50

◆ load() [1/2]

JReader& JIO::JReader::load ( JSerialisable object)
inlineinherited

Read object.

Parameters
objectobject
Returns
this reader

Definition at line 110 of file JSerialisable.hh.

111  {
112  return object.read(*this);
113  }

◆ load() [2/2]

template<class T >
JReader& JIO::JReader::load ( T &  object)
inlineinherited

Read object.

Parameters
objectobject
Returns
this reader

Definition at line 123 of file JSerialisable.hh.

124  {
125  return *this >> object;
126  }

◆ operator bool()

JLANG::JAbstractObjectStatus::operator bool ( ) const
inlineinherited

Type conversion operator.

Returns
status of this object

Definition at line 33 of file JAbstractObjectStatus.hh.

34  {
35  return this->getStatus();
36  }
virtual bool getStatus() const =0
Get status of object.

◆ operator!()

bool JLANG::JAbstractObjectStatus::operator! ( ) const
inlineinherited

Negated status of this object.

Returns
negated status of this object

Definition at line 44 of file JAbstractObjectStatus.hh.

45  {
46  return !(this->getStatus());
47  }

Member Data Documentation

◆ prefix

template<class JPrefix_t >
JPrefix_t JNET::JSocketInputChannel< JPrefix_t >::prefix

Definition at line 171 of file JSocketChannel.hh.

◆ buffer

template<class JPrefix_t >
std::vector<char> JNET::JSocketInputChannel< JPrefix_t >::buffer
private

Definition at line 174 of file JSocketChannel.hh.

◆ result

int JLANG::JFile::result
privateinherited

Definition at line 170 of file JFile.hh.

◆ FILE_CLOSED

const int JLANG::JAbstractFile::FILE_CLOSED = -1
staticinherited

Definition at line 27 of file JAbstractFile.hh.

◆ fileDescriptor

int JLANG::JAbstractFile::fileDescriptor
protectedinherited

Definition at line 102 of file JAbstractFile.hh.

◆ __data [1/2]

template<class JElement_t >
JElement_t* JNET::JSocketBuffer< JElement_t >::__data
protectedinherited

Definition at line 104 of file JSocketNonblocking.hh.

◆ __size [1/2]

template<class JElement_t >
int JNET::JSocketBuffer< JElement_t >::__size
protectedinherited

Definition at line 105 of file JSocketNonblocking.hh.

◆ status

JStatus_t JNET::JSocketStatus::status
protectedinherited

Definition at line 115 of file JSocketStatus.hh.

◆ counter

int JNET::JSocketStatus::counter
protectedinherited

Definition at line 116 of file JSocketStatus.hh.

◆ type

JType JNET::JSocketChannel::type
protectedinherited

Definition at line 67 of file JSocketChannel.hh.

◆ __data [2/2]

const char* JIO::JByteArrayReader::__data
protectedinherited

Definition at line 147 of file JByteArrayIO.hh.

◆ __size [2/2]

int JIO::JByteArrayReader::__size
protectedinherited

Definition at line 148 of file JByteArrayIO.hh.

◆ __pos

int JIO::JByteArrayReader::__pos
protectedinherited

Definition at line 149 of file JByteArrayIO.hh.


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