Jpp  18.3.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
JNET::JSocketOutputChannel< JPrefix_t > Class Template Reference

Socket output channel. More...

#include <JSocketChannel.hh>

Inheritance diagram for JNET::JSocketOutputChannel< JPrefix_t >:
JNET::JSocketNonblockingWriter JNET::JSocketChannel JIO::JByteArrayWriter JNET::JTCPSocket JNET::JSocketBuffer< JElement_t > JIO::JWriter std::vector< char > JNET::JSocket JNET::JSocketStatus JLANG::JBinaryOutput 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

 JSocketOutputChannel (JTCPSocket &socket)
 Constructor. More...
 
JStatus_t write ()
 Interruptable write method. More...
 
void reset ()
 Reset channel. More...
 
virtual int write (const char *buffer, const int length) override
 Write data to 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 read (char *buffer, const int length) override
 Read data from 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...
 
virtual bool getStatus () const override
 Status of writer. More...
 
void clear ()
 Clear buffer. More...
 
int tellp () const
 Get write position. More...
 
void seekp (const int pos)
 Set write position. More...
 
virtual int write (const char *buffer, const int length) override
 Write byte array. More...
 
JWriteroperator<< (const JSerialisable &object)
 Write serialisable data object. More...
 
JWriteroperator<< (const bool value)
 
JWriteroperator<< (const char value)
 
JWriteroperator<< (const unsigned char value)
 
JWriteroperator<< (const short value)
 
JWriteroperator<< (const unsigned short value)
 
JWriteroperator<< (const int value)
 
JWriteroperator<< (const unsigned int value)
 
JWriteroperator<< (const long int value)
 
JWriteroperator<< (const unsigned long int value)
 
JWriteroperator<< (const long long int value)
 
JWriteroperator<< (const unsigned long long int value)
 
JWriteroperator<< (const float value)
 
JWriteroperator<< (const double value)
 
JWriteroperator<< (const long double value)
 
JWriteroperator<< (const JLANG::JObjectID &value)
 
JWriterstore (const JSerialisable &object)
 Write object. More...
 
template<class T >
JWriterstore (const T &object)
 Write 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
 
int __pos
 

Detailed Description

template<class JPrefix_t>
class JNET::JSocketOutputChannel< JPrefix_t >

Socket output channel.

This class can be used to user write to an internal buffer, to format these data as a packet and to write this packet to the socket without blocking.

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 setSizeOfPacket() should be implemented for each header type.

The wroting to 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 writing the next data packet.

Definition at line 193 of file JSocketChannel.hh.

Member Enumeration Documentation

Enumerator
IO_RESET 
IO_READY 
IO_BUSY 

Definition at line 26 of file JSocketStatus.hh.

Enumerator
IO_PREFIX 
IO_DATA 

Definition at line 54 of file JSocketChannel.hh.

Constructor & Destructor Documentation

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

Constructor.

Parameters
socketsocket

Definition at line 208 of file JSocketChannel.hh.

208  :
209  JSocketNonblockingWriter(socket),
210  JSocketChannel(),
212  {
213  reset();
214  }
Auxiliary class for socket channel.
JByteArrayWriter(const int size=65536)
Constructor.
JSocketNonblockingWriter(const JTCPSocket &socket)
Constructor.
void reset()
Reset channel.

Member Function Documentation

template<class JPrefix_t >
JStatus_t JNET::JSocketOutputChannel< JPrefix_t >::write ( )
inline

Interruptable write method.

Returns
status

Definition at line 222 of file JSocketChannel.hh.

223  {
224  if (type == IO_PREFIX) {
225 
226  const int length = tellp();
227 
228  setSizeOfPacket(length, prefix);
229 
230  // overwrite prefix
231 
232  seekp(0);
233 
234  JByteArrayWriter::write((char*) &prefix, sizeof(JPrefix_t));
235 
236  seekp(length);
237 
238  type = IO_DATA;
239 
240  set(data(), tellp());
241  }
242 
243  if (isBusy()) {
245  }
246 
247  return JSocketStatus::getStatus();
248  }
ControlHost prefix.
Definition: JPrefix.hh:31
void seekp(const int pos)
Set write position.
void set(const JSocketBuffer< JElement_t > &buffer)
Initialise buffer.
JStatus_t getStatus() const
Get status of I/O.
virtual int write(const char *buffer, const int length) override
Write byte array.
JStatus_t write()
Continuation of non-blocking write method.
void setSizeOfPacket(const int size, JPrefix_t &prefix)
Set total size of internet packet.
Definition: JLigier.cc:51
bool isBusy() const
Check busy status.
int tellp() const
Get write position.
template<class JPrefix_t >
void JNET::JSocketOutputChannel< JPrefix_t >::reset ( )
inline

