#include <IORawData/DTCommissioning/src/DTSpyHelper.h>
Public Member Functions | |
DTCtcp * | Accept () |
unsigned long | addr () |
void | Connect (unsigned long hostaddr, int port) |
void | Connect (const char *hostaddr, int port) |
int | Disconnect () |
DTCtcp (DTCtcp *) | |
DTCtcp (int sock, int opt) | |
DTCtcp (int port) | |
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 |
Definition at line 19 of file DTSpyHelper.h.
DTCtcp::DTCtcp | ( | ) |
Definition at line 15 of file DTSpyHelper.cc.
Referenced by Accept().
00016 { 00017 DTCtcp(0); 00018 }
DTCtcp::DTCtcp | ( | int | port | ) |
Definition at line 20 of file DTSpyHelper.cc.
References connected, myaddr, port, sock, and socket.
00021 { 00022 // struct sockaddr_in myaddr; 00023 00024 connected=false; 00025 00026 printf("zeroing...\n"); 00027 bzero ((char *) &myaddr, sizeof(myaddr)); 00028 printf("zeroing done..\n"); 00029 00030 00031 sock = socket (AF_INET, SOCK_STREAM, 0); 00032 printf("create socket..\n"); 00033 00034 if (sock < 0) 00035 { 00036 printf("no socket...\n"); 00037 throw DTtcpExcp(errno); 00038 } 00039 00040 00041 myaddr.sin_family = AF_INET; 00042 myaddr.sin_port = htons (localport); 00043 00044 //int blen = 65536; 00045 int blen = 65536*8; 00046 00047 // printf("setting socket opts buf...\n"); 00048 // if(setsockopt(sock,SOL_SOCKET,SO_SNDBUF,(char *)&blen,sizeof(blen))<0) 00049 // throw DTtcpExcp(errno); 00050 // if(setsockopt(sock,SOL_SOCKET,SO_RCVBUF,(char *)&blen,sizeof(blen))<0) 00051 // throw DTtcpExcp(errno); 00052 printf("setting socket opts reuse...\n"); 00053 if(setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,(char *)&blen,sizeof(blen))<0) 00054 throw DTtcpExcp(errno); 00055 // printf("setting socket opts nodelay...\n"); 00056 // if(setsockopt(sock,SOL_SOCKET,TCP_NODELAY,(char *)&blen,sizeof(blen))<0) 00057 // throw; 00058 printf("binding...\n"); 00059 00060 port = localport; 00061 00062 if (port) 00063 if(bind(sock,(struct sockaddr *)&myaddr,sizeof (myaddr)) < 0) 00064 { perror ("bind failed"); 00065 throw DTtcpExcp(errno); 00066 } 00067 00068 00069 }
DTCtcp::DTCtcp | ( | DTCtcp * | aconn | ) |
DTCtcp::~DTCtcp | ( | ) |
Definition at line 89 of file DTSpyHelper.cc.
References sock.
00090 { 00091 printf("deleting DTCtcp\n"); 00092 //if (connected) shutdown(sock,2); 00093 shutdown(sock,SHUT_RDWR); 00094 close (sock); 00095 }
DTCtcp * DTCtcp::Accept | ( | ) |
Definition at line 121 of file DTSpyHelper.cc.
References clientAddr, DTCtcp(), len, and sock.
00122 { 00123 00124 // struct sockaddr_in clientAddr; /* client's address */ 00125 00126 bzero ((char *) &clientAddr, sizeof (clientAddr)); 00127 00128 if (listen (sock, 2) < 0) 00129 { 00130 perror ("listen failed"); 00131 throw DTtcpExcp(errno); 00132 } 00133 00134 int len = sizeof (clientAddr); 00135 00136 int snew = accept (sock, (struct sockaddr *) &clientAddr,(socklen_t *) &len); 00137 if (snew <=0) 00138 { 00139 perror ("accept failed"); 00140 throw DTtcpExcp(errno); 00141 } 00142 00143 return new DTCtcp(snew,0); 00144 }
unsigned long DTCtcp::addr | ( | ) |
Definition at line 106 of file DTSpyHelper.cc.
References clientAddr.
00107 { 00108 unsigned long maddr = clientAddr.sin_addr.s_addr; 00109 maddr = htonl (maddr); 00110 return maddr; 00111 }
Definition at line 147 of file DTSpyHelper.cc.
References clientAddr, HLT_VtxMuL3::connect, connected, and sock.
00148 { 00149 clientAddr.sin_family = AF_INET; 00150 clientAddr.sin_addr.s_addr = htonl (in); 00151 clientAddr.sin_port = htons (toport); 00152 00153 if (connect (sock, (struct sockaddr *)&clientAddr, sizeof (clientAddr)) < 0) 00154 { 00155 perror ("connect failed"); 00156 throw DTtcpExcp(errno); 00157 } 00158 connected = true; 00159 }
Definition at line 162 of file DTSpyHelper.cc.
References clientAddr, HLT_VtxMuL3::connect, connected, and sock.
Referenced by DTSpy::DTSpy(), and DTSpyReader::DTSpyReader().
00163 { 00164 clientAddr.sin_family = AF_INET; 00165 clientAddr.sin_addr.s_addr = inet_addr (host); 00166 clientAddr.sin_port = htons (toport); 00167 00168 if (connect (sock, (struct sockaddr *)&clientAddr, sizeof (clientAddr)) < 0) 00169 { 00170 perror ("connect failed"); 00171 throw DTtcpExcp(errno); 00172 } 00173 connected = true; 00174 }
int DTCtcp::Disconnect | ( | ) |
short DTCtcp::Id | ( | ) |
Definition at line 98 of file DTSpyHelper.cc.
References clientAddr.
00099 { 00100 long maddr = clientAddr.sin_addr.s_addr; 00101 maddr = htonl (maddr); 00102 return maddr&0xff; 00103 }
Definition at line 197 of file DTSpyHelper.cc.
References sock.
Referenced by DTSpy::getNextBuffer().
00198 { 00199 // return read (sock, buffer,size) ; 00200 00201 int howmany = 0; 00202 int toberead = size; 00203 do 00204 { 00205 //int readnow = recv (sock, &buffer[howmany], toberead,MSG_WAITALL) ; 00206 int readnow = recv (sock, &buffer[howmany], toberead,0) ; 00207 //if (readnow < 0 ) {printf("some rrorrs...%d\n",errno); return -1;} 00208 if (readnow <= 0 ) 00209 {printf("some rrorrs...%d\n",errno); throw DTtcpExcp(errno);} 00210 else { 00211 howmany+=readnow; toberead-=readnow;} 00212 } while (toberead>0); 00213 return howmany; 00214 }
Definition at line 177 of file DTSpyHelper.cc.
References dummy::select(), and sock.
00178 { 00179 // return read (sock, buffer,size) ; 00180 fd_set rfds; 00181 struct timeval tv; 00182 00183 FD_ZERO(&rfds); 00184 FD_SET(sock,&rfds); 00185 00186 tv.tv_sec = timeout; 00187 tv.tv_usec = 0; 00188 00189 int retva = select (1,&rfds,0,&rfds,&tv); 00190 if (retva) 00191 if (FD_ISSET(0,&rfds)) return 1; 00192 else return -1; 00193 else return 0; 00194 }
struct sockaddr_in DTCtcp::clientAddr [read, protected] |
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 [read, protected] |
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().