Commit 0f826d98 authored by Benoit Steiner's avatar Benoit Steiner

Pinger termine (Il faudrait factoriser le code pour avoir un truc

vraiment propre).

Nettoyage du code avant ecriture des fonctions d'administration par
telnet du bridge.

Benny
parent 9a8b18ee
......@@ -59,10 +59,10 @@ struct s_Fifo* FifoCreate()
int FifoDestroy(struct s_Fifo* psfFifo)
{
int iRc = pthread_mutex_destroy(&psfFifo->FifoLock);
printf("FIFO mutex destruction: %s\n", strerror(iRc));
// printf("FIFO mutex destruction: %s\n", strerror(iRc));
iRc |= pthread_cond_destroy(&psfFifo->FifoSignal);
printf("FIFO cond destruction: iRc %d, %s\n", iRc, strerror(iRc));
// printf("FIFO cond destruction: iRc %d, %s\n", iRc, strerror(iRc));
free(psfFifo);
......
......@@ -166,7 +166,7 @@ int Receive(struct s_Listener* share)
if (iConnectionOK <= 0)
{
/* Connection lost: register error and exit the for loop */
Log(LOG_ERROR, MOD_NAME, "Read error: %s", strerror(errno));
Log(LOG_ERROR, MOD_NAME, "Recv from VLANserver error: %s", strerror(errno));
iRc = errno;
break;
}
......@@ -291,10 +291,10 @@ int CancelListener (struct s_Listener* pslListener)
{
Log(LOG_NOTE, MOD_NAME, "Stopping listener thread");
iRc = pthread_cancel(pslListener->tid);
printf("listner canceled with iRc %d\n", iRc);
// printf("listner canceled with iRc %d and error: %s\n", iRc, strerror(iRc));
/* Synchronise ourselves with the destruction of the thread */
iRc |= pthread_join(pslListener->tid, NULL);
printf("listner joined with iRc %d\n", iRc);
// printf("listner joined with iRc %d and error: %s\n", iRc, strerror(iRc));
/* When the thread is cancelled while waiting for a a socket, it relocks
the ConnectionLock, so that the sender thread cannot anymore work for
it shares the ConnectionLock with the listener */
......@@ -320,8 +320,7 @@ int FreeListener(struct s_Listener* pslListener)
if (pslListener->tid != 0)
{
iRc |= pthread_cond_destroy(&pslListener->WakeUpSignal);
printf("Listener cond destroyed with iRc %d\n", iRc);
// printf("Listener cond destroyed with iRc %d and error: %s\n", iRc, strerror(iRc));
/* No more listener is running */
pslListener->tid = 0;
......
......@@ -505,6 +505,15 @@ int WarnNetwork(const struct s_Request* psrJob)
Log (LOG_NOTE, MOD_NAME, "Sending the requested gratuitous ARP packets");
#endif
/* Tell the client how to reach the VLANbridge */
#ifdef DEBUG
Log (LOG_NOTE, MOD_NAME, "The bridge, it's now me on VLAN %d",
psrJob->iVLANdst);
#endif
iRc = Gratuitous_Send (&asaMapToIP[psrJob->iVLANdst],
&asaMapToMAC[psrJob->iVLANdst],
strMapToDev[psrJob->iVLANdst]);
/* Tell the client how to reach the router */
if (psrJob->iVLANdst != iVLANDflt)
{
......@@ -551,18 +560,6 @@ int WarnNetwork(const struct s_Request* psrJob)
strMapToDev[psrJob->iVLANsrc]);
};
// for (iVLAN = 1; iVLAN <= iVLANNumber; iVLAN++)
// {
// if (iVLAN != psrJob->iVLANdst && strcmp (strMapToDev[iVLAN], "") > 0)
// {
//#ifdef DEBUG
// Log (LOG_NOTE, MOD_NAME, "The client, it's now me on VLAN %d", iVLAN);
//#endif
// iRc |= Gratuitous_Send (&psrJob->saClientIP, &asaMapToMAC[iVLAN],
// strMapToDev[iVLAN]);
// };
// };
return iRc;
}
......
......@@ -210,7 +210,9 @@ int Pinger_DetectMove(const struct s_Pinger* pspConfig, int* piHasMoved)
fd_set fds;
struct timeval tv;
int iAnswered = 0;
char strAnswer[PINGER_ANSWERSIZE];
int i = 0;
int iAddrLen = sizeof(pspConfig->saHostAddr);
ASSERT(pspConfig);
ASSERT(piHasMoved);
......@@ -234,9 +236,21 @@ int Pinger_DetectMove(const struct s_Pinger* pspConfig, int* piHasMoved)
switch (iAnswered)
{
case 1: /* The host has answered */
Pinger(pspConfig); /* Reannounce ourselves to the host */
{
iAnswered = recvfrom(pspConfig->iSockFd, strAnswer, sizeof(strAnswer),
0, (struct sockaddr *)&pspConfig->saHostAddr, &iAddrLen);
if (iAnswered > 0 && CheckAnswer(strAnswer, pspConfig))
Pinger(pspConfig); /* Reannounce ourselves to the host */
else
{
Log(LOG_NOTE, MOD_NAME, "Bad packet receive or receive error from %s",
inet_ntoa(pspConfig->saHostAddr.sin_addr));
*piHasMoved = 1;
}
break;
case 0: /* The host didn't answer */
}
case 0: /* The host didn't answer */
*piHasMoved = 1;
break;
case -1: /* There was a problem */
......@@ -251,7 +265,7 @@ int Pinger_DetectMove(const struct s_Pinger* pspConfig, int* piHasMoved)
{
/* Reinit tv struct or select modifies it at each call */
tv.tv_sec = 0;
tv.tv_usec = 500000;
tv.tv_usec = PINGER_TIMEOUT;
}
}
}
......
......@@ -42,12 +42,6 @@ extern pthread_mutex_t ConnectionLock;
#define MOD_NAME MOD_SENDER
void clean_toto(void* pvSenderFifo)
{
pthread_cond_signal(&((struct s_Fifo*)pvSenderFifo)->FifoSignal);
// pthread_mutex_trylock(&ConnectionLock);
pthread_mutex_unlock(&ConnectionLock);
}
/***************************************************************************/
......@@ -186,8 +180,9 @@ int Answer(struct s_Sender *share)
while (iConnectionOK > 0)
{
/* Wait for a message if the FIFO is empty */
// printf("Sender -> Waiting for a message from manager\n");
iRc = FifoPull(share->psfWaitingAnswers, &psrAnswer);
// printf("Sender -> Message received\n");
/* Convert the msg to ascii */
iRc = ParseAnswer(psrAnswer, buff);
/* Message is no more used */
......@@ -232,11 +227,6 @@ void* SenderThread (void* arg)
ASSERT(arg);
pthread_cleanup_push(&clean_toto, sender->psfWaitingAnswers);
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
#ifdef DEBUG
Log (LOG_NOTE, MOD_NAME, "Sender thread is running");
#endif
......@@ -286,8 +276,6 @@ void* SenderThread (void* arg)
}
}
pthread_cleanup_pop(0);
/* Exit the thread returning the NULL value */
pthread_exit(NULL);
}
......@@ -308,16 +296,16 @@ int CancelSender(struct s_Sender* pssSender)
Log(LOG_NOTE, MOD_NAME, "Stopping sender thread");
iRc = pthread_cancel(pssSender->tid);
printf("Sender thread canceled with iRc %d and error %s\n", iRc, strerror(errno));
// printf("Sender thread canceled with iRc %d and error %s\n", iRc, strerror(iRc));
/* Synchronise ourselves with the destruction of the thread, to avoid to destroy
the condition while the sender is waiting on it */
iRc |= pthread_join(pssSender->tid, NULL);
printf("Sender thread joined with iRc %d and error %s\n", iRc, strerror(errno));
// printf("Sender thread joined with iRc %d and error %s\n", iRc, strerror(iRc));
/* When the thread is cancelled while waiting for a a socket, it relocks
the ConnectionLock, so that the sender thread cannot anymore work for
it shares the ConnectionLock with the listener */
// pthread_mutex_trylock(&ConnectionLock);
// pthread_mutex_unlock(&ConnectionLock);
pthread_mutex_trylock(&ConnectionLock);
pthread_mutex_unlock(&ConnectionLock);
}
else
Log(LOG_WARN, MOD_NAME, "Could not stop sender, none is running");
......@@ -338,10 +326,10 @@ int FreeSender(struct s_Sender* pssSender)
if (pssSender->tid != 0)
{
iRc = pthread_cond_destroy(&pssSender->WakeUpSignal);
printf("Sender thread cond destoyed with iRc %d and error %s\n", iRc, strerror(errno));
// printf("Sender thread cond destoyed with iRc %d and error %s\n", iRc, strerror(iRc));
iRc |= FifoDestroy(pssSender->psfWaitingAnswers);
printf("Sender thread FIFO destoyed with iRc %d and error %s\n", iRc, strerror(errno));
// printf("Sender thread FIFO destoyed with iRc %d and error %s\n", iRc, strerror(iRc));
if (!iRc)
Log(LOG_NOTE, MOD_NAME, "Sender thread destroyed");
......
......@@ -2,7 +2,8 @@
*
* Benoit Steiner, VIA, ECP, France <benny@via.ecp.fr> 23/10/98
*
* TO DO: Everything !
* Known Bug: When stopping the pgrm with a Ctrl+C, it often freezes when
* trying to cancel the sender thread
*/
......@@ -19,9 +20,6 @@
void SigHup(int iCrap)
{
Log(LOG_WARN, MOD_NAME, "Received SIGHUP: Hangup detected");
/* Normally the signal handler should no be reset to its default value */
// signal(SIGHUP, SigHup);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment