1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-23 01:33:02 +01:00

create dns loopup threads in detached state & add a few missing error descriptions

This commit is contained in:
Jfreegman 2014-07-09 23:40:46 -04:00
parent e19b0ed710
commit aaeb47dc14
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
3 changed files with 20 additions and 17 deletions

View File

@ -79,6 +79,7 @@ static struct _thread_data {
static struct _dns_thread {
pthread_t tid;
pthread_attr_t attr;
} dns_thread;
@ -100,7 +101,8 @@ static void kill_dns_thread(void *dns_obj)
tox_dns3_kill(dns_obj);
memset(&t_data, 0, sizeof(struct _thread_data));
pthread_exit(0);
pthread_attr_destroy(&dns_thread.attr);
pthread_exit(NULL);
}
/* puts TXT from dns response in buf. Returns length of TXT on success, -1 on fail.*/
@ -303,10 +305,12 @@ void dns3_lookup(ToxWindow *self, Tox *m, char *id_bin, char *addr, char *msg)
t_data.m = m;
t_data.busy = 1;
pthread_mutex_unlock(&Winthread.lock);
if (pthread_attr_init(&dns_thread.attr) != 0)
exit_toxic_err("failed in dns3_lookup", FATALERR_THREAD_ATTR);
if (pthread_create(&dns_thread.tid, NULL, dns3_lookup_thread, NULL) != 0)
if (pthread_attr_setdetachstate(&dns_thread.attr, PTHREAD_CREATE_DETACHED) != 0)
exit_toxic_err("failed in dns3_lookup", FATALERR_THREAD_ATTR);
if (pthread_create(&dns_thread.tid, &dns_thread.attr, dns3_lookup_thread, NULL) != 0)
exit_toxic_err("failed in dns3_lookup", FATALERR_THREAD_CREATE);
pthread_mutex_lock(&Winthread.lock);
}

View File

@ -446,9 +446,7 @@ static void load_data(Tox *m, char *path)
free(buf);
fclose(fd);
} else {
int st;
if ((st = store_data(m, path)) != 0)
if (store_data(m, path) != 0)
exit_toxic_err("failed in load_data", FATALERR_STORE_DATA);
}
}

View File

@ -64,15 +64,16 @@
#define T_KEY_C_H 0x08 /* ctrl-h */
typedef enum _FATAL_ERRS {
FATALERR_MEMORY = -1, /* malloc() or calloc() failed */
FATALERR_FREAD = -2, /* fread() failed on critical read */
FATALERR_THREAD_CREATE = -3,
FATALERR_MUTEX_INIT = -4,
FATALERR_LOCALE_SET = -5,
FATALERR_STORE_DATA = -6,
FATALERR_NETWORKINIT = -7, /* Tox network failed to init */
FATALERR_INFLOOP = -8, /* infinite loop detected */
FATALERR_WININIT = -9, /* window init failed */
FATALERR_MEMORY = -1, /* malloc() or calloc() failed */
FATALERR_FREAD = -2, /* fread() failed on critical read */
FATALERR_THREAD_CREATE = -3, /* thread creation failed */
FATALERR_MUTEX_INIT = -4, /* mutex init failed */
FATALERR_THREAD_ATTR = -5, /* thread attr object init failed */
FATALERR_LOCALE_SET = -6, /* system locale not set */
FATALERR_STORE_DATA = -7, /* store_data failed in critical section */
FATALERR_NETWORKINIT = -8, /* Tox network failed to init */
FATALERR_INFLOOP = -9, /* infinite loop detected */
FATALERR_WININIT = -10, /* window init failed */
} FATAL_ERRS;
/* Fixes text color problem on some terminals.