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)
 
 ~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::DTCtcp ( )

Definition at line 15 of file DTSpyHelper.cc.

Referenced by Accept().

15 { DTCtcp(0); }
DTCtcp::DTCtcp ( int  port)

Definition at line 17 of file DTSpyHelper.cc.

References connected, myaddr, port, and sock.

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 }
struct sockaddr_in myaddr
Definition: DTSpyHelper.h:25
int sock
Definition: DTSpyHelper.h:21
int connected
Definition: DTSpyHelper.h:23
int port
Definition: DTSpyHelper.h:20
DTCtcp::DTCtcp ( int  sock,
int  opt 
)

Definition at line 62 of file DTSpyHelper.cc.

References connected, port, and sock.

62  {
63  connected = true;
64  port = 0;
65 
66  sock = snew;
67 }
int sock
Definition: DTSpyHelper.h:21
int connected
Definition: DTSpyHelper.h:23
int port
Definition: DTSpyHelper.h:20
DTCtcp::DTCtcp ( DTCtcp aconn)

Definition at line 69 of file DTSpyHelper.cc.

References connected, port, and sock.

69  {
70  connected = aconn->connected;
71  port = aconn->port;
72 
73  sock = aconn->sock;
74 }
int sock
Definition: DTSpyHelper.h:21
int connected
Definition: DTSpyHelper.h:23
int port
Definition: DTSpyHelper.h:20
DTCtcp::~DTCtcp ( )

Definition at line 76 of file DTSpyHelper.cc.

References sock.

76  {
77  printf("deleting DTCtcp\n");
78  //if (connected) shutdown(sock,2);
79  shutdown(sock, SHUT_RDWR);
80  close(sock);
81 }
int sock
Definition: DTSpyHelper.h:21

Member Function Documentation

DTCtcp * DTCtcp::Accept ( )

Definition at line 100 of file DTSpyHelper.cc.

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

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 }
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:30
int sock
Definition: DTSpyHelper.h:21
struct sockaddr_in clientAddr
Definition: DTSpyHelper.h:24
unsigned long DTCtcp::addr ( )

Definition at line 89 of file DTSpyHelper.cc.

References clientAddr.

89  {
90  unsigned long maddr = clientAddr.sin_addr.s_addr;
91  maddr = htonl(maddr);
92  return maddr;
93 }
struct sockaddr_in clientAddr
Definition: DTSpyHelper.h:24
void DTCtcp::Connect ( const char *  hostaddr,
int  port 
)

Definition at line 133 of file DTSpyHelper.cc.

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

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

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 }
host
Definition: query.py:115
int sock
Definition: DTSpyHelper.h:21
int connected
Definition: DTSpyHelper.h:23
struct sockaddr_in clientAddr
Definition: DTSpyHelper.h:24
void DTCtcp::Connect ( unsigned long  hostaddr,
int  port 
)

Definition at line 121 of file DTSpyHelper.cc.

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

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 }
int sock
Definition: DTSpyHelper.h:21
int connected
Definition: DTSpyHelper.h:23
struct sockaddr_in clientAddr
Definition: DTSpyHelper.h:24
int DTCtcp::Disconnect ( )

Definition at line 95 of file DTSpyHelper.cc.

References connected, and sock.

95  {
96  connected = false;
97  return shutdown(sock, SHUT_RDWR);
98 }
int sock
Definition: DTSpyHelper.h:21
int connected
Definition: DTSpyHelper.h:23
short DTCtcp::Id ( )

Definition at line 83 of file DTSpyHelper.cc.

References clientAddr.

83  {
84  long maddr = clientAddr.sin_addr.s_addr;
85  maddr = htonl(maddr);
86  return maddr & 0xff;
87 }
struct sockaddr_in clientAddr
Definition: DTSpyHelper.h:24
int DTCtcp::Receive ( char *  buffer,
int  size 
)

Definition at line 145 of file DTSpyHelper.cc.

References findQualityFiles::size, and sock.

Referenced by DTSpy::getNextBuffer().

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 }
size
Write out results.
int sock
Definition: DTSpyHelper.h:21
int DTCtcp::Send ( char *  buffer,
int  size 
)

Definition at line 165 of file DTSpyHelper.cc.

References connected, sock, and writeEcalDQMStatus::write.

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 }
size
Write out results.
int sock
Definition: DTSpyHelper.h:21
int connected
Definition: DTSpyHelper.h:23

Member Data Documentation

struct sockaddr_in DTCtcp::clientAddr
protected

Definition at line 24 of file DTSpyHelper.h.

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

int DTCtcp::connected
protected

Definition at line 23 of file DTSpyHelper.h.

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

struct sockaddr_in DTCtcp::myaddr
protected

Definition at line 25 of file DTSpyHelper.h.

Referenced by DTCtcp().

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

Definition at line 21 of file DTSpyHelper.h.

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