#include <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 port) | |
DTCtcp (int sock, int opt) | |
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 | ( | ) |
DTCtcp::DTCtcp | ( | int | port | ) |
Definition at line 20 of file DTSpyHelper.cc.
References connected, myaddr, port, and sock.
{ // struct sockaddr_in myaddr; connected=false; printf("zeroing...\n"); bzero ((char *) &myaddr, sizeof(myaddr)); printf("zeroing done..\n"); sock = socket (AF_INET, SOCK_STREAM, 0); printf("create socket..\n"); if (sock < 0) { printf("no socket...\n"); throw DTtcpExcp(errno); } myaddr.sin_family = AF_INET; myaddr.sin_port = htons (localport); //int blen = 65536; int blen = 65536*8; // printf("setting socket opts buf...\n"); // if(setsockopt(sock,SOL_SOCKET,SO_SNDBUF,(char *)&blen,sizeof(blen))<0) // throw DTtcpExcp(errno); // if(setsockopt(sock,SOL_SOCKET,SO_RCVBUF,(char *)&blen,sizeof(blen))<0) // throw DTtcpExcp(errno); printf("setting socket opts reuse...\n"); if(setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,(char *)&blen,sizeof(blen))<0) throw DTtcpExcp(errno); // printf("setting socket opts nodelay...\n"); // if(setsockopt(sock,SOL_SOCKET,TCP_NODELAY,(char *)&blen,sizeof(blen))<0) // throw; printf("binding...\n"); port = localport; if (port) if(bind(sock,(struct sockaddr *)&myaddr,sizeof (myaddr)) < 0) { perror ("bind failed"); throw DTtcpExcp(errno); } }
DTCtcp::DTCtcp | ( | int | sock, |
int | opt | ||
) |
DTCtcp::DTCtcp | ( | DTCtcp * | aconn | ) |
DTCtcp::~DTCtcp | ( | ) |
Definition at line 89 of file DTSpyHelper.cc.
References sock.
DTCtcp * DTCtcp::Accept | ( | ) |
Definition at line 121 of file DTSpyHelper.cc.
References accept(), clientAddr, DTCtcp(), and sock.
{ // struct sockaddr_in clientAddr; /* client's address */ bzero ((char *) &clientAddr, sizeof (clientAddr)); if (listen (sock, 2) < 0) { perror ("listen failed"); throw DTtcpExcp(errno); } int len = sizeof (clientAddr); int snew = accept (sock, (struct sockaddr *) &clientAddr,(socklen_t *) &len); if (snew <=0) { perror ("accept failed"); throw DTtcpExcp(errno); } return new DTCtcp(snew,0); }
unsigned long DTCtcp::addr | ( | ) |
Definition at line 106 of file DTSpyHelper.cc.
References clientAddr.
{ unsigned long maddr = clientAddr.sin_addr.s_addr; maddr = htonl (maddr); return maddr; }
void DTCtcp::Connect | ( | const char * | hostaddr, |
int | port | ||
) |
Definition at line 162 of file DTSpyHelper.cc.
References clientAddr, convertSQLitetoXML_cfg::connect, connected, and sock.
Referenced by DTSpy::DTSpy(), and DTSpyReader::DTSpyReader().
{ clientAddr.sin_family = AF_INET; clientAddr.sin_addr.s_addr = inet_addr (host); clientAddr.sin_port = htons (toport); if (connect (sock, (struct sockaddr *)&clientAddr, sizeof (clientAddr)) < 0) { perror ("connect failed"); throw DTtcpExcp(errno); } connected = true; }
void DTCtcp::Connect | ( | unsigned long | hostaddr, |
int | port | ||
) |
Definition at line 147 of file DTSpyHelper.cc.
References clientAddr, convertSQLitetoXML_cfg::connect, connected, and sock.
{ clientAddr.sin_family = AF_INET; clientAddr.sin_addr.s_addr = htonl (in); clientAddr.sin_port = htons (toport); if (connect (sock, (struct sockaddr *)&clientAddr, sizeof (clientAddr)) < 0) { perror ("connect failed"); throw DTtcpExcp(errno); } connected = true; }
int DTCtcp::Disconnect | ( | ) |
short DTCtcp::Id | ( | ) |
Definition at line 98 of file DTSpyHelper.cc.
References clientAddr.
{ long maddr = clientAddr.sin_addr.s_addr; maddr = htonl (maddr); return maddr&0xff; }
int DTCtcp::Receive | ( | char * | buffer, |
int | size | ||
) |
Definition at line 197 of file DTSpyHelper.cc.
References findQualityFiles::size, and sock.
Referenced by DTSpy::getNextBuffer().
{ // return read (sock, buffer,size) ; int howmany = 0; int toberead = size; do { //int readnow = recv (sock, &buffer[howmany], toberead,MSG_WAITALL) ; int readnow = recv (sock, &buffer[howmany], toberead,0) ; //if (readnow < 0 ) {printf("some rrorrs...%d\n",errno); return -1;} if (readnow <= 0 ) {printf("some rrorrs...%d\n",errno); throw DTtcpExcp(errno);} else { howmany+=readnow; toberead-=readnow;} } while (toberead>0); return howmany; }
int DTCtcp::Send | ( | char * | buffer, |
int | size | ||
) |
int DTCtcp::WaitData | ( | int | timeout | ) |
Definition at line 177 of file DTSpyHelper.cc.
References benchmark_cfg::select, and sock.
struct sockaddr_in DTCtcp::clientAddr [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 [protected] |
Definition at line 28 of file DTSpyHelper.h.
Referenced by DTCtcp().
int DTCtcp::port [protected] |
Definition at line 23 of file DTSpyHelper.h.
Referenced by DTCtcp().
int DTCtcp::sock [protected] |
Definition at line 24 of file DTSpyHelper.h.
Referenced by Accept(), Connect(), Disconnect(), DTCtcp(), Receive(), Send(), WaitData(), and ~DTCtcp().