mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-13 13:27:14 +02:00
do not push, debug commands involved
This commit is contained in:
@ -60,7 +60,7 @@ class sockaddr_in;
|
|||||||
#include <ifaddrs.h>
|
#include <ifaddrs.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
#include "ansi.h"
|
||||||
#include <stdlib.h> /******exit */
|
#include <stdlib.h> /******exit */
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -71,6 +71,8 @@ class sockaddr_in;
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <signal.h> //SIGINT
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#define DEFAULT_PACKET_SIZE 1286
|
#define DEFAULT_PACKET_SIZE 1286
|
||||||
@ -125,6 +127,7 @@ typedef struct
|
|||||||
struct hostent *hostInfo = gethostbyname(host_ip_or_name);
|
struct hostent *hostInfo = gethostbyname(host_ip_or_name);
|
||||||
if (hostInfo == NULL){
|
if (hostInfo == NULL){
|
||||||
cerr << "Exiting: Problem interpreting host: " << host_ip_or_name << "\n";
|
cerr << "Exiting: Problem interpreting host: " << host_ip_or_name << "\n";
|
||||||
|
cprintf(RED,"Exiting: Problem interpreting host:%s\n",host_ip_or_name);
|
||||||
} else {
|
} else {
|
||||||
// Set some fields in the serverAddress structure.
|
// Set some fields in the serverAddress structure.
|
||||||
serverAddress.sin_family = hostInfo->h_addrtype;
|
serverAddress.sin_family = hostInfo->h_addrtype;
|
||||||
@ -134,6 +137,7 @@ typedef struct
|
|||||||
socketDescriptor=0; //You can use send and recv, //would it work?????
|
socketDescriptor=0; //You can use send and recv, //would it work?????
|
||||||
}
|
}
|
||||||
clientAddress_length=sizeof(clientAddress);
|
clientAddress_length=sizeof(clientAddress);
|
||||||
|
cprintf(MAGENTA, "client socket created %d \n",socketDescriptor,protocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -176,6 +180,7 @@ typedef struct
|
|||||||
nsent(0),
|
nsent(0),
|
||||||
total_sent(0)
|
total_sent(0)
|
||||||
{
|
{
|
||||||
|
signal(SIGCHLD,SIG_IGN);
|
||||||
//memset(&serverAddress, 0, sizeof(sockaddr_in));
|
//memset(&serverAddress, 0, sizeof(sockaddr_in));
|
||||||
// memset(&clientAddress, 0, sizeof(sockaddr_in));
|
// memset(&clientAddress, 0, sizeof(sockaddr_in));
|
||||||
// serverAddress = {0};
|
// serverAddress = {0};
|
||||||
@ -205,9 +210,12 @@ typedef struct
|
|||||||
|
|
||||||
|
|
||||||
socketDescriptor = socket(AF_INET, getProtocol(),0); //tcp
|
socketDescriptor = socket(AF_INET, getProtocol(),0); //tcp
|
||||||
|
cprintf(MAGENTA, "socket created %d protocol:%d\n",socketDescriptor,protocol);
|
||||||
|
|
||||||
|
|
||||||
if (socketDescriptor < 0) {
|
if (socketDescriptor < 0) {
|
||||||
cerr << "Can not create socket "<<endl;
|
cerr << "Can not create socket "<<endl;
|
||||||
|
cprintf(RED,"Can not create socket \n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,6 +237,7 @@ typedef struct
|
|||||||
int val=1;
|
int val=1;
|
||||||
if (setsockopt(socketDescriptor,SOL_SOCKET,SO_REUSEADDR,&val,sizeof(int)) == -1) {
|
if (setsockopt(socketDescriptor,SOL_SOCKET,SO_REUSEADDR,&val,sizeof(int)) == -1) {
|
||||||
cerr << "setsockopt" << endl;
|
cerr << "setsockopt" << endl;
|
||||||
|
cprintf(RED,"setsockopt \n");
|
||||||
socketDescriptor=-1;
|
socketDescriptor=-1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -239,6 +248,7 @@ typedef struct
|
|||||||
if((p == UDP) && (setsockopt(socketDescriptor, SOL_SOCKET, SO_RCVBUF, &val, sizeof(int)) == -1))
|
if((p == UDP) && (setsockopt(socketDescriptor, SOL_SOCKET, SO_RCVBUF, &val, sizeof(int)) == -1))
|
||||||
{
|
{
|
||||||
cerr << "WARNING:Could not set socket receive buffer size" << endl;
|
cerr << "WARNING:Could not set socket receive buffer size" << endl;
|
||||||
|
cprintf(RED,"WARNING:Could not set socket receive buffer size \n");
|
||||||
//socketDescriptor=-1;
|
//socketDescriptor=-1;
|
||||||
//return;
|
//return;
|
||||||
}
|
}
|
||||||
@ -247,6 +257,7 @@ typedef struct
|
|||||||
|
|
||||||
if(bind(socketDescriptor,(struct sockaddr *) &serverAddress,sizeof(serverAddress))<0){
|
if(bind(socketDescriptor,(struct sockaddr *) &serverAddress,sizeof(serverAddress))<0){
|
||||||
cerr << "Can not bind socket "<< endl;
|
cerr << "Can not bind socket "<< endl;
|
||||||
|
cprintf(RED,"Can not bind socket \n");
|
||||||
socketDescriptor=-1;
|
socketDescriptor=-1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -330,6 +341,7 @@ typedef struct
|
|||||||
if (socketDescriptor>0) {
|
if (socketDescriptor>0) {
|
||||||
if ((file_des = accept(socketDescriptor,(struct sockaddr *) &clientAddress, &clientAddress_length)) < 0) {
|
if ((file_des = accept(socketDescriptor,(struct sockaddr *) &clientAddress, &clientAddress_length)) < 0) {
|
||||||
cerr << "Error: with server accept, connection refused"<<endl;
|
cerr << "Error: with server accept, connection refused"<<endl;
|
||||||
|
cprintf(RED,"Error: with server accept, connection refused");
|
||||||
switch(errno) {
|
switch(errno) {
|
||||||
case EWOULDBLOCK:
|
case EWOULDBLOCK:
|
||||||
printf("ewouldblock eagain\n");
|
printf("ewouldblock eagain\n");
|
||||||
@ -377,12 +389,15 @@ typedef struct
|
|||||||
printf("unknown error\n");
|
printf("unknown error\n");
|
||||||
}
|
}
|
||||||
socketDescriptor=-1;
|
socketDescriptor=-1;
|
||||||
|
cprintf(RED, "file des NOT connected %d \n",file_des);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
inet_ntop(AF_INET, &(clientAddress.sin_addr), dummyClientIP, INET_ADDRSTRLEN);
|
inet_ntop(AF_INET, &(clientAddress.sin_addr), dummyClientIP, INET_ADDRSTRLEN);
|
||||||
#ifdef VERY_VERBOSE
|
#ifdef VERY_VERBOSE
|
||||||
cout << "client connected "<< file_des << endl;
|
cout << "client connected "<< file_des << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
cprintf(MAGENTA, "file des connected %d \n",file_des);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -397,14 +412,17 @@ typedef struct
|
|||||||
// SetTimeOut(10);
|
// SetTimeOut(10);
|
||||||
if (socketDescriptor < 0){
|
if (socketDescriptor < 0){
|
||||||
cerr << "Can not create socket "<<endl;
|
cerr << "Can not create socket "<<endl;
|
||||||
|
cprintf(RED, "Can not create socket in accept\n");
|
||||||
file_des = socketDescriptor;
|
file_des = socketDescriptor;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if(connect(socketDescriptor,(struct sockaddr *) &serverAddress,sizeof(serverAddress))<0){
|
if(connect(socketDescriptor,(struct sockaddr *) &serverAddress,sizeof(serverAddress))<0){
|
||||||
cerr << "Can not connect to socket "<<endl;
|
cerr << "Can not connect to socket "<<endl;
|
||||||
|
cprintf(RED, "Can not connect socket in accept\n");
|
||||||
file_des = -1;
|
file_des = -1;
|
||||||
} else{
|
} else{
|
||||||
file_des = socketDescriptor;
|
file_des = socketDescriptor;
|
||||||
|
cprintf(MAGENTA, "file des connected %d \n",file_des);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -427,24 +445,44 @@ typedef struct
|
|||||||
socketDescriptor=-1;
|
socketDescriptor=-1;
|
||||||
}
|
}
|
||||||
else{
|
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(file_des>=0){ //then was open
|
||||||
if(is_a_server){
|
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 {
|
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;
|
socketDescriptor=-1;
|
||||||
}
|
}
|
||||||
file_des=-1;
|
file_des=-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void ShutDownSocket(){
|
void ShutDownSocket(){
|
||||||
while(!shutdown(socketDescriptor, SHUT_RDWR));
|
while(!shutdown(socketDescriptor, SHUT_RDWR));
|
||||||
close(socketDescriptor);
|
Disconnect();
|
||||||
socketDescriptor = -1;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -745,16 +745,20 @@ int UDPBaseImplementation::createUDPSockets(){ FILE_LOG(logDEBUG) << __AT__ << "
|
|||||||
if(!strlen(eth)){
|
if(!strlen(eth)){
|
||||||
cout<<"warning:eth is empty.listening to all"<<endl;
|
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);
|
udpSocket[i] = new genericSocket(server_port[i],genericSocket::UDP,bufferSize);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//normal socket
|
//normal socket
|
||||||
else{
|
else{
|
||||||
cout<<"eth:"<<eth<<endl;
|
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);
|
udpSocket[i] = new genericSocket(server_port[i],genericSocket::UDP,bufferSize,eth);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//error
|
//error
|
||||||
int iret;
|
int iret;
|
||||||
|
@ -80,6 +80,7 @@ UDPStandardImplementation::UDPStandardImplementation()
|
|||||||
cout << "\nWARNING: Could not change socket receiver buffer size in file /proc/sys/net/core/rmem_max" << endl;
|
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"))
|
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;
|
cout << "\nWARNING: Could not change max length of input queue in file /proc/sys/net/core/netdev_max_backlog" << endl;
|
||||||
|
|
||||||
/** permanent setting heiner
|
/** permanent setting heiner
|
||||||
net.core.rmem_max = 104857600 # 100MiB
|
net.core.rmem_max = 104857600 # 100MiB
|
||||||
net.core.netdev_max_backlog = 250000
|
net.core.netdev_max_backlog = 250000
|
||||||
@ -1056,24 +1057,29 @@ int UDPStandardImplementation::createUDPSockets(){
|
|||||||
if(!strlen(eth)){
|
if(!strlen(eth)){
|
||||||
cout<<"warning:eth is empty.listening to all"<<endl;
|
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);
|
udpSocket[i] = new genericSocket(port[i],genericSocket::UDP,bufferSize);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//normal socket
|
//normal socket
|
||||||
else{
|
else{
|
||||||
cout<<"eth:"<<eth<<endl;
|
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);
|
udpSocket[i] = new genericSocket(port[i],genericSocket::UDP,bufferSize,eth);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//error
|
//error
|
||||||
int iret;
|
int iret;
|
||||||
for(int i=0;i<numListeningThreads;i++){
|
for(int i=0;i<numListeningThreads;i++){
|
||||||
iret = udpSocket[i]->getErrorStatus();
|
iret = udpSocket[i]->getErrorStatus();
|
||||||
if(!iret)
|
if(!iret){
|
||||||
cout << "UDP port opened at port " << port[i] << endl;
|
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
|
#ifdef VERBOSE
|
||||||
cprintf(BG_RED,"Could not create UDP socket on port %d error: %d\n", port[i], iret);
|
cprintf(BG_RED,"Could not create UDP socket on port %d error: %d\n", port[i], iret);
|
||||||
#endif
|
#endif
|
||||||
@ -1082,6 +1088,8 @@ int UDPStandardImplementation::createUDPSockets(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1276,7 +1284,7 @@ int UDPStandardImplementation::setupWriter(){
|
|||||||
packetsInFile=0;
|
packetsInFile=0;
|
||||||
packetsCaught=0;
|
packetsCaught=0;
|
||||||
frameIndex=0;
|
frameIndex=0;
|
||||||
if(sfilefd) sfilefd=NULL;
|
if(sfilefd) {cprintf(RED,"**FILE not closed!\n");fclose(sfilefd);sfilefd=NULL;}
|
||||||
guiData = NULL;
|
guiData = NULL;
|
||||||
guiDataReady=0;
|
guiDataReady=0;
|
||||||
strcpy(guiFileName,"");
|
strcpy(guiFileName,"");
|
||||||
@ -1402,9 +1410,13 @@ int UDPStandardImplementation::createNewFile(){
|
|||||||
if(enableFileWrite && cbAction > DO_NOTHING){
|
if(enableFileWrite && cbAction > DO_NOTHING){
|
||||||
//close
|
//close
|
||||||
if(sfilefd){
|
if(sfilefd){
|
||||||
|
if(fclose(sfilefd)){
|
||||||
|
cprintf(YELLOW, "file clsoe problem %d\n",fileno(sfilefd));
|
||||||
fclose(sfilefd);
|
fclose(sfilefd);
|
||||||
|
}
|
||||||
sfilefd = NULL;
|
sfilefd = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
//open file
|
//open file
|
||||||
if(!overwrite){
|
if(!overwrite){
|
||||||
if (NULL == (sfilefd = fopen((const char *) (savefilename), "wx"))){
|
if (NULL == (sfilefd = fopen((const char *) (savefilename), "wx"))){
|
||||||
@ -1418,6 +1430,9 @@ int UDPStandardImplementation::createNewFile(){
|
|||||||
//setting buffer
|
//setting buffer
|
||||||
setvbuf(sfilefd,NULL,_IOFBF,BUF_SIZE);
|
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
|
//printing packet losses and file names
|
||||||
if(!packetsCaught)
|
if(!packetsCaught)
|
||||||
cout << savefilename << endl;
|
cout << savefilename << endl;
|
||||||
@ -1459,10 +1474,12 @@ void UDPStandardImplementation::closeFile(int ithr){
|
|||||||
|
|
||||||
if(!dataCompression){
|
if(!dataCompression){
|
||||||
if(sfilefd){
|
if(sfilefd){
|
||||||
#ifdef VERBOSE
|
//#ifdef VERBOSE
|
||||||
cout << "sfield:" << (int)sfilefd << endl;
|
cprintf(YELLOW, "gonna close file:%d\n",fileno(sfilefd));
|
||||||
#endif
|
//#endif
|
||||||
fclose(sfilefd);
|
if(fclose(sfilefd))
|
||||||
|
perror("close ERRROR");
|
||||||
|
cprintf(YELLOW, "check close file:%d\n",fileno(sfilefd));
|
||||||
sfilefd = NULL;
|
sfilefd = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1473,7 +1490,8 @@ void UDPStandardImplementation::closeFile(int ithr){
|
|||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
cout << "sfield:" << (int)sfilefd << endl;
|
cout << "sfield:" << (int)sfilefd << endl;
|
||||||
#endif
|
#endif
|
||||||
fclose(sfilefd);
|
if(fclose(sfilefd))
|
||||||
|
perror("close ERRROR");
|
||||||
sfilefd = NULL;
|
sfilefd = NULL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -1612,7 +1630,6 @@ int UDPStandardImplementation::stopReceiver(){
|
|||||||
}else cout <<" Not idle to stop receiver" << endl;
|
}else cout <<" Not idle to stop receiver" << endl;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//sem_post(&smp);
|
//sem_post(&smp);
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
|
@ -65,7 +65,6 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, UDPInterface*
|
|||||||
strcpy(socket->lastClientIP,"none");
|
strcpy(socket->lastClientIP,"none");
|
||||||
strcpy(socket->thisClientIP,"none1");
|
strcpy(socket->thisClientIP,"none1");
|
||||||
strcpy(mess,"dummy message");
|
strcpy(mess,"dummy message");
|
||||||
|
|
||||||
function_table();
|
function_table();
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
cout << "Function table assigned." << endl;
|
cout << "Function table assigned." << endl;
|
||||||
|
Reference in New Issue
Block a user