Jpp  17.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
JNET::JClient Class Reference

ControlHost client manager. More...

Inheritance diagram for JNET::JClient:
JNET::JSocket JLANG::JFile JNET::JSocketAddress JLANG::JAbstractFile JLANG::JBinaryInput JLANG::JBinaryOutput JLANG::JComparable< JAbstractFile >

Public Member Functions

 JClient ()
 Default constructor. More...
 
 JClient (const JSocket &socket)
 Constructor. More...
 
const std::string & getNickname () const
 Get nick name. More...
 
void setNickname (const std::string &nick_name)
 Set nick name. More...
 
bool checkRequest () const
 Check request. More...
 
void incrementRequest ()
 Increment request by one. More...
 
void decrementRequest ()
 Decrement request by one. More...
 
void setRequestAll ()
 Set no request. More...
 
const std::set< JTag > & getSubscriptionAll () const
 Get subscription. More...
 
const std::set< JTag > & getSubscriptionAny () const
 Get subscription. More...
 
bool setSubscription (const std::string &subscription)
 Set subcription. More...
 
bool checkSubscriptionAll (const JPrefix_t &prefix) const
 Check subscription for given prefix. More...
 
bool checkSubscriptionAny (const JPrefix_t &prefix) const
 Check subscription for given prefix. More...
 
bool checkSubscription (const JPrefix_t &prefix) const
 Check subscription for given prefix. More...
 
void add (const JDispatch &message)
 Add message to client queues depending on subscription of each client. More...
 
void drop ()
 Drop all messages for which the client has not the 'all' subscription. 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 read (char *buffer, const int length) override
 Read data from socket. More...
 
virtual int write (const char *buffer, const int length) override
 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...
 

Static Public Member Functions

static int sizeOf ()
 Get size of object. More...
 

Public Attributes

JSocketInputChannel_t in
 reader for incoming messages More...
 
JSocketNonblockingWriter out
 writer for outgoing messages More...
 
std::deque< JDispatchqueue
 queue for outgoing messages More...
 

Static Public Attributes

static unsigned int QUEUE_LIMIT
 Maximum number of messages in queue. More...
 
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...
 

Protected Attributes

std::set< JTagsubscriptionAll
 
std::set< JTagsubscriptionAny
 
std::string nick_name
 
bool requestAll
 
int requestCounter
 
int fileDescriptor
 

Detailed Description

ControlHost client manager.

Definition at line 243 of file JLigier.cc.

Constructor & Destructor Documentation

JNET::JClient::JClient ( )
inline

Default constructor.

Definition at line 255 of file JLigier.cc.

255  :
256  JSocket(),
257  in (*this),
258  out(*this),
259  requestAll(false),
260  requestCounter(0)
261  {}
JSocketNonblockingWriter out
writer for outgoing messages
Definition: JLigier.cc:462
bool requestAll
Definition: JLigier.cc:469
int requestCounter
Definition: JLigier.cc:470
JSocketInputChannel_t in
reader for incoming messages
Definition: JLigier.cc:461
JSocket()
Default constructor.
Definition: JSocket.hh:51
JNET::JClient::JClient ( const JSocket socket)
inline

Constructor.

Parameters
socketsocket

Definition at line 269 of file JLigier.cc.

269  :
270  JSocket(socket),
271  in (*this),
272  out(*this),
273  requestAll(false),
274  requestCounter(0)
275  {}
JSocketNonblockingWriter out
writer for outgoing messages
Definition: JLigier.cc:462
bool requestAll
Definition: JLigier.cc:469
int requestCounter
Definition: JLigier.cc:470
JSocketInputChannel_t in
reader for incoming messages
Definition: JLigier.cc:461
JSocket()
Default constructor.
Definition: JSocket.hh:51

Member Function Documentation

const std::string& JNET::JClient::getNickname ( ) const
inline

Get nick name.

Returns
nick name

Definition at line 283 of file JLigier.cc.

284  {
285  return nick_name;
286  }
std::string nick_name
Definition: JLigier.cc:468
void JNET::JClient::setNickname ( const std::string &  nick_name)
inline

Set nick name.

Parameters
nick_namenick name

Definition at line 294 of file JLigier.cc.

295  {
296  this->nick_name = nick_name;
297  }
std::string nick_name
Definition: JLigier.cc:468
bool JNET::JClient::checkRequest ( ) const
inline

Check request.

Returns
true if request can be honoured; else false

Definition at line 305 of file JLigier.cc.

306  {
307  return requestAll || requestCounter != 0;
308  }
bool requestAll
Definition: JLigier.cc:469
int requestCounter
Definition: JLigier.cc:470
void JNET::JClient::incrementRequest ( )
inline

Increment request by one.

Definition at line 314 of file JLigier.cc.

315  {
316  ++requestCounter;
317  }
int requestCounter
Definition: JLigier.cc:470
void JNET::JClient::decrementRequest ( )
inline

Decrement request by one.

Definition at line 323 of file JLigier.cc.

324  {
325  --requestCounter;
326  }
int requestCounter
Definition: JLigier.cc:470
void JNET::JClient::setRequestAll ( )
inline

Set no request.

Definition at line 332 of file JLigier.cc.

333  {
334  requestAll = true;
335  }
bool requestAll
Definition: JLigier.cc:469
const std::set<JTag>& JNET::JClient::getSubscriptionAll ( ) const
inline

Get subscription.

Returns
subscription

Definition at line 343 of file JLigier.cc.

344  {
345  return subscriptionAll;
346  }
std::set< JTag > subscriptionAll
Definition: JLigier.cc:466
const std::set<JTag>& JNET::JClient::getSubscriptionAny ( ) const
inline

Get subscription.

Returns
subscription

Definition at line 354 of file JLigier.cc.

355  {
356  return subscriptionAny;
357  }
std::set< JTag > subscriptionAny
Definition: JLigier.cc:467
bool JNET::JClient::setSubscription ( const std::string &  subscription)
inline

Set subcription.

Parameters
subscriptionsubscription
Returns
true of OK; else false

Definition at line 366 of file JLigier.cc.

367  {
368  using namespace std;
369 
370  subscriptionAll.clear();
371  subscriptionAny.clear();
372 
373  try {
374 
375  char c;
376  JTag tag;
377 
378  for (istringstream is(subscription); is >> c >> tag; ) {
379  if (c == SUBSCRIBE_ALL) subscriptionAll.insert(tag);
380  else if (c == SUBSCRIBE_ANY) subscriptionAny.insert(tag);
381  //else if (c == SUBSCRIBE_SHARED_MEMORY) subscriptionAny.insert(tag);
382  }
383  }
384  catch(const JControlHostException& error) {
385  return false;
386  }
387 
388  return true;
389  }
std::set< JTag > subscriptionAll
Definition: JLigier.cc:466
std::set< JTag > subscriptionAny
Definition: JLigier.cc:467
is
Definition: JDAQCHSM.chsm:167
$WORKDIR ev_configure_domsimulator txt echo process $DOM_SIMULATOR $i $SOURCE_HOST[$index] csh c(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&($DOM_SIMULATOR\-u\$NAME\$\-H\$SERVER\$\-M\$LOGGER\$\-d $DEBUG</dev/null > &/dev/null &))'
bool JNET::JClient::checkSubscriptionAll ( const JPrefix_t prefix) const
inline

Check subscription for given prefix.

Parameters
prefixprefix
Returns
true if subscription valid; else false

Definition at line 398 of file JLigier.cc.

399  {
400  return subscriptionAll.find(prefix) != subscriptionAll.end();
401  }
std::set< JTag > subscriptionAll
Definition: JLigier.cc:466
bool JNET::JClient::checkSubscriptionAny ( const JPrefix_t prefix) const
inline

Check subscription for given prefix.

Parameters
prefixprefix
Returns
true if subscription valid; else false

Definition at line 410 of file JLigier.cc.

