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 (DTCtcp *)
 
 DTCtcp (int port)
 
 DTCtcp (int sock, int opt)
 
short Id ()
 
int Receive (char *buffer, int size)
 
int Send (char *buffer, int size)
 
 ~DTCtcp ()
 

Protected Attributes

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

Detailed Description

Definition at line 18 of file DTSpyHelper.h.

Constructor & Destructor Documentation

◆ DTCtcp() [1/4]

DTCtcp::DTCtcp ( )

Definition at line 15 of file DTSpyHelper.cc.

15 { DTCtcp(0); }

Referenced by Accept().

◆ DTCtcp() [2/4]

DTCtcp::DTCtcp ( int  port)

Definition at line 17 of file DTSpyHelper.cc.

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

References connected, myaddr, port, and sock.

◆ DTCtcp() [3/4]

DTCtcp::DTCtcp ( int  sock,
int  opt 
)

Definition at line 62 of file DTSpyHelper.cc.

62  {
63  connected = true;
64  port = 0;
65 
66  sock = snew;
67 }

References connected, port, and sock.

◆ DTCtcp() [4/4]

DTCtcp::DTCtcp ( DTCtcp aconn)

Definition at line 69 of file DTSpyHelper.cc.

69  {
70  connected = aconn->connected;
71  port = aconn->port;
72 
73  sock = aconn->sock;
74 }

References connected, port, and sock.

◆ ~DTCtcp()

DTCtcp::~DTCtcp ( )

Definition at line 76 of file DTSpyHelper.cc.

76  {
77  printf("deleting DTCtcp\n");
78  //if (connected) shutdown(sock,2);
79  shutdown(sock, SHUT_RDWR);
80  close(sock);
81 }

References sock.

Member Function Documentation

◆ Accept()

DTCtcp * DTCtcp::Accept ( )

Definition at line 100 of file DTSpyHelper.cc.

100  {
101  // struct sockaddr_in clientAddr; /* client's address */
102 
103  bzero((char *)&clientAddr, sizeof(clientAddr));
104 
105  if (listen(sock, 2) < 0) {
106  perror("listen failed");
107  throw DTtcpExcp(errno);
108  }
109 
110  int len = sizeof(clientAddr);
111 
112  int snew = accept(sock, (struct sockaddr *)&clientAddr, (socklen_t *)&len);
113  if (snew <= 0) {
114  perror("accept failed");
115  throw DTtcpExcp(errno);
116  }
117 
118  return new DTCtcp(snew, 0);
119 }

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

◆ addr()

unsigned long DTCtcp::addr ( )

Definition at line 89 of file DTSpyHelper.cc.

89  {
90  unsigned long maddr = clientAddr.sin_addr.s_addr;
91  maddr = htonl(maddr);
92  return maddr;
93 }

References clientAddr.

◆ Connect() [1/2]

void DTCtcp::Connect ( const char *  hostaddr,
int  port 
)

Definition at line 133 of file DTSpyHelper.cc.

133  {
134  clientAddr.sin_family = AF_INET;
135  clientAddr.sin_addr.s_addr = inet_addr(host);
136  clientAddr.sin_port = htons(toport);
137 
138  if (connect(sock, (struct sockaddr *)&clientAddr, sizeof(clientAddr)) < 0) {
139  perror("connect failed");
140  throw DTtcpExcp(errno);
141  }
142  connected = true;
143 }

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

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

◆ Connect() [2/2]

void DTCtcp::Connect ( unsigned long  hostaddr,
int  port 
)

Definition at line 121 of file DTSpyHelper.cc.

121  {
122  clientAddr.sin_family = AF_INET;
123  clientAddr.sin_addr.s_addr = htonl(in);
124  clientAddr.sin_port = htons(toport);
125 
126  if (connect(sock, (struct sockaddr *)&clientAddr, sizeof(clientAddr)) < 0) {
127  perror("connect failed");
128  throw DTtcpExcp(errno);
129  }
130  connected = true;
131 }

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

◆ Disconnect()

int DTCtcp::Disconnect ( )

Definition at line 95 of file DTSpyHelper.cc.

95  {
96  connected = false;
97  return shutdown(sock, SHUT_RDWR);
98 }

References connected, and sock.

◆ Id()

short DTCtcp::Id ( )

Definition at line 83 of file DTSpyHelper.cc.

83  {
84  long maddr = clientAddr.sin_addr.s_addr;
85  maddr = htonl(maddr);
86  return maddr & 0xff;
87 }

References clientAddr.

◆ Receive()

int DTCtcp::Receive ( char *  buffer,
int  size 
)

Definition at line 145 of file DTSpyHelper.cc.

145  {
146  // return read (sock, buffer,size) ;
147 
148  int howmany = 0;
149  int toberead = size;
150  do {
151  //int readnow = recv (sock, &buffer[howmany], toberead,MSG_WAITALL) ;
152  int readnow = recv(sock, &buffer[howmany], toberead, 0);
153  //if (readnow < 0 ) {printf("some rrorrs...%d\n",errno); return -1;}
154  if (readnow <= 0) {
155  printf("some rrorrs...%d\n", errno);
156  throw DTtcpExcp(errno);
157  } else {
158  howmany += readnow;
159  toberead -= readnow;
160  }
161  } while (toberead > 0);
162  return howmany;
163 }

References edmScanValgrind::buffer, findQualityFiles::size, and sock.

Referenced by DTSpy::getNextBuffer().

◆ Send()

int DTCtcp::Send ( char *  buffer,
int  size 
)

Definition at line 165 of file DTSpyHelper.cc.

165  {
166  if (connected == false)
167  throw DTtcpExcp(EPIPE);
168  int myret = write(sock, buffer, size);
169  if (myret < 0)
170  throw DTtcpExcp(errno);
171  return myret;
172 }

References edmScanValgrind::buffer, connected, findQualityFiles::size, sock, and writeEcalDQMStatus::write.

Member Data Documentation

◆ clientAddr

struct sockaddr_in DTCtcp::clientAddr
protected

Definition at line 24 of file DTSpyHelper.h.

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

◆ connected

int DTCtcp::connected
protected

Definition at line 23 of file DTSpyHelper.h.

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

◆ myaddr

struct sockaddr_in DTCtcp::myaddr
protected

Definition at line 25 of file DTSpyHelper.h.

Referenced by DTCtcp().

◆ port

int DTCtcp::port
protected

Definition at line 20 of file DTSpyHelper.h.

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

◆ sock

int DTCtcp::sock
protected

Definition at line 21 of file DTSpyHelper.h.

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

DTCtcp::port
int port
Definition: DTSpyHelper.h:20
query.host
string host
Definition: query.py:115
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
accept
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:30
DTCtcp::myaddr
struct sockaddr_in myaddr
Definition: DTSpyHelper.h:25
DTCtcp::clientAddr
struct sockaddr_in clientAddr
Definition: DTSpyHelper.h:24
DTtcpExcp
Definition: DTSpyHelper.h:11
recoMuon::in
Definition: RecoMuonEnumerators.h:6
DBConfiguration_cff.connect
connect
Definition: DBConfiguration_cff.py:18
writeEcalDQMStatus.write
write
Definition: writeEcalDQMStatus.py:48
DTCtcp::connected
int connected
Definition: DTSpyHelper.h:23
DTCtcp::sock
int sock
Definition: DTSpyHelper.h:21
DTCtcp::DTCtcp
DTCtcp()
Definition: DTSpyHelper.cc:15
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443