do not push, debug commands involved

This commit is contained in:
Dhanya Maliakal 2015-08-10 13:44:57 +02:00
parent a4a0ea508e
commit 52f83b9249
4 changed files with 79 additions and 21 deletions

View File

@ -60,7 +60,7 @@ class sockaddr_in;
#include <ifaddrs.h>
#endif
#include "ansi.h"
#include <stdlib.h> /******exit */
#include <unistd.h>
@ -71,6 +71,8 @@ class sockaddr_in;
#include <errno.h>
#include <stdio.h>
#include <signal.h> //SIGINT
using namespace std;
#define DEFAULT_PACKET_SIZE 1286
@ -125,6 +127,7 @@ typedef struct
struct hostent *hostInfo = gethostbyname(host_ip_or_name);
if (hostInfo == NULL){
cerr << "Exiting: Problem interpreting host: " << host_ip_or_name << "\n";
cprintf(RED,"Exiting: Problem interpreting host:%s\n",host_ip_or_name);
} else {
// Set some fields in the serverAddress structure.
serverAddress.sin_family = hostInfo->h_addrtype;
@ -134,6 +137,7 @@ typedef struct
socketDescriptor=0; //You can use send and recv, //would it work?????
}
clientAddress_length=sizeof(clientAddress);
cprintf(MAGENTA, "client socket created %d \n",socketDescriptor,protocol);
}
@ -176,6 +180,7 @@ typedef struct
nsent(0),
total_sent(0)
{
signal(SIGCHLD,SIG_IGN);
//memset(&serverAddress, 0, sizeof(sockaddr_in));
// memset(&clientAddress, 0, sizeof(sockaddr_in));
// serverAddress = {0};
@ -205,9 +210,12 @@ typedef struct
socketDescriptor = socket(AF_INET, getProtocol(),0); //tcp
cprintf(MAGENTA, "socket created %d protocol:%d\n",socketDescriptor,protocol);
if (socketDescriptor < 0) {
cerr << "Can not create socket "<<endl;
cprintf(RED,"Can not create socket \n");
return;
}
@ -229,6 +237,7 @@ typedef struct
int val=1;
if (setsockopt(socketDescriptor,SOL_SOCKET,SO_REUSEADDR,&val,sizeof(int)) == -1) {
cerr << "setsockopt" << endl;
cprintf(RED,"setsockopt \n");
socketDescriptor=-1;
return;
}
@ -239,6 +248,7 @@ typedef struct
if((p == UDP) && (setsockopt(socketDescriptor, SOL_SOCKET, SO_RCVBUF, &val, sizeof(int)) == -1))
{
cerr << "WARNING:Could not set socket receive buffer size" << endl;
cprintf(RED,"WARNING:Could not set socket receive buffer size \n");
//socketDescriptor=-1;
//return;
}
@ -247,6 +257,7 @@ typedef struct
if(bind(socketDescriptor,(struct sockaddr *) &serverAddress,sizeof(serverAddress))<0){
cerr << "Can not bind socket "<< endl;
cprintf(RED,"Can not bind socket \n");
socketDescriptor=-1;
return;
}
@ -330,6 +341,7 @@ typedef struct
if (socketDescriptor>0) {
if ((file_des = accept(socketDescriptor,(struct sockaddr *) &clientAddress, &clientAddress_length)) < 0) {
cerr << "Error: with server accept, connection refused"<<endl;
cprintf(RED,"Error: with server accept, connection refused");
switch(errno) {
case EWOULDBLOCK:
printf("ewouldblock eagain\n");
@ -377,12 +389,15 @@ typedef struct
printf("unknown error\n");
}
socketDescriptor=-1;
cprintf(RED, "file des NOT connected %d \n",file_des);
}
else{
inet_ntop(AF_INET, &(clientAddress.sin_addr), dummyClientIP, INET_ADDRSTRLEN);
#ifdef VERY_VERBOSE
cout << "client connected "<< file_des << endl;
#endif
cprintf(MAGENTA, "file des connected %d \n",file_des);
}
}
@ -397,14 +412,17 @@ typedef struct
// SetTimeOut(10);
if (socketDescriptor < 0){
cerr << "Can not create socket "<<endl;
cprintf(RED, "Can not create socket in accept\n");
file_des = socketDescriptor;
} else {
if(connect(socketDescriptor,(struct sockaddr *) &serverAddress,sizeof(serverAddress))<0){
cerr << "Can not connect to socket "<<endl;
cprintf(RED, "Can not connect socket in accept\n");
file_des = -1;
} else{
file_des = socketDescriptor;
cprintf(MAGENTA, "file des connected %d \n",file_des);
}
}
@ -427,24 +445,44 @@ typedef struct
socketDescriptor=-1;
}
else{
/*
close(socketDescriptor);
socketDescriptor=-1;
if(is_a_server){
if(file_des>=0){
close(file_des);
file_des=-1;
}
}
*/
if(file_des>=0){ //then was open
if(is_a_server){
close(file_des);
// cprintf(MAGENTA, "file_des disconnected %d \n",file_des);
if(close(file_des))
cprintf(RED,"file_des not disconnected %d\n", file_des);
// cprintf(MAGENTA, "file_des disconnected %d \n",file_des);
}
else {
close(socketDescriptor);
//cprintf(MAGENTA, "socketDescriptor disconnected %d \n",socketDescriptor);
if(close(socketDescriptor))
cprintf(RED,"socketDescriptor not disconnected %d\n", file_des);
// cprintf(MAGENTA, "socketDescriptor disconnected %d \n",socketDescriptor);
socketDescriptor=-1;
}
file_des=-1;
}
}
};
void ShutDownSocket(){
while(!shutdown(socketDescriptor, SHUT_RDWR));
close(socketDescriptor);
socketDescriptor = -1;
while(!shutdown(socketDescriptor, SHUT_RDWR));
Disconnect();
};

View File

@ -745,15 +745,19 @@ int UDPBaseImplementation::createUDPSockets(){ FILE_LOG(logDEBUG) << __AT__ << "
if(!strlen(eth)){
cout<<"warning:eth is empty.listening to all"<<endl;
for(int i=0;i<numListeningThreads;i++)
for(int i=0;i<numListeningThreads;i++){
cprintf(RED, "gonna try listening to all\n");
udpSocket[i] = new genericSocket(server_port[i],genericSocket::UDP,bufferSize);
}
}
//normal socket
else{
cout<<"eth:"<<eth<<endl;
for(int i=0;i<numListeningThreads;i++)
for(int i=0;i<numListeningThreads;i++){
cprintf(RED, "gonna try listening to all\n");
udpSocket[i] = new genericSocket(server_port[i],genericSocket::UDP,bufferSize,eth);
}
}
//error

View File

@ -80,6 +80,7 @@ UDPStandardImplementation::UDPStandardImplementation()
cout << "\nWARNING: Could not change socket receiver buffer size in file /proc/sys/net/core/rmem_max" << endl;
else if(system("echo 250000 > /proc/sys/net/core/netdev_max_backlog"))
cout << "\nWARNING: Could not change max length of input queue in file /proc/sys/net/core/netdev_max_backlog" << endl;
/** permanent setting heiner
net.core.rmem_max = 104857600 # 100MiB
net.core.netdev_max_backlog = 250000
@ -1056,24 +1057,29 @@ int UDPStandardImplementation::createUDPSockets(){
if(!strlen(eth)){
cout<<"warning:eth is empty.listening to all"<<endl;
for(int i=0;i<numListeningThreads;i++)
for(int i=0;i<numListeningThreads;i++){
cprintf(YELLOW, "gonna try listening to all\n");
udpSocket[i] = new genericSocket(port[i],genericSocket::UDP,bufferSize);
}
}
//normal socket
else{
cout<<"eth:"<<eth<<endl;
for(int i=0;i<numListeningThreads;i++)
for(int i=0;i<numListeningThreads;i++){
cprintf(YELLOW, "gonna try focussed\n");
udpSocket[i] = new genericSocket(port[i],genericSocket::UDP,bufferSize,eth);
}
}
//error
int iret;
for(int i=0;i<numListeningThreads;i++){
iret = udpSocket[i]->getErrorStatus();
if(!iret)
if(!iret){
cout << "UDP port opened at port " << port[i] << endl;
else{
cprintf(YELLOW, "socket of port %d descriptor:%d\n",i,udpSocket[i]->getsocketDescriptor());
}else{
#ifdef VERBOSE
cprintf(BG_RED,"Could not create UDP socket on port %d error: %d\n", port[i], iret);
#endif
@ -1082,6 +1088,8 @@ int UDPStandardImplementation::createUDPSockets(){
}
}
return OK;
}
@ -1276,7 +1284,7 @@ int UDPStandardImplementation::setupWriter(){
packetsInFile=0;
packetsCaught=0;
frameIndex=0;
if(sfilefd) sfilefd=NULL;
if(sfilefd) {cprintf(RED,"**FILE not closed!\n");fclose(sfilefd);sfilefd=NULL;}
guiData = NULL;
guiDataReady=0;
strcpy(guiFileName,"");
@ -1402,9 +1410,13 @@ int UDPStandardImplementation::createNewFile(){
if(enableFileWrite && cbAction > DO_NOTHING){
//close
if(sfilefd){
fclose(sfilefd);
if(fclose(sfilefd)){
cprintf(YELLOW, "file clsoe problem %d\n",fileno(sfilefd));
fclose(sfilefd);
}
sfilefd = NULL;
}
//open file
if(!overwrite){
if (NULL == (sfilefd = fopen((const char *) (savefilename), "wx"))){
@ -1418,6 +1430,9 @@ int UDPStandardImplementation::createNewFile(){
//setting buffer
setvbuf(sfilefd,NULL,_IOFBF,BUF_SIZE);
cprintf(YELLOW, "file value:%d\n",fileno(sfilefd));
//cprintf(YELLOW, "file valuex:%d",(int)sfilefd);
//printing packet losses and file names
if(!packetsCaught)
cout << savefilename << endl;
@ -1459,10 +1474,12 @@ void UDPStandardImplementation::closeFile(int ithr){
if(!dataCompression){
if(sfilefd){
#ifdef VERBOSE
cout << "sfield:" << (int)sfilefd << endl;
#endif
fclose(sfilefd);
//#ifdef VERBOSE
cprintf(YELLOW, "gonna close file:%d\n",fileno(sfilefd));
//#endif
if(fclose(sfilefd))
perror("close ERRROR");
cprintf(YELLOW, "check close file:%d\n",fileno(sfilefd));
sfilefd = NULL;
}
}
@ -1473,7 +1490,8 @@ void UDPStandardImplementation::closeFile(int ithr){
#ifdef VERBOSE
cout << "sfield:" << (int)sfilefd << endl;
#endif
fclose(sfilefd);
if(fclose(sfilefd))
perror("close ERRROR");
sfilefd = NULL;
}
#endif
@ -1612,7 +1630,6 @@ int UDPStandardImplementation::stopReceiver(){
}else cout <<" Not idle to stop receiver" << endl;
//sem_post(&smp);
return OK;

View File

@ -65,7 +65,6 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, UDPInterface*
strcpy(socket->lastClientIP,"none");
strcpy(socket->thisClientIP,"none1");
strcpy(mess,"dummy message");
function_table();
#ifdef VERBOSE
cout << "Function table assigned." << endl;