411  {
412  return subscriptionAny.find(prefix) != subscriptionAny.end() && checkRequest() && queue.size() < QUEUE_LIMIT;
413  }
std::deque< JDispatch > queue
queue for outgoing messages
Definition: JLigier.cc:463
std::set< JTag > subscriptionAny
Definition: JLigier.cc:467
bool checkRequest() const
Check request.
Definition: JLigier.cc:305
static unsigned int QUEUE_LIMIT
Maximum number of messages in queue.
Definition: JLigier.cc:249
bool JNET::JClient::checkSubscription ( const JPrefix_t prefix) const
inline

Check subscription for given prefix.

Parameters
prefixprefix
Returns
true if subscription valid; else false

Definition at line 422 of file JLigier.cc.

423  {
424  return checkSubscriptionAll(prefix) || checkSubscriptionAny(prefix);
425  }
bool checkSubscriptionAll(const JPrefix_t &prefix) const
Check subscription for given prefix.
Definition: JLigier.cc:398
bool checkSubscriptionAny(const JPrefix_t &prefix) const
Check subscription for given prefix.
Definition: JLigier.cc:410
void JNET::JClient::add ( const JDispatch message)
inline

Add message to client queues depending on subscription of each client.

Note that adding a message may result in dropping (other) messages.

Parameters
messagemessage

Definition at line 434 of file JLigier.cc.

435  {
436  if (checkSubscription(message)) {
437 
438  queue.push_back(message);
439 
440  if (queue.size() > QUEUE_LIMIT) {
441  drop();
442  }
443  }
444  }
std::deque< JDispatch > queue
queue for outgoing messages
Definition: JLigier.cc:463
bool checkSubscription(const JPrefix_t &prefix) const
Check subscription for given prefix.
Definition: JLigier.cc:422
void drop()
Drop all messages for which the client has not the &#39;all&#39; subscription.
Definition: JLigier.cc:450
static unsigned int QUEUE_LIMIT
Maximum number of messages in queue.
Definition: JLigier.cc:249
void JNET::JClient::drop ( )
inline

Drop all messages for which the client has not the 'all' subscription.

Definition at line 450 of file JLigier.cc.

451  {
452  for (std::deque<JDispatch>::iterator i = queue.begin(); i != queue.end(); ) {
453  if (!checkSubscriptionAll(*i) && (i != queue.begin() || !out.isBusy()))
454  i = queue.erase(i);
455  else
456  ++i;
457  }
458  }
JSocketNonblockingWriter out
writer for outgoing messages
Definition: JLigier.cc:462
std::deque< JDispatch > queue
queue for outgoing messages
Definition: JLigier.cc:463
bool checkSubscriptionAll(const JPrefix_t &prefix) const
Check subscription for given prefix.
Definition: JLigier.cc:398
bool isBusy() const
Check busy status.
int JNET::JSocket::shutdown ( )
inlineinherited

Shut down socket.

Definition at line 95 of file JSocket.hh.

96  {
97  const int value = ::shutdown(getFileDescriptor(), SHUT_RDWR);
98 
99  close();
100 
101  return value;
102  }
void close()
Close file.
Definition: JFile.hh:55
int getFileDescriptor() const
Get file descriptor.
int shutdown()
Shut down socket.
Definition: JSocket.hh:95
void JNET::JSocket::setNonBlocking ( const bool  on)
inlineinherited

Set non-blocking of I/O.

Parameters
ontrue to enable non-blocking; false to disable

Definition at line 110 of file JSocket.hh.