Reset channel.

After a reset, the socket channel is ready to receive a new data packet.

Definition at line 255 of file JSocketChannel.hh.

256  {
259 
260  // reserve space for prefix
261 
262  resize(sizeof(JPrefix_t));
263  seekp (sizeof(JPrefix_t));
264  }
ControlHost prefix.
Definition: JPrefix.hh:31
void seekp(const int pos)
Set write position.
void reset()
Reset channel.
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 222 of file JSocket.hh.

223  {
224  int pos = JFile::write(buffer, length);
225 
226  if (pos == 0) {
227 
228  THROW(JSocketException, "Socket write failed " << getFileDescriptor() << ' ' << errno);
229 
230  } else if (pos < 0) {
231 
232  switch (errno) {
233 
234  case EINTR:
235  case EWOULDBLOCK:
236  //case EAGAIN:
237  break;
238 
239  default:
240  THROW(JSocketException, "Socket write error " << getFileDescriptor() << ' ' << errno);
241  }
242 
243  pos = 0;
244  }
245 
246  return pos;
247  }
#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 write(const char *buffer, const int length)
Write data to file.
Definition: JFile.hh:93
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 53 of file JTCPSocket.hh.

54  {
55  const int flags = fcntl(getFileDescriptor(), F_GETFL, -1);
56  const int mask = FNDELAY;
57 
58  if (flags == -1) {
59  THROW(JSocketException, "Get socket option failed " << errno);
60  }
61 
62  if (((flags & mask) != mask && on) ||
63  ((flags & mask) != 0 && !on) ) {
64 
65  if (fcntl(getFileDescriptor(), F_SETFL, flags ^ mask) < 0) {
66  THROW(JSocketException, "Set socket option failed " << errno);
67  }
68  }
69  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
int getFileDescriptor() const
Get file descriptor.
bool JNET::JTCPSocket::getNonBlocking ( ) const
inlineinherited

Get non-blocking of I/O.

Returns
true if enabled non-blocking; else false

Definition at line 77 of file JTCPSocket.hh.

78  {
79  const int flags = fcntl(getFileDescriptor(), F_GETFL, -1);
80  const int mask = FNDELAY;
81 
82  if (flags == -1) {
83  THROW(JSocketException, "Get socket option failed " << errno);
84  }
85 
86  return ((flags & mask) != 0);
87  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
int getFileDescriptor() const
Get file descriptor.
void JNET::JTCPSocket::setKeepIdle ( const int  t_s)
inlineinherited

Set the TCP idle time.

Parameters
t_stime [s]

Definition at line 95 of file JTCPSocket.hh.

96  {
97  setOption(IPROTO_TCP, TCP_KEEPIDLE, t_s);
98  }
#define IPROTO_TCP
Definition: JTCPSocket.hh:11
void setOption(const int level, const int option, const T value)
Set socket option.
Definition: JSocket.hh:259
void JNET::JTCPSocket::setKeepCnt ( const int  count)
inlineinherited

Set the TCP idle count.

Parameters
countcount

Definition at line 106 of file JTCPSocket.hh.

107  {
108  setOption(IPROTO_TCP, TCP_KEEPCNT, count);
109  }
#define IPROTO_TCP
Definition: JTCPSocket.hh:11
void setOption(const int level, const int option, const T value)
Set socket option.
Definition: JSocket.hh:259
void JNET::JTCPSocket::setKeepIntvl ( const int  t_s)
inlineinherited

Set the TCP interval time.

Parameters
t_stime [s]

Definition at line 117 of file JTCPSocket.hh.

118  {
119  setOption(IPROTO_TCP, TCP_KEEPINTVL, t_s);
120  }
#define IPROTO_TCP
Definition: JTCPSocket.hh:11
void setOption(const int level, const int option, const T value)
Set socket option.
Definition: JSocket.hh:259
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 128 of file JTCPSocket.hh.

129  {
130  setOption(IPPROTO_TCP, TCP_NODELAY, int(on ? 1 : 0));
131  }
void setOption(const int level, const int option, const T value)
Set socket option.
Definition: JSocket.hh:259
bool JNET::JTCPSocket::getTcpNoDelay ( ) const
inlineinherited

Get TCP no-delay.

Returns
true if TCP no-delay; else false

Definition at line 139 of file JTCPSocket.hh.

140  {
141  return (getOption<int>(IPPROTO_TCP, TCP_NODELAY) == 1);
142  }
void JNET::JTCPSocket::accept ( const int  server)
inlineinherited

Accept connection from a server.

Parameters
serverfile descriptor of TCP server socket

Definition at line 150 of file JTCPSocket.hh.

151  {
152  socklen_t size = sizeof(sockaddr_in);
153 
154  fileDescriptor = ::accept(server, getSockaddr(), &size);
155  }
const sockaddr * getSockaddr() const
Get sockaddr.
void accept(const int server)
Accept connection from a server.
Definition: JTCPSocket.hh:150
void JNET::JTCPSocket::connect ( const int  port)
inlineinherited

Connect to port on local host.

Parameters
portport number

Definition at line 163 of file JTCPSocket.hh.

164  {
165  connect(INADDR_ANY, port);
166  }
void connect(const int port)
Connect to port on local host.
Definition: JTCPSocket.hh:163
void JNET::JTCPSocket::connect ( const JHostname hostname)
inlineinherited

Connect to port on specified host.

Parameters
hostnamehost name

Definition at line 174 of file JTCPSocket.hh.

175  {
176  connect(hostname.hostname, hostname.port);
177  }
std::string hostname
Definition: JHostname.hh:171
void connect(const int port)
Connect to port on local host.
Definition: JTCPSocket.hh:163
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 186 of file JTCPSocket.hh.

187  {
188  connect(JSYSTEM::getIPnumber(hostname), port);
189  }
int getIPnumber(const std::string &host_name)
Get IP number.
Definition: JNetwork.hh:117
void connect(const int port)
Connect to port on local host.
Definition: JTCPSocket.hh:163
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 198 of file JTCPSocket.hh.

199  {
200  setIPnumber(ip_number);
201  setPort(port);
202 
203  if (::connect(getFileDescriptor(), getSockaddr(), sizeof(sockaddr_in)) < 0) {
204  THROW(JSocketException, "Socket connection failed " << JSYSTEM::getIPaddress(ip_number) << ":" << port << " / " << getFileDescriptor() << " " << errno);
205  }
206  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
std::string getIPaddress(const int ip)
Get IP address (decimal-dot notation).
Definition: JNetwork.hh:154
void setIPnumber()
Set any IP number.
const sockaddr * getSockaddr() const
Get sockaddr.
int getFileDescriptor() const
Get file descriptor.
void setPort(const int port)
Set port number.
void connect(const int port)
Connect to port on local host.
Definition: JTCPSocket.hh:163
int JNET::JSocket::shutdown ( )
inlineinherited

Shut down socket.

Returns
return value

Definition at line 74 of file JSocket.hh.

75  {
76  const int value = ::shutdown(getFileDescriptor(), SHUT_RDWR);
77 
78  close();
79 
80  return value;
81  }
int close()
Close file.
Definition: JFile.hh:57
int getFileDescriptor() const
Get file descriptor.
int shutdown()
Shut down socket.
Definition: JSocket.hh:74
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 89 of file JSocket.hh.

90  {
91  setOption(SOL_SOCKET, SO_KEEPALIVE, int(on ? 1 : 0));
92  }
void setOption(const int level, const int option, const T value)
Set socket option.
Definition: JSocket.hh:259
bool JNET::JSocket::getKeepAlive ( ) const
inlineinherited

Get keep alive of socket.

Returns
true if keep alive; else false

Definition at line 100 of file JSocket.hh.

101  {
102  return (getOption<int>(SOL_SOCKET, SO_KEEPALIVE) == 1);
103  }
void JNET::JSocket::setReuseAddress ( const bool  on)
inlineinherited

Set reuse address.

Parameters
ontrue to enable reuse address; false to disable

Definition at line 111 of file JSocket.hh.

112  {
113  setOption(SOL_SOCKET, SO_REUSEADDR, int(on ? 1 : 0));
114  }
void setOption(const int level, const int option, const T value)
Set socket option.
Definition: JSocket.hh:259
bool JNET::JSocket::getReuseAddress ( ) const
inlineinherited

Get reuse address.

Returns
true if enable reuse address; else false

Definition at line 122 of file JSocket.hh.

123  {
124  return (getOption<int>(SOL_SOCKET, SO_REUSEADDR) == 1);
125  }
void JNET::JSocket::setReceiveBufferSize ( const int  size)
inlineinherited

Set receive buffer size.

Parameters
sizenumber of bytes

Definition at line 133 of file JSocket.hh.

134  {
135  setOption(SOL_SOCKET, SO_RCVBUF, int(size));
136  }
void setOption(const int level, const int option, const T value)
Set socket option.
Definition: JSocket.hh:259
int JNET::JSocket::getReceiveBufferSize ( ) const
inlineinherited

Set receive buffer size.

Returns
number of bytes

Definition at line 144 of file JSocket.hh.

145  {
146  return getOption<int>(SOL_SOCKET, SO_RCVBUF);
147  }
void JNET::JSocket::setSendBufferSize ( const int  size)
inlineinherited

Set send buffer size.

Parameters
sizenumber of bytes

Definition at line 155 of file JSocket.hh.

156  {
157  setOption(SOL_SOCKET, SO_SNDBUF, int(size));
158  }
void setOption(const int level, const int option, const T value)
Set socket option.
Definition: JSocket.hh:259
int JNET::JSocket::getSendBufferSize ( ) const
inlineinherited

Get send buffer size.

Returns
number of bytes

Definition at line 166 of file JSocket.hh.

167  {
168  return getOption<int>(SOL_SOCKET, SO_SNDBUF);
169  }
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 183 of file JSocket.hh.

184  {
185  int pos = JFile::read(buffer, length);
186 
187  if (pos == 0) {
188 
189  THROW(JSocketException, "Socket read failed " << getFileDescriptor() << ' ' << errno);
190 
191  } else if (pos < 0) {
192 
193  switch (errno) {
194 
195  case EINTR:
196  case EWOULDBLOCK:
197  //case EAGAIN:
198  break;
199 
200  default:
201  THROW(JSocketException, "Socket read error " << getFileDescriptor() << ' ' << errno);
202  }
203 
204  pos = 0;
205  }
206 
207  return pos;
208  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
virtual int read(char *buffer, const int length)
Read data from file.
Definition: JFile.hh:80
int getFileDescriptor() const
Get file descriptor.
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 259 of file JSocket.hh.

260  {
261  socklen_t size = sizeof(T);
262 
263  if (setsockopt(getFileDescriptor(), level, option, &value, size) < 0) {
264  THROW(JSocketException, "Set socket option failed " << errno);
265  }
266  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
int getFileDescriptor() const
Get file descriptor.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
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 277 of file JSocket.hh.

278  {
279  T value;
280  socklen_t size = sizeof(T);
281 
282  if (getsockopt(getFileDescriptor(), level, option, &value, &size) < 0) {
283  THROW(JSocketException, "Get socket option failed " << errno);
284  }
285 
286  return value;
287  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
int getFileDescriptor() const
Get file descriptor.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
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  }
int close()
Close file.
Definition: JFile.hh:57
static const int FILE_CLOSED
int result
Definition: JFile.hh:170
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.
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.
Auxiliary class for method select.
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  }
virtual bool eof() const
Check end of file.
Definition: JFile.hh:163
bool is_open() const
Get open status.
virtual bool bad() const
Check status.
Definition: JFile.hh:152
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  }
int result
Definition: JFile.hh:170
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
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  }
int result
Definition: JFile.hh:170
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  }
int getFileDescriptor() const
Get file descriptor.
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  }
void JLANG::JAbstractFile::setFileDescriptor ( const int  file)
inlineinherited

