some changes to remove possible warnings

This commit is contained in:
Dhanya Maliakal 2017-05-11 14:41:07 +02:00
parent 95bf19a417
commit f53770a2fc
4 changed files with 45 additions and 30 deletions

View File

@ -206,7 +206,7 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
static pthread_mutex_t Mutex;
/** GeneralData (Detector Data) object */
static const GeneralData* generalData;
const GeneralData* generalData;
/** Fifo structure */
Fifo* fifo;
@ -241,10 +241,10 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
uint32_t* dynamicRange;
/**Number of complete Packets caught for an entire acquisition (including all scans) */
uint64_t numTotalPacketsCaught;
volatile uint64_t numTotalPacketsCaught;
/** Number of complete Packets caught for each real time acquisition (eg. for each scan) */
uint64_t numPacketsCaught;
volatile uint64_t numPacketsCaught;
/** Frame Number of First Frame of an entire Acquisition (including all scans) */
uint64_t firstAcquisitionIndex;

View File

@ -88,7 +88,7 @@ enum communicationProtocol{
genericSocket(const char* const host_ip_or_name, unsigned short int const port_number, communicationProtocol p, int ps = DEFAULT_PACKET_SIZE) :
// portno(port_number),
portno(port_number),
protocol(p),
is_a_server(0),
socketDescriptor(-1),
@ -149,7 +149,7 @@ enum communicationProtocol{
*/
genericSocket(unsigned short int const port_number, communicationProtocol p, int ps = DEFAULT_PACKET_SIZE, const char *eth=NULL, int hsize=0):
//portno(port_number),
portno(port_number),
protocol(p),
is_a_server(1),
socketDescriptor(-1),
@ -161,8 +161,10 @@ enum communicationProtocol{
header_packet_size(hsize)
{
memset(&serverAddress, 0, sizeof(serverAddress));
memset(&clientAddress, 0, sizeof(clientAddress));
/* // you can specify an IP address: */
/* // or you can let it automatically select one: */
/* myaddr.sin_addr.s_addr = INADDR_ANY; */
@ -483,15 +485,17 @@ enum communicationProtocol{
static string ipToName(string ip) {
struct ifaddrs *addrs, *iap;
struct sockaddr_in *sa;
char buf[32];
char buf[32];
const int buf_len = sizeof(buf);
memset(buf,0,buf_len);
strcpy(buf,"none");
getifaddrs(&addrs);
for (iap = addrs; iap != NULL; iap = iap->ifa_next) {
if (iap->ifa_addr && (iap->ifa_flags & IFF_UP) && iap->ifa_addr->sa_family == AF_INET) {
sa = (struct sockaddr_in *)(iap->ifa_addr);
inet_ntop(iap->ifa_addr->sa_family, (void *)&(sa->sin_addr), buf, sizeof(buf));
inet_ntop(iap->ifa_addr->sa_family, (void *)&(sa->sin_addr), buf, buf_len);
if (ip==string(buf)) {
//printf("%s\n", iap->ifa_name);
strcpy(buf,iap->ifa_name);
@ -507,6 +511,8 @@ enum communicationProtocol{
struct ifreq ifr;
int sock, j, k;
char mac[32];
const int mac_len = sizeof(mac);
memset(mac,0,mac_len);
sock=getSock(inf,&ifr);
@ -515,10 +521,10 @@ enum communicationProtocol{
return string("00:00:00:00:00:00");
}
for (j=0, k=0; j<6; j++) {
k+=snprintf(mac+k, sizeof(mac)-k-1, j ? ":%02X" : "%02X",
k+=snprintf(mac+k, mac_len-k-1, j ? ":%02X" : "%02X",
(int)(unsigned int)(unsigned char)ifr.ifr_hwaddr.sa_data[j]);
}
mac[sizeof(mac)-1]='\0';
mac[mac_len-1]='\0';
if(sock!=1){
close(sock);
@ -533,6 +539,8 @@ enum communicationProtocol{
struct ifreq ifr;
int sock;
char *p, addr[32];
const int addr_len = sizeof(addr);
memset(addr,0,addr_len);
sock=getSock(inf,&ifr);
@ -541,8 +549,8 @@ enum communicationProtocol{
return string("0.0.0.0");
}
p=inet_ntoa(((struct sockaddr_in *)(&ifr.ifr_addr))->sin_addr);
strncpy(addr,p,sizeof(addr)-1);
addr[sizeof(addr)-1]='\0';
strncpy(addr,p,addr_len-1);
addr[addr_len-1]='\0';
if(sock!=1){
close(sock);
@ -616,6 +624,9 @@ enum communicationProtocol{
//normal
nsending=packet_size;
while(1){
#ifdef VERYVERBOSE
cprintf(BLUE,"%d gonna listen\n", portno); fflush(stdout);
#endif
nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length);
//break out of loop only if read one packets size or read didnt work (cuz of shutdown)
if(nsent<=0 || nsent == packet_size)
@ -697,6 +708,7 @@ enum communicationProtocol{
protected:
int portno;
communicationProtocol protocol;
int is_a_server;
int socketDescriptor;

View File

@ -26,11 +26,10 @@ uint64_t Listener::RunningMask(0x0);
pthread_mutex_t Listener::Mutex = PTHREAD_MUTEX_INITIALIZER;
const GeneralData* Listener::generalData(0);
Listener::Listener(Fifo*& f, runStatus* s, uint32_t* portno, char* e, int* act, uint64_t* nf, uint32_t* dr) :
ThreadObject(NumberofListeners),
generalData(0),
fifo(f),
acquisitionStartedFlag(false),
measurementStartedFlag(false),
@ -64,8 +63,8 @@ Listener::Listener(Fifo*& f, runStatus* s, uint32_t* portno, char* e, int* act,
Listener::~Listener() {
if (udpSocket) delete udpSocket;
if (carryOverPacket) delete carryOverPacket;
if (listeningPacket) delete listeningPacket;
if (carryOverPacket) delete [] carryOverPacket;
if (listeningPacket) delete [] listeningPacket;
ThreadObject::DestroyThread();
NumberofListeners--;
}
@ -146,11 +145,13 @@ void Listener::ResetParametersforNewMeasurement(){
firstMeasurementIndex = 0;
carryOverFlag = false;
if (carryOverPacket)
delete carryOverPacket;
delete [] carryOverPacket;
carryOverPacket = new char[generalData->packetSize];
memset(carryOverPacket,0,generalData->packetSize);
if (listeningPacket)
delete listeningPacket;
delete [] listeningPacket;
listeningPacket = new char[generalData->packetSize];
memset(listeningPacket,0,generalData->packetSize);
}
@ -191,19 +192,19 @@ int Listener::SetThreadPriority(int priority) {
}
int Listener::CreateUDPSockets() {
ShutDownUDPSocket();
if (!(*activated))
return OK;
//if eth is mistaken with ip address
if (strchr(eth,'.') != NULL){
strcpy(eth,"");
strncpy(eth,"", MAX_STR_LENGTH);
}
if(!strlen(eth)){
FILE_LOG(logWARNING) << "eth is empty. Listening to all";
}
ShutDownUDPSocket();
udpSocket = new genericSocket(*udpPortNumber, genericSocket::UDP,
generalData->packetSize, (strlen(eth)?eth:NULL), generalData->headerPacketSize);
int iret = udpSocket->getErrorStatus();
@ -247,7 +248,7 @@ void Listener::ThreadExecution() {
}
//get data
if (*status != TRANSMITTING) {
if (*status != TRANSMITTING && udpSocket) {
if (*activated)
rc = ListenToAnImage(buffer);
else
@ -255,7 +256,7 @@ void Listener::ThreadExecution() {
}
//done acquiring
if (*status == TRANSMITTING || ((!(*activated)) && (rc == 0))) {
if ((*status == TRANSMITTING) || ( (!(*activated)) && (rc == 0)) ) {
StopListening(buffer);
return;
}
@ -288,13 +289,13 @@ void Listener::StopListening(char* buf) {
fifo->PushAddress(buf);
StopRunning();
#ifdef VERBOSE
cprintf(GREEN,"%d: Listening Packets (%d) : %d\n", index, *udpPortNumber, numPacketsCaught);
cprintf(GREEN,"%d: Listening Packets (%u) : %llu\n", index, *udpPortNumber, numPacketsCaught);
printf("%d: Listening Completed\n", index);
#endif
}
/* buf includes the header */
/* buf includes the fifo header and packet header */
uint32_t Listener::ListenToAnImage(char* buf) {
uint32_t rc = 0;
uint64_t fnum = 0, bid = 0;
@ -345,8 +346,10 @@ uint32_t Listener::ListenToAnImage(char* buf) {
while ( isHeaderEmpty || (pnum < (generalData->packetsPerFrame-1))) {
//listen to new packet
int curr_rc = udpSocket->ReceiveDataOnly(listeningPacket);
int curr_rc = 0;
if (udpSocket){
curr_rc = udpSocket->ReceiveDataOnly(listeningPacket);
}
if(curr_rc <= 0) {
if (rc <= 0) return 0; //empty image
return generalData->imageSize; //empty packet now, but not empty image
@ -359,7 +362,7 @@ uint32_t Listener::ListenToAnImage(char* buf) {
generalData->GetHeaderInfo(index, listeningPacket, *dynamicRange, fnum, pnum, snum, bid);
lastCaughtFrameIndex = fnum;
#ifdef VERBOSE
if (!index)
//if (!index)
cprintf(GREEN,"Listening %d: fnum:%lu, pnum:%d\n", index,fnum, pnum);
#endif
if (!measurementStartedFlag)

View File

@ -553,7 +553,7 @@ void UDPStandardImplementation::startReadout(){
if(activated){
//current packets caught
int totalP = 0,prev=-1;
volatile int totalP = 0,prev=-1;
for (vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it)
totalP += (*it)->GetTotalPacketsCaught();
@ -563,10 +563,11 @@ void UDPStandardImplementation::startReadout(){
//wait as long as there is change from prev totalP,
while(prev != totalP){
#ifdef VERY_VERBOSE
cprintf(MAGENTA,"waiting for all packets prevP:%d totalP:%d PrevBuffer:%d currentBuffer:%d\n",prev,totalP,prevReceivedInBuffer,currentReceivedInBuffer);
cprintf(MAGENTA,"waiting for all packets prevP:%d totalP:%d\n",
prev,totalP);
#endif
//usleep(2*1000*1000);
usleep(1*1000*1000);usleep(1*1000*1000);usleep(1*1000*1000);usleep(1*1000*1000);
usleep(5*1000);/* Need to find optimal time **/
prev = totalP;
@ -588,7 +589,6 @@ void UDPStandardImplementation::startReadout(){
FILE_LOG(logINFO) << "Status: Transmitting";
}
//shut down udp sockets so as to make listeners push dummy (end) packets for processors
shutDownUDPSockets();
}