111  {
112  const int flags = fcntl(getFileDescriptor(), F_GETFL, -1);
113  const int mask = FNDELAY;
114 
115  if (flags == -1) {
116  THROW(JSocketException, "Get socket option failed.");
117  }
118 
119  if (((flags & mask) != mask && on) ||
120  ((flags & mask) != 0 && !on) ) {
121 
122  if (fcntl(getFileDescriptor(), F_SETFL, flags ^ mask) < 0) {
123  THROW(JSocketException, "Set socket option failed.");
124  }
125  }
126  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
int getFileDescriptor() const
Get file descriptor.
bool JNET::JSocket::getNonBlocking ( ) const
inlineinherited

Get non-blocking of I/O.

Returns
true if enabled non-blocking; else false

Definition at line 134 of file JSocket.hh.

135  {
136  const int flags = fcntl(getFileDescriptor(), F_GETFL, -1);
137  const int mask = FNDELAY;
138 
139  if (flags == -1) {
140  THROW(JSocketException, "Get socket option failed.");
141  }
142 
143  return ((flags & mask) != 0);
144  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
int getFileDescriptor() const
Get file descriptor.
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 152 of file JSocket.hh.

153  {
154  setOption(SOL_SOCKET, SO_KEEPALIVE, int(on ? 1 : 0));
155  }
void setOption(const int level, const int option, const T value)
Set socket option.
Definition: JSocket.hh:429
bool JNET::JSocket::getKeepAlive ( ) const
inlineinherited

Get keep alive of socket.

Returns
true if keep alive; else false

Definition at line 163 of file JSocket.hh.

164  {
165  return (getOption<int>(SOL_SOCKET, SO_KEEPALIVE) == 1);
166  }
void JNET::JSocket::setKeepIdle ( const int  t_s)
inlineinherited

Set the TCP idle time.

Parameters
t_stime [s]

Definition at line 174 of file JSocket.hh.

175  {
176  setOption(IPROTO_TCP, TCP_KEEPIDLE, t_s);
177  }
#define IPROTO_TCP
Definition: JSocket.hh:18
void setOption(const int level, const int option, const T value)
Set socket option.
Definition: JSocket.hh:429
void JNET::JSocket::setKeepCnt ( const int  count)
inlineinherited

Set the TCP idle count.

Parameters
countcount

Definition at line 185 of file JSocket.hh.

186  {
187  setOption(IPROTO_TCP, TCP_KEEPCNT, count);
188  }
#define IPROTO_TCP
Definition: JSocket.hh:18
std::vector< int > count
Definition: JAlgorithm.hh:180
void setOption(const int level, const int option, const T value)
Set socket option.
Definition: JSocket.hh:429
void JNET::JSocket::setKeepIntvl ( const int  t_s)
inlineinherited

Set the TCP interval time.

Parameters
t_stime [s]

Definition at line 196 of file JSocket.hh.

197  {
198  setOption(IPROTO_TCP, TCP_KEEPINTVL, t_s);
199  }
#define IPROTO_TCP
Definition: JSocket.hh:18
void setOption(const int level, const int option, const T value)
Set socket option.
Definition: JSocket.hh:429
void JNET::JSocket::setReuseAddress ( const bool  on)
inlineinherited

Set reuse address.

Parameters
ontrue to enable reuse address; false to disable

Definition at line 207 of file JSocket.hh.

208  {
209  setOption(SOL_SOCKET, SO_REUSEADDR, int(on ? 1 : 0));
210  }
void setOption(const int level, const int option, const T value)
Set socket option.
Definition: JSocket.hh:429
bool JNET::JSocket::getReuseAddress ( ) const
inlineinherited

Get reuse address.

Returns
true if enable reuse address; else false

Definition at line 218 of file JSocket.hh.

219  {
220  return (getOption<int>(SOL_SOCKET, SO_REUSEADDR) == 1);
221  }
void JNET::JSocket::setTcpNoDelay ( const bool  on)
inlineinherited

Set TCP no-delay.

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

Definition at line 229 of file JSocket.hh.

230  {
231  setOption(IPPROTO_TCP, TCP_NODELAY, int(on ? 1 : 0));
232  }
void setOption(const int level, const int option, const T value)
Set socket option.
Definition: JSocket.hh:429
bool JNET::JSocket::getTcpNoDelay ( ) const
inlineinherited

Get TCP no-delay.

Returns
true if TCP no-delay; else false

Definition at line 240 of file JSocket.hh.

241  {
242  return (getOption<int>(IPPROTO_TCP, TCP_NODELAY) == 1);
243  }
void JNET::JSocket::setReceiveBufferSize ( const int  size)
inlineinherited

Set receive buffer size.

Parameters
sizenumber of bytes

Definition at line 251 of file JSocket.hh.

252  {
253  setOption(SOL_SOCKET, SO_RCVBUF, int(size));
254  }
void setOption(const int level, const int option, const T value)
Set socket option.
Definition: JSocket.hh:429
int JNET::JSocket::getReceiveBufferSize ( ) const
inlineinherited

Set receive buffer size.

Returns
number of bytes

Definition at line 262 of file JSocket.hh.

263  {
264  return getOption<int>(SOL_SOCKET, SO_RCVBUF);
265  }
void JNET::JSocket::setSendBufferSize ( const int  size)
inlineinherited

Set send buffer size.

Parameters
sizenumber of bytes

Definition at line 273 of file JSocket.hh.

274  {
275  setOption(SOL_SOCKET, SO_SNDBUF, int(size));
276  }
void setOption(const int level, const int option, const T value)
Set socket option.
Definition: JSocket.hh:429
int JNET::JSocket::getSendBufferSize ( ) const
inlineinherited

Get send buffer size.

Returns
number of bytes

Definition at line 284 of file JSocket.hh.

285  {
286  return getOption<int>(SOL_SOCKET, SO_SNDBUF);
287  }
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::JSocketBlocking.

Definition at line 301 of file JSocket.hh.

302  {
303  int pos = JFile::read(buffer, length);
304 
305  if (pos == 0) {
306 
307  THROW(JSocketException, "Socket read failed.");
308 
309  } else if (pos < 0) {
310 
311  switch (errno) {
312 
313  case EINTR:
314  case EWOULDBLOCK:
315  //case EAGAIN:
316  break;
317 
318  default:
319  THROW(JSocketException, "Socket read error.");
320  }
321 
322  pos = 0;
323  }
324 
325  return pos;
326  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
virtual int read(char *buffer, const int length)
Read data from file.
Definition: JFile.hh:74
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::JSocketBlocking.

Definition at line 340 of file JSocket.hh.

341  {
342  int pos = JFile::write(buffer, length);
343 
344  if (pos == 0) {
345 
346  THROW(JSocketException, "Socket write failed.");
347 
348  } else if (pos < 0) {
349 
350  switch (errno) {
351 
352  case EINTR:
353  case EWOULDBLOCK:
354  //case EAGAIN:
355  break;
356 
357  default:
358  THROW(JSocketException, "Socket write error.");
359  }
360 
361  pos = 0;
362  }
363 
364  return pos;
365  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
virtual int write(const char *buffer, const int length)
Write data to file.
Definition: JFile.hh:87
void JNET::JSocket::accept ( const int  server)
inlineinherited

Accept connection from a server.

Parameters
serverfile descriptor of server socket

Definition at line 373 of file JSocket.hh.

374  {
375  socklen_t size = sizeof(sockaddr_in);
376  fileDescriptor = ::accept(server, getSockaddr(), &size);
377  }
const sockaddr * getSockaddr() const
Get sockaddr.
void accept(const int server)
Accept connection from a server.
Definition: JSocket.hh:373
void JNET::JSocket::connect ( const int  port)
inlineinherited

Connect to port on local host.

Parameters
portport number

Definition at line 385 of file JSocket.hh.

386  {
387  connect(INADDR_ANY, port);
388  }
void connect(const int port)
Connect to port on local host.
Definition: JSocket.hh:385
void JNET::JSocket::connect ( const std::string &  host_name,
const int  port 
)
inlineinherited

Connect to port on specified host.

Parameters
host_namehost name
portport number

Definition at line 397 of file JSocket.hh.

398  {
399  connect(JSYSTEM::getIPnumber(host_name), port);
400  }
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: JSocket.hh:385
void JNET::JSocket::connect ( const int  ip_number,
const int  port 
)
inlineinherited

Connect to port on specified host.

Parameters
ip_numberIP number
portport number

Definition at line 409 of file JSocket.hh.

410  {
411  setIPnumber(ip_number);
412  setPort(port);
413 
414  if (::connect(getFileDescriptor(), getSockaddr(), sizeof(sockaddr_in)) < 0) {
415  THROW(JSocketException, "Socket connection failed " << getIPaddress(ip_number) << ":" << port);
416  }
417  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
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: JSocket.hh:385
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 429 of file JSocket.hh.

430  {
431  socklen_t size = sizeof(T);
432 
433  if (setsockopt(getFileDescriptor(), level, option, &value, size) < 0) {
434  THROW(JSocketException, "Set socket option failed.");
435  }
436  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
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 447 of file JSocket.hh.

448  {
449  T value;
450  socklen_t size = sizeof(T);
451 
452  if (getsockopt(getFileDescriptor(), level, option, &value, &size) < 0) {
453  THROW(JSocketException, "Get socket option failed.");
454  }
455 
456  return value;
457  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
int getFileDescriptor() const
Get file descriptor.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
void JLANG::JFile::close ( )
inlineinherited

Close file.

Definition at line 55 of file JFile.hh.

56  {
57  if (fileDescriptor != FILE_CLOSED) {
58 
60 
62  result = 0;
63  }
64  }
void close()
Close file.
Definition: JFile.hh:55
static const int FILE_CLOSED
int result
Definition: JFile.hh:164
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 100 of file JFile.hh.

101  {
102  return JFileDescriptorMask(*this).in_avail(timeout);
103  }
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 113 of file JFile.hh.

114  {
115  return JFileDescriptorMask(*this).out_avail(timeout);
116  }
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 124 of file JFile.hh.

125  {
126  return is_open() && !eof() && !bad();
127  }
virtual bool eof() const
Check end of file.
Definition: JFile.hh:157
bool is_open() const
Get open status.
virtual bool bad() const
Check status.
Definition: JFile.hh:146
virtual bool JLANG::JFile::fail ( ) const
inlinevirtualinherited

Check status.

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

Definition at line 135 of file JFile.hh.

136  {
137  return result == 0;
138  }
int result
Definition: JFile.hh:164
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 146 of file JFile.hh.

147  {
148  return fail();
149  }
virtual bool fail() const
Check status.
Definition: JFile.hh:135
virtual bool JLANG::JFile::eof ( ) const
inlinevirtualinherited

Check end of file.

Returns
true if end of file; else false

Definition at line 157 of file JFile.hh.

158  {
159  return result == EOF;
160  }
int result
Definition: JFile.hh:164
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  }
bool JLANG::JAbstractFile::is_open ( ) const
inlineinherited

Get open status.

Definition at line 84 of file JAbstractFile.hh.

85  {
86  return fileDescriptor != FILE_CLOSED;
87  }
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:696
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  }

Member Data Documentation

unsigned int JNET::JClient::QUEUE_LIMIT
static

Maximum number of messages in queue.

queue size limit

Definition at line 249 of file JLigier.cc.

JSocketInputChannel_t JNET::JClient::in

reader for incoming messages

Definition at line 461 of file JLigier.cc.

JSocketNonblockingWriter JNET::JClient::out

writer for outgoing messages

Definition at line 462 of file JLigier.cc.

std::deque<JDispatch> JNET::JClient::queue

queue for outgoing messages

Definition at line 463 of file JLigier.cc.

std::set<JTag> JNET::JClient::subscriptionAll
protected

Definition at line 466 of file JLigier.cc.

std::set<JTag> JNET::JClient::subscriptionAny
protected

Definition at line 467 of file JLigier.cc.

std::string JNET::JClient::nick_name
protected

Definition at line 468 of file JLigier.cc.

bool JNET::JClient::requestAll
protected

Definition at line 469 of file JLigier.cc.

int JNET::JClient::requestCounter
protected

Definition at line 470 of file JLigier.cc.

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

Definition at line 27 of file JAbstractFile.hh.

int JLANG::JAbstractFile::fileDescriptor
protectedinherited

Definition at line 91 of file JAbstractFile.hh.


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