"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/names/thread_resolve.c" between
etherape-0.9.17.tar.gz and etherape-0.9.18.tar.gz

About: EtherApe is a GNOME/pcap-based graphical network monitor (etherman clone).

thread_resolve.c  (etherape-0.9.17):thread_resolve.c  (etherape-0.9.18)
skipping to change at line 94 skipping to change at line 94
} }
static void static void
close_mutex(void) close_mutex(void)
{ {
pthread_mutex_destroy(&resolvemtx); pthread_mutex_destroy(&resolvemtx);
pthread_cond_destroy(&resolvecond); pthread_cond_destroy(&resolvecond);
} }
/* thread routine */ /* thread routine */
static void * static void *thread_pool_routine(void *dt)
thread_pool_routine(void *dt)
{ {
struct ipcache_item *curitem; struct ipcache_item *curitem;
struct ipresolve_link *el; struct ipresolve_link *el;
struct hostent resultbuf;
struct hostent *resultptr; struct hostent *resultptr;
struct sockaddr_in sa;
struct sockaddr_in6 sa6;
struct sockaddr *saptr;
socklen_t salen;
char extrabuf[4096]; char extrabuf[4096];
int errnovar;
int result; int result;
while (!request_stop_thread) while (!request_stop_thread)
{ {
pthread_mutex_lock(&resolvemtx); pthread_mutex_lock(&resolvemtx);
if (!request_stop_thread && !resolveListHead) if (!request_stop_thread && !resolveListHead)
{ {
/* list empty, wait on condition releasing mutex */ /* list empty, wait on condition releasing mutex */
pthread_cond_wait (&resolvecond, &resolvemtx); pthread_cond_wait (&resolvecond, &resolvemtx);
skipping to change at line 142 skipping to change at line 144
/* ok, release mutex and resolve */ /* ok, release mutex and resolve */
pthread_mutex_unlock(&resolvemtx); pthread_mutex_unlock(&resolvemtx);
free(el); /* item saved, link elem now useless, freeing */ free(el); /* item saved, link elem now useless, freeing */
#ifdef FORCE_SINGLE_THREAD #ifdef FORCE_SINGLE_THREAD
/* if forced single thread, uses gethostbyaddr */ /* if forced single thread, uses gethostbyaddr */
result=0; result=0;
resultptr = gethostbyaddr (&curitem->ip.addr8, resultptr = gethostbyaddr (&curitem->ip.addr8,
address_len(curitem->ip.type), curitem->ip.type); address_len(curitem->ip.type), curitem->ip.type);
#else
/* full multithreading, use thread safe gethostbyaddr_r */
result = gethostbyaddr_r (&curitem->ip.addr8,
address_len(curitem->ip.type), curitem->ip.type,
&resultbuf, extrabuf, sizeof(extrabuf),
&resultptr, &errnovar);
if (result != 0 && errnovar == ERANGE)
g_my_critical("Insufficient memory allocated to gethostbyaddr_r\n");
#endif
if (request_stop_thread) if (request_stop_thread)
break; break;
/* resolving completed or failed, lock again and notify ip-cache */ /* resolving completed or failed, lock again and notify ip-cache */
pthread_mutex_lock(&resolvemtx); pthread_mutex_lock(&resolvemtx);
if (result || !resultptr) if (result || !resultptr)
ipcache_request_failed(curitem); ipcache_request_failed(curitem);
else else
ipcache_request_succeeded(curitem, 3600L*24L, resultptr->h_name); ipcache_request_succeeded(curitem, 3600L*24L, resultptr->h_name);
#else
/* full multithreading, use thread safe getnameinfo */
if (curitem->ip.type == AF_INET) {
memset(&sa, 0, sizeof sa);
sa.sin_family = curitem->ip.type;
g_assert(sizeof(sa.sin_addr) == sizeof(curitem->ip.addr_v4));
memmove(&sa.sin_addr, curitem->ip.addr_v4, sizeof sa.sin_addr);
saptr = (struct sockaddr *)&sa;
salen = sizeof sa;
} else {
memset(&sa6, 0, sizeof sa6);
sa6.sin6_family = curitem->ip.type;
g_assert(sizeof(sa6.sin6_addr) == sizeof(curitem->ip.addr_v6));
memmove(&sa6.sin6_addr, curitem->ip.addr_v6, sizeof sa6.sin6_addr);
saptr = (struct sockaddr *)&sa6;
salen = sizeof sa6;
}
result = getnameinfo(saptr, salen,
extrabuf, sizeof(extrabuf),
NULL, 0,
0);
if (result != 0 && result != EAI_AGAIN) {
g_my_critical("getnameinfo error %d (%s)\n",
result, gai_strerror(result));
}
if (request_stop_thread)
break;
/* resolving completed or failed, lock again and notify ip-cache */
pthread_mutex_lock(&resolvemtx);
if (result)
ipcache_request_failed(curitem);
else
ipcache_request_succeeded(curitem, 3600L*24L, extrabuf);
#endif
} }
pthread_mutex_unlock(&resolvemtx); pthread_mutex_unlock(&resolvemtx);
} }
return NULL; return NULL;
} }
static void start_threads() static void start_threads()
{ {
pthread_t curth; pthread_t curth;
 End of changes. 6 change blocks. 
13 lines changed or deleted 42 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)