implemented waiting llist in alarm_handler
This commit is contained in:
parent
278e880e62
commit
6a4034668b
@ -33,10 +33,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
#include <why2/memory.h>
|
#include <why2/memory.h>
|
||||||
#include <why2/misc.h>
|
#include <why2/misc.h>
|
||||||
|
|
||||||
//TIMEOUT STUFF
|
//LINKED LIST STUFF (BIT CHANGED memory.c'S VERSION) //TODO: Move llist in some single separate file
|
||||||
pthread_t thread_timeout_buffer;
|
|
||||||
|
|
||||||
//LINKED LIST STUFF (BIT CHANGED memory.c'S VERSION)
|
|
||||||
typedef struct node
|
typedef struct node
|
||||||
{
|
{
|
||||||
int connection;
|
int connection;
|
||||||
@ -285,7 +282,14 @@ void remove_json_syntax_characters(char *text)
|
|||||||
|
|
||||||
void alarm_handler()
|
void alarm_handler()
|
||||||
{
|
{
|
||||||
pthread_cancel(thread_timeout_buffer);
|
//CANCEL OLDEST THREAD
|
||||||
|
pthread_cancel(waiting_head -> thread);
|
||||||
|
|
||||||
|
//REMOVE FIRST NODE
|
||||||
|
waiting_node_t *buffer = waiting_head; //BUFFER
|
||||||
|
|
||||||
|
waiting_head = buffer -> next; //UNLINK
|
||||||
|
free(waiting_head);
|
||||||
}
|
}
|
||||||
|
|
||||||
//GLOBAL
|
//GLOBAL
|
||||||
@ -356,13 +360,14 @@ void *why2_communicate_thread(void *arg)
|
|||||||
while (!exiting) //KEEP COMMUNICATION ALIVE FOR 5 MINUTES [RESET TIMER AT MESSAGE SENT]
|
while (!exiting) //KEEP COMMUNICATION ALIVE FOR 5 MINUTES [RESET TIMER AT MESSAGE SENT]
|
||||||
{
|
{
|
||||||
//READ
|
//READ
|
||||||
pthread_create(&thread_timeout_buffer, NULL, read_socket_raw_thread, &connection);
|
pthread_create(&thread_buffer, NULL, read_socket_raw_thread, &connection);
|
||||||
|
waiting_push_to_list(thread_buffer);
|
||||||
|
|
||||||
//SET TIMEOUT (DEFAULT IS 5 MINUTES)
|
//SET TIMEOUT (DEFAULT IS 5 MINUTES)
|
||||||
signal(SIGALRM, alarm_handler);
|
signal(SIGALRM, alarm_handler);
|
||||||
alarm(WHY2_COMMUNICATION_TIME);
|
alarm(WHY2_COMMUNICATION_TIME);
|
||||||
|
|
||||||
pthread_join(thread_timeout_buffer, &raw_ptr);
|
pthread_join(thread_buffer, &raw_ptr);
|
||||||
|
|
||||||
if (raw_ptr == WHY2_INVALID_POINTER || raw_ptr == NULL) break; //QUIT COMMUNICATION IF INVALID PACKET WAS RECEIVED
|
if (raw_ptr == WHY2_INVALID_POINTER || raw_ptr == NULL) break; //QUIT COMMUNICATION IF INVALID PACKET WAS RECEIVED
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user