Set file descriptor.

Parameters
filefile descriptor

Definition at line 86 of file JAbstractFile.hh.

87  {
89  }
then usage $script[< detector identifier >< run range >]< QA/QCfile > nExample script to produce data quality plots nWhen a detector identifier and run range are data are downloaded from the database nand subsequently stored in the given QA QC file
Definition: JDataQuality.sh:19
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  }
static const int FILE_CLOSED
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  }
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  }
int JNET::JSocketAddress::getFamily ( ) const
inlineinherited

Get family.

Returns
family

Definition at line 66 of file JSocketAddress.hh.

67  {
68  return sin_family;
69  }
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  }
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
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  }
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  }
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  }
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  }
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  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
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  }
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  }
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  }
void set(const JSocketBuffer< JElement_t > &buffer)
Initialise buffer.
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  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
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  }
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  }
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  }
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  }
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  }
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  }
virtual bool JIO::JByteArrayWriter::getStatus ( ) const
inlineoverridevirtualinherited

Status of writer.

Returns
status of this writer

Implements JLANG::JAbstractObjectStatus.

Definition at line 180 of file JByteArrayIO.hh.

181  {
182  return true;
183  }
void JIO::JByteArrayWriter::clear ( )
inlineinherited

Clear buffer.

Definition at line 189 of file JByteArrayIO.hh.

