CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Attributes
DTCtcp Class Reference

#include <DTSpyHelper.h>

Inheritance diagram for DTCtcp:
DTSpy

Public Member Functions

DTCtcpAccept ()
 
unsigned long addr ()
 
void Connect (const char *hostaddr, int port)
 
void Connect (unsigned long hostaddr, int port)
 
int Disconnect ()
 
 DTCtcp ()
 
 DTCtcp (int port)
 
 DTCtcp (int sock, int opt)
 
 DTCtcp (DTCtcp *)
 
short Id ()
 
int Receive (char *buffer, int size)
 
int Send (char *buffer, int size)
 
int WaitData (int timeout)
 
 ~DTCtcp ()
 

Protected Attributes

struct sockaddr_in clientAddr
 
int connected
 
struct sockaddr_in myaddr
 
int port
 
int sock
 

Detailed Description

Definition at line 19 of file DTSpyHelper.h.

Constructor & Destructor Documentation

DTCtcp::DTCtcp ( )

Definition at line 15 of file DTSpyHelper.cc.

Referenced by Accept().

16 {
17  DTCtcp(0);
18 }
DTCtcp::DTCtcp ( int  port)

Definition at line 20 of file DTSpyHelper.cc.

References connected, myaddr, port, and sock.

21 {
22 // struct sockaddr_in myaddr;
23 
24  connected=false;
25 
26  printf("zeroing...\n");
27  bzero ((char *) &myaddr, sizeof(myaddr));
28  printf("zeroing done..\n");
29 
30 
31  sock = socket (AF_INET, SOCK_STREAM, 0);
32  printf("create socket..\n");
33 
34  if (sock < 0)
35  {
36  printf("no socket...\n");
37  throw DTtcpExcp(errno);
38  }
39 
40 
41  myaddr.sin_family = AF_INET;
42  myaddr.sin_port = htons (localport);
43 
44  //int blen = 65536;
45  int blen = 65536*8;
46 
47 // printf("setting socket opts buf...\n");
48 // if(setsockopt(sock,SOL_SOCKET,SO_SNDBUF,(char *)&blen,sizeof(blen))<0)
49 // throw DTtcpExcp(errno);
50 // if(setsockopt(sock,SOL_SOCKET,SO_RCVBUF,(char *)&blen,sizeof(blen))<0)
51 // throw DTtcpExcp(errno);
52  printf("setting socket opts reuse...\n");
53  if(setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,(char *)&blen,sizeof(blen))<0)
54  throw DTtcpExcp(errno);
55 // printf("setting socket opts nodelay...\n");
56 // if(setsockopt(sock,SOL_SOCKET,TCP_NODELAY,(char *)&blen,sizeof(blen))<0)
57 // throw;
58  printf("binding...\n");
59 
60  port = localport;
61 
62  if (port)
63  if(bind(sock,(struct sockaddr *)&myaddr,sizeof (myaddr)) < 0)
64  { perror ("bind failed");
65  throw DTtcpExcp(errno);
66  }
67 
68 
69 }
struct sockaddr_in myaddr
Definition: DTSpyHelper.h:28
int sock
Definition: DTSpyHelper.h:24
int connected
Definition: DTSpyHelper.h:26
int port
Definition: DTSpyHelper.h:23
DTCtcp::DTCtcp ( int  sock,
int  opt 
)

Definition at line 71 of file DTSpyHelper.cc.

References connected, port, and sock.

72 {
73 
74  connected = true;
75  port =0;
76 
77  sock = snew;
78 }
int sock
Definition: DTSpyHelper.h:24
int connected
Definition: DTSpyHelper.h:26
int port
Definition: DTSpyHelper.h:23
DTCtcp::DTCtcp ( DTCtcp aconn)

Definition at line 80 of file DTSpyHelper.cc.

References connected, port, and sock.

81 {
82 
83  connected = aconn->connected;
84  port = aconn->port;
85 
86  sock = aconn->sock;
87 }
int sock
Definition: DTSpyHelper.h:24
int connected
Definition: DTSpyHelper.h:26
int port
Definition: DTSpyHelper.h:23
DTCtcp::~DTCtcp ( )

Definition at line 89 of file DTSpyHelper.cc.

References sock.

90 {
91  printf("deleting DTCtcp\n");
92  //if (connected) shutdown(sock,2);
93  shutdown(sock,SHUT_RDWR);
94  close (sock);
95 }
int sock
Definition: DTSpyHelper.h:24

Member Function Documentation

DTCtcp * DTCtcp::Accept ( )

Definition at line 121 of file DTSpyHelper.cc.

References accept(), clientAddr, DTCtcp(), and sock.

122 {
123 
124  // struct sockaddr_in clientAddr; /* client's address */
125 
126  bzero ((char *) &clientAddr, sizeof (clientAddr));
127 
128  if (listen (sock, 2) < 0)
129  {
130  perror ("listen failed");
131  throw DTtcpExcp(errno);
132  }
133 
134  int len = sizeof (clientAddr);
135 
136  int snew = accept (sock, (struct sockaddr *) &clientAddr,(socklen_t *) &len);
137  if (snew <=0)
138  {
139  perror ("accept failed");
140  throw DTtcpExcp(errno);
141  }
142 
143  return new DTCtcp(snew,0);
144 }
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:30
int sock
Definition: DTSpyHelper.h:24
struct sockaddr_in clientAddr
Definition: DTSpyHelper.h:27
unsigned long DTCtcp::addr ( )

Definition at line 106 of file DTSpyHelper.cc.

References clientAddr.

