Added server status

This commit is contained in:
elvis
2022-03-12 10:05:58 +01:00
parent d99a19228b
commit b4ca73b8d6
4 changed files with 129 additions and 76 deletions

View File

@ -48,7 +48,7 @@
#define CHECK_EQ_EXIT(name, X, val, str, ...) \
if ((X)==val) { \
perror(#name); \
perror(#name); \
int errno_copy = errno; \
print_error(str, __VA_ARGS__); \
exit(errno_copy); \
@ -56,7 +56,7 @@
#define CHECK_NEQ_EXIT(name, X, val, str, ...) \
if ((X)!=val) { \
perror(#name); \
perror(#name); \
int errno_copy = errno; \
print_error(str, __VA_ARGS__); \
exit(errno_copy); \
@ -72,8 +72,8 @@ static inline void print_error(const char * str, ...) {
char * p=(char *)malloc(strlen(str)+strlen(err)+EXTRA_LEN_PRINT_ERROR);
if (!p) {
perror("malloc");
fprintf(stderr,"FATAL ERROR nella funzione 'print_error'\n");
return;
fprintf(stderr,"FATAL ERROR nella funzione 'print_error'\n");
return;
}
strcpy(p,err);
strcpy(p+strlen(err), str);
@ -84,7 +84,7 @@ static inline void print_error(const char * str, ...) {
}
/**
/**
* \brief Controlla se la stringa passata come primo argomento e' un numero.
* \return 0 ok 1 non e' un numbero 2 overflow/underflow
*/
@ -97,55 +97,56 @@ static inline int isNumber(const char* s, long* n) {
if (errno == ERANGE) return 2; // overflow/underflow
if (e != NULL && *e == (char)0) {
*n = val;
return 0; // successo
return 0; // successo
}
return 1; // non e' un numero
}
#define LOCK(l) if (pthread_mutex_lock(l)!=0) { \
fprintf(stderr, "ERRORE FATALE lock\n"); \
pthread_exit((void*)EXIT_FAILURE); \
}
#define LOCK_RETURN(l, r) if (pthread_mutex_lock(l)!=0) { \
fprintf(stderr, "ERRORE FATALE lock\n"); \
return r; \
}
#define LOCK(l) if (pthread_mutex_lock(l)!=0) { \
fprintf(stderr, "ERRORE FATALE lock\n"); \
pthread_exit((void*)EXIT_FAILURE); \
}
#define LOCK_RETURN(l, r) if (pthread_mutex_lock(l)!=0) { \
fprintf(stderr, "ERRORE FATALE lock\n"); \
return r; \
}
#define UNLOCK(l) if (pthread_mutex_unlock(l)!=0) { \
fprintf(stderr, "ERRORE FATALE unlock\n"); \
pthread_exit((void*)EXIT_FAILURE); \
}
#define UNLOCK_RETURN(l,r) if (pthread_mutex_unlock(l)!=0) { \
fprintf(stderr, "ERRORE FATALE unlock\n"); \
return r; \
}
#define WAIT(c,l) if (pthread_cond_wait(c,l)!=0) { \
fprintf(stderr, "ERRORE FATALE wait\n"); \
pthread_exit((void*)EXIT_FAILURE); \
}
#define UNLOCK(l) if (pthread_mutex_unlock(l)!=0) { \
fprintf(stderr, "ERRORE FATALE unlock\n"); \
pthread_exit((void*)EXIT_FAILURE); \
}
#define UNLOCK_RETURN(l,r) if (pthread_mutex_unlock(l)!=0) { \
fprintf(stderr, "ERRORE FATALE unlock\n"); \
return r; \
}
#define WAIT(c,l) if (pthread_cond_wait(c,l)!=0) { \
fprintf(stderr, "ERRORE FATALE wait\n"); \
pthread_exit((void*)EXIT_FAILURE); \
}
/* ATTENZIONE: t e' un tempo assoluto! */
#define TWAIT(c,l,t) { \
int r=0; \
if ((r=pthread_cond_timedwait(c,l,t))!=0 && r!=ETIMEDOUT) { \
fprintf(stderr, "ERRORE FATALE timed wait\n"); \
pthread_exit((void*)EXIT_FAILURE); \
} \
}
#define SIGNAL(c) if (pthread_cond_signal(c)!=0) { \
fprintf(stderr, "ERRORE FATALE signal\n"); \
pthread_exit((void*)EXIT_FAILURE); \
}
#define BCAST(c) if (pthread_cond_broadcast(c)!=0) { \
fprintf(stderr, "ERRORE FATALE broadcast\n"); \
pthread_exit((void*)EXIT_FAILURE); \
}
#define TWAIT(c,l,t) { \
int r=0; \
if ((r=pthread_cond_timedwait(c,l,t))!=0 && r!=ETIMEDOUT) { \
fprintf(stderr, "ERRORE FATALE timed wait\n"); \
pthread_exit((void*)EXIT_FAILURE); \
} \
}
#define SIGNAL(c) if (pthread_cond_signal(c)!=0) { \
fprintf(stderr, "ERRORE FATALE signal\n"); \
pthread_exit((void*)EXIT_FAILURE); \
}
#define BCAST(c) if (pthread_cond_broadcast(c)!=0) { \
fprintf(stderr, "ERRORE FATALE broadcast\n"); \
pthread_exit((void*)EXIT_FAILURE); \
}
static inline int TRYLOCK(pthread_mutex_t* l) {
int r=0;
if ((r=pthread_mutex_trylock(l))!=0 && r!=EBUSY) {
fprintf(stderr, "ERRORE FATALE unlock\n");
pthread_exit((void*)EXIT_FAILURE);
}
return r;
int r=0;
if ((r=pthread_mutex_trylock(l))!=0 && r!=EBUSY) {
fprintf(stderr, "ERRORE FATALE unlock\n");
pthread_exit((void*)EXIT_FAILURE);
}
return r;
}
#endif /* _UTIL_H */