SocketUtils Class Reference

#include <SocketUtils.h>

List of all members.

Public Member Functions

 SocketUtils (TROOT *serv, TMonitor *moni, TSocket *sock)
 ~SocketUtils ()
const string getStringMessage ()
const string getHostname ()
const string getId ()
void closeSocket ()

Private Member Functions

 SocketUtils (const SocketUtils &su)
SocketUtilsoperator= (const SocketUtils &su)

Private Attributes

TROOT * _server
TMonitor * _moni
TSocket * _socket
string _hostname
string _id

Detailed Description

Definition at line 33 of file SocketUtils.h.


Constructor & Destructor Documentation

SocketUtils::SocketUtils ( TROOT *  serv,
TMonitor *  moni,
TSocket *  sock 
)

Definition at line 29 of file SocketUtils.cc.

References _hostname, _id, and port.

00030   : _server(serv), _moni(moni), _socket(sock), _id(":") 
00031 {
00032   _hostname = string(sock->GetInetAddress().GetHostName());
00033   int    port = sock->GetInetAddress().GetPort();
00034   char portChar[20];
00035   sprintf(portChar, "%d", port);
00036   _id = _hostname + string(":") + string(portChar);
00037 
00038 }

SocketUtils::~SocketUtils (  ) 

Definition at line 40 of file SocketUtils.cc.

00041 {
00042 }

SocketUtils::SocketUtils ( const SocketUtils su  )  [private]

Member Function Documentation

void SocketUtils::closeSocket (  ) 

Definition at line 86 of file SocketUtils.cc.

References _moni, _server, and _socket.

Referenced by getStringMessage(), DisplayServer::pollClients(), and DisplayServer::pollConsumer().

00087 {
00088   // Close the socket, remove it from the socket lists and delete it. 
00089   if ( _socket && (_socket != (TSocket*)-1) ) {
00090     if (_moni) _moni->Remove(_socket);
00091     _socket->Close();
00092     _server->GetListOfSockets()->Remove(_socket);
00093     delete _socket;
00094    _socket = 0;
00095   }
00096   else {
00097     cerr << "SocketUtils::closeSocket(): ERROR: _socket not valid." << endl;
00098   }  
00099 
00100   return;
00101 }

const string SocketUtils::getHostname (  ) 

Definition at line 74 of file SocketUtils.cc.

References _hostname.

Referenced by DisplayServer::pollClients().

00075 {
00076   return _hostname;
00077 }

const string SocketUtils::getId (  ) 

Definition at line 80 of file SocketUtils.cc.

References _id.

Referenced by DisplayServer::pollClients().

00081 {
00082   return _id;
00083 } 

const string SocketUtils::getStringMessage (  ) 

Definition at line 44 of file SocketUtils.cc.

References _socket, and closeSocket().

Referenced by DisplayServer::pollClients(), and DisplayServer::pollConsumer().

00045 {
00046   char*     mess = 0;
00047   TMessage* clientMess = 0;
00048   Int_t     recvRes = 0;
00049 
00050   if ( _socket && (_socket != (TSocket*)-1) ) {
00051     recvRes = _socket->Recv(clientMess);
00052     if ((recvRes != -1) && (recvRes != 0)) {
00053       if (clientMess) { 
00054         if (clientMess->What() == kMESS_STRING) {
00055           int messLength = clientMess->BufferSize() + 10; 
00056           mess = new char[messLength];
00057           clientMess->ReadString(mess,messLength);                  
00058         } 
00059       }
00060       else closeSocket(); 
00061     } 
00062     else closeSocket();
00063   } 
00064   delete clientMess;
00065   clientMess = 0;
00066   string clientString(mess);
00067   delete mess;
00068   mess = 0;
00069 
00070   return clientString;
00071 }

SocketUtils& SocketUtils::operator= ( const SocketUtils su  )  [private]

Member Data Documentation

string SocketUtils::_hostname [private]

Definition at line 48 of file SocketUtils.h.

Referenced by getHostname(), and SocketUtils().

string SocketUtils::_id [private]

Definition at line 49 of file SocketUtils.h.

Referenced by getId(), and SocketUtils().

TMonitor* SocketUtils::_moni [private]

Definition at line 46 of file SocketUtils.h.

Referenced by closeSocket().

TROOT* SocketUtils::_server [private]

Definition at line 45 of file SocketUtils.h.

Referenced by closeSocket().

TSocket* SocketUtils::_socket [private]

Definition at line 47 of file SocketUtils.h.

Referenced by closeSocket(), and getStringMessage().


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

Generated on 2 Nov 2017 for loon by  doxygen 1.6.1