#include <signal.h>
#include <pthread.h>
#include "common.h"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include "com_defs.h"
#include "common.h"
#include "fat_defs.h"
#include "fat.h"
Vai al codice sorgente di questo file.
Funzioni | |
void * | thread_servernte (void *) |
This program is free software; you can redistribuite it and/or modify it under the terms of the GNU/General Pubblic License as published the Free software Foundation; either version 2 of the License, or (at your opinion) any later version.
Definizione nel file comandi.h.
void* thread_servernte | ( | void * | ) |
Thread delegato all'esecuzione dei messaggi mandati dai client
Definizione alla linea 125 del file comandi.c.
00125 { 00126 extern struct lista my_socket; 00127 extern pthread_mutex_t lock; 00128 extern pthread_cond_t wait_me; 00129 extern int num_threads; 00130 sigset_t set; 00131 channel_t sk_cl; 00132 message_t msg; 00133 int recive_val=0; 00134 00135 sk_cl = *(int *)sk; 00136 msg.buffer = NULL; 00137 00138 /* Blocco i segnali */ 00139 if (sigfillset(&set) == -1){ 00140 errore(__FILE__,__LINE__,"Server: error sigfillset",errno); 00141 return 0; 00142 } 00143 if (pthread_sigmask(SIG_SETMASK, &set, NULL) != 0) { 00144 errore(__FILE__,__LINE__,"Server: pthread_sigmask error 'sigsetmask'",errno); 00145 return 0; 00146 } 00147 00148 while (recive_val!=SEOF){ 00149 if ((recive_val = receiveMessage(sk_cl, &msg)) == -1) break; 00150 else if (recive_val != SEOF){ /* !SIGPIPE */ 00151 switch(msg.type){ 00152 case MSG_MKDIR: 00153 msg_mkdir(&msg); 00154 break; 00155 case MSG_LS: 00156 msg_ls(&msg); 00157 break; 00158 case MSG_MKFILE: 00159 msg_mkfile(&msg); 00160 break; 00161 case MSG_FREAD: 00162 msg_fread(&msg); 00163 break; 00164 case MSG_FWRITE: 00165 msg_fwrite(&msg); 00166 break; 00167 } 00168 if (sendMessage(sk_cl, &msg) == -1) break; 00169 } 00170 } 00171 /* Chiudo il socket di comunicazione tra client e server */ 00172 closeSocket(sk_cl); 00173 /* Rimuovo il thread dalla lista dei thread */ 00174 pthread_mutex_lock(&lock); 00175 num_threads--; 00176 rimuovi(sk_cl, &my_socket); 00177 pthread_mutex_unlock(&lock); 00178 pthread_cond_signal(&wait_me); 00179 00180 return 0; 00181 }