190  {
192 
193  __pos = 0;
194  }
int JIO::JByteArrayWriter::tellp ( ) const
inlineinherited

Get write position.

Returns
write position

Definition at line 202 of file JByteArrayIO.hh.

203  {
204  return __pos;
205  }
void JIO::JByteArrayWriter::seekp ( const int  pos)
inlineinherited

Set write position.

Parameters
poswrite position

Definition at line 213 of file JByteArrayIO.hh.

214  {
215  __pos = pos;
216  }
virtual int JIO::JByteArrayWriter::write ( const char *  buffer,
const int  length 
)
inlineoverridevirtualinherited

Write byte array.

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

Implements JLANG::JBinaryOutput.

Definition at line 226 of file JByteArrayIO.hh.

227  {
228  if (__pos + length > (int) this->size()) {
229  this->resize(__pos + length);
230  }
231 
232  memcpy(this->data() + __pos, buffer, length);
233 
234  __pos += length;
235 
236  return length;
237  }
JWriter& JIO::JWriter::operator<< ( const JSerialisable object)
inlineinherited

Write serialisable data object.

Parameters
objectserialisable data object
Returns
JWriter

Definition at line 144 of file JSerialisable.hh.

145  {
146  return object.write(*this);
147  }
JWriter& JIO::JWriter::operator<< ( const bool  value)
inlineinherited

Definition at line 150 of file JSerialisable.hh.

150 { write((const char*) &value, sizeof(bool)); return *this; }
virtual int write(const char *buffer, const int length)=0
Write byte array.
JWriter& JIO::JWriter::operator<< ( const char  value)
inlineinherited

Definition at line 151 of file JSerialisable.hh.

151 { write((const char*) &value, sizeof(char)); return *this; }
virtual int write(const char *buffer, const int length)=0
Write byte array.
JWriter& JIO::JWriter::operator<< ( const unsigned char  value)
inlineinherited

Definition at line 152 of file JSerialisable.hh.

152 { write((const char*) &value, sizeof(unsigned char)); return *this; }
virtual int write(const char *buffer, const int length)=0
Write byte array.
JWriter& JIO::JWriter::operator<< ( const short  value)
inlineinherited

Definition at line 153 of file JSerialisable.hh.

153 { write((const char*) &value, sizeof(short)); return *this; }
virtual int write(const char *buffer, const int length)=0
Write byte array.
JWriter& JIO::JWriter::operator<< ( const unsigned short  value)
inlineinherited

Definition at line 154 of file JSerialisable.hh.

154 { write((const char*) &value, sizeof(unsigned short)); return *this; }
virtual int write(const char *buffer, const int length)=0
Write byte array.
JWriter& JIO::JWriter::operator<< ( const int  value)
inlineinherited

Definition at line 155 of file JSerialisable.hh.

155 { write((const char*) &value, sizeof(int)); return *this; }
virtual int write(const char *buffer, const int length)=0
Write byte array.
JWriter& JIO::JWriter::operator<< ( const unsigned int  value)
inlineinherited

Definition at line 156 of file JSerialisable.hh.

156 { write((const char*) &value, sizeof(unsigned int)); return *this; }
virtual int write(const char *buffer, const int length)=0
Write byte array.
JWriter& JIO::JWriter::operator<< ( const long int  value)
inlineinherited

Definition at line 157 of file JSerialisable.hh.

157 { write((const char*) &value, sizeof(long int)); return *this; }
virtual int write(const char *buffer, const int length)=0
Write byte array.
JWriter& JIO::JWriter::operator<< ( const unsigned long int  value)
inlineinherited

Definition at line 158 of file JSerialisable.hh.

158 { write((const char*) &value, sizeof(unsigned long int)); return *this; }
virtual int write(const char *buffer, const int length)=0
Write byte array.
JWriter& JIO::JWriter::operator<< ( const long long int  value)
inlineinherited

Definition at line 159 of file JSerialisable.hh.

159 { write((const char*) &value, sizeof(long long int)); return *this; }
virtual int write(const char *buffer, const int length)=0
Write byte array.
JWriter& JIO::JWriter::operator<< ( const unsigned long long int  value)
inlineinherited

Definition at line 160 of file JSerialisable.hh.

160 { write((const char*) &value, sizeof(unsigned long long int)); return *this; }
virtual int write(const char *buffer, const int length)=0
Write byte array.
JWriter& JIO::JWriter::operator<< ( const float  value)
inlineinherited

Definition at line 161 of file JSerialisable.hh.

161 { write((const char*) &value, sizeof(float)); return *this; }
virtual int write(const char *buffer, const int length)=0
Write byte array.
JWriter& JIO::JWriter::operator<< ( const double  value)
inlineinherited

Definition at line 162 of file JSerialisable.hh.

162 { write((const char*) &value, sizeof(double)); return *this; }
virtual int write(const char *buffer, const int length)=0
Write byte array.
JWriter& JIO::JWriter::operator<< ( const long double  value)
inlineinherited

Definition at line 163 of file JSerialisable.hh.

163 { write((const char*) &value, sizeof(long double)); return *this; }
virtual int write(const char *buffer, const int length)=0
Write byte array.
JWriter& JIO::JWriter::operator<< ( const JLANG::JObjectID value)
inlineinherited

Definition at line 164 of file JSerialisable.hh.

164 { return (*this) << value.getID(); }
int getID() const
Get identifier.
Definition: JObjectID.hh:50
JWriter& JIO::JWriter::store ( const JSerialisable object)
inlineinherited

Write object.

Parameters
objectobject
Returns
this writer

Definition at line 173 of file JSerialisable.hh.

174  {
175  return object.write(*this);
176  }
template<class T >
JWriter& JIO::JWriter::store ( const T object)
inlineinherited

Write object.

Parameters
objectobject
Returns
this writer

Definition at line 186 of file JSerialisable.hh.

187  {
188  return *this << object;
189  }
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.
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  }
virtual bool getStatus() const =0
Get status of object.

Member Data Documentation

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

Definition at line 267 of file JSocketChannel.hh.

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

Definition at line 27 of file JAbstractFile.hh.

int JLANG::JAbstractFile::fileDescriptor
protectedinherited

Definition at line 102 of file JAbstractFile.hh.

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

Definition at line 104 of file JSocketNonblocking.hh.

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

Definition at line 105 of file JSocketNonblocking.hh.

JStatus_t JNET::JSocketStatus::status
protectedinherited

Definition at line 115 of file JSocketStatus.hh.

int JNET::JSocketStatus::counter
protectedinherited

Definition at line 116 of file JSocketStatus.hh.

JType JNET::JSocketChannel::type
protectedinherited

Definition at line 67 of file JSocketChannel.hh.

int JIO::JByteArrayWriter::__pos
protectedinherited

Definition at line 241 of file JByteArrayIO.hh.


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