107 {
108  unsigned long maddr = clientAddr.sin_addr.s_addr;
109  maddr = htonl (maddr);
110  return maddr;
111 }
struct sockaddr_in clientAddr
Definition: DTSpyHelper.h:27
void DTCtcp::Connect ( const char *  hostaddr,
int  port 
)

Definition at line 162 of file DTSpyHelper.cc.

References clientAddr, DBConfiguration_cff::connect, connected, and sock.

Referenced by DTSpy::DTSpy(), and DTSpyReader::DTSpyReader().

163 {
164  clientAddr.sin_family = AF_INET;
165  clientAddr.sin_addr.s_addr = inet_addr (host);
166  clientAddr.sin_port = htons (toport);
167 
168  if (connect (sock, (struct sockaddr *)&clientAddr, sizeof (clientAddr)) < 0)
169 {
170  perror ("connect failed");
171  throw DTtcpExcp(errno);
172 }
173  connected = true;
174 }
host
Definition: query.py:114
int sock
Definition: DTSpyHelper.h:24
int connected
Definition: DTSpyHelper.h:26
struct sockaddr_in clientAddr
Definition: DTSpyHelper.h:27
void DTCtcp::Connect ( unsigned long  hostaddr,
int  port 
)

Definition at line 147 of file DTSpyHelper.cc.

References clientAddr, DBConfiguration_cff::connect, connected, and sock.

148 {
149  clientAddr.sin_family = AF_INET;
150  clientAddr.sin_addr.s_addr = htonl (in);
151  clientAddr.sin_port = htons (toport);
152 
153  if (connect (sock, (struct sockaddr *)&clientAddr, sizeof (clientAddr)) < 0)
154 {
155  perror ("connect failed");
156  throw DTtcpExcp(errno);
157 }
158  connected = true;
159 }
int sock
Definition: DTSpyHelper.h:24
int connected
Definition: DTSpyHelper.h:26
struct sockaddr_in clientAddr
Definition: DTSpyHelper.h:27
int DTCtcp::Disconnect ( )

Definition at line 114 of file DTSpyHelper.cc.

References connected, and sock.

115 {
116  connected = false;
117  return shutdown(sock,SHUT_RDWR);
118 }
int sock
Definition: DTSpyHelper.h:24
int connected
Definition: DTSpyHelper.h:26
short DTCtcp::Id ( )

Definition at line 98 of file DTSpyHelper.cc.

References clientAddr.

99 {
100  long maddr = clientAddr.sin_addr.s_addr;
101  maddr = htonl (maddr);
102  return maddr&0xff;
103 }
struct sockaddr_in clientAddr
Definition: DTSpyHelper.h:27
int DTCtcp::Receive ( char *  buffer,
int  size 
)

Definition at line 197 of file DTSpyHelper.cc.

References findQualityFiles::size, and sock.

Referenced by DTSpy::getNextBuffer().

198 {
199 // return read (sock, buffer,size) ;
200 
201  int howmany = 0;
202  int toberead = size;
203  do
204  {
205  //int readnow = recv (sock, &buffer[howmany], toberead,MSG_WAITALL) ;
206  int readnow = recv (sock, &buffer[howmany], toberead,0) ;
207  //if (readnow < 0 ) {printf("some rrorrs...%d\n",errno); return -1;}
208  if (readnow <= 0 )
209  {printf("some rrorrs...%d\n",errno); throw DTtcpExcp(errno);}
210  else {
211  howmany+=readnow; toberead-=readnow;}
212  } while (toberead>0);
213  return howmany;
214 }
size
Write out results.
int sock
Definition: DTSpyHelper.h:24
int DTCtcp::Send ( char *  buffer,
int  size 
)

Definition at line 217 of file DTSpyHelper.cc.

References connected, sock, and TriggerAnalyzer::write().

218 {
219  if (connected==false) throw DTtcpExcp(EPIPE);
220  int myret = write (sock, buffer, size) ;
221  if (myret<0) throw DTtcpExcp(errno);
222  return myret;
223 }
size
Write out results.
int sock
Definition: DTSpyHelper.h:24
int connected
Definition: DTSpyHelper.h:26
def write(self, setup)
int DTCtcp::WaitData ( int  timeout)

Definition at line 177 of file DTSpyHelper.cc.

References TauGenJetsDecayModeSelectorAllHadrons_cfi::select, sock, and mps_check::timeout.

178 {
179 // return read (sock, buffer,size) ;
180  fd_set rfds;
181  struct timeval tv;
182 
183  FD_ZERO(&rfds);
184  FD_SET(sock,&rfds);
185 
186  tv.tv_sec = timeout;
187  tv.tv_usec = 0;
188 
189  int retva = select (1,&rfds,nullptr,&rfds,&tv);
190  if (retva)
191  if (FD_ISSET(0,&rfds)) return 1;
192  else return -1;
193  else return 0;
194 }
int timeout
Definition: mps_check.py:51
int sock
Definition: DTSpyHelper.h:24

Member Data Documentation

struct sockaddr_in DTCtcp::clientAddr
protected

Definition at line 27 of file DTSpyHelper.h.

Referenced by Accept(), addr(), Connect(), and Id().

int DTCtcp::connected
protected

Definition at line 26 of file DTSpyHelper.h.

Referenced by Connect(), Disconnect(), DTCtcp(), DTSpy::getNextBuffer(), and Send().

struct sockaddr_in DTCtcp::myaddr
protected

Definition at line 28 of file DTSpyHelper.h.

Referenced by DTCtcp().

int DTCtcp::port
protected
int DTCtcp::sock
protected

Definition at line 24 of file DTSpyHelper.h.

Referenced by Accept(), Connect(), Disconnect(), DTCtcp(), Receive(), Send(), WaitData(), and ~DTCtcp().