Browse Source

Handle early exiting of connector receiver and sender threads

master
Con Kolivas 10 years ago
parent
commit
1fe5373c87
  1. 18
      src/connector.c

18
src/connector.c

@ -30,6 +30,8 @@ struct connector_instance {
int serverfd; int serverfd;
int nfds; int nfds;
bool accept; bool accept;
pthread_t pth_sender;
pthread_t pth_receiver;
}; };
typedef struct connector_instance conn_instance_t; typedef struct connector_instance conn_instance_t;
@ -546,6 +548,17 @@ static int connector_loop(proc_instance_t *pi, conn_instance_t *ci)
LOGWARNING("%s connector ready", ckp->name); LOGWARNING("%s connector ready", ckp->name);
retry: retry:
if (unlikely(!pthread_tryjoin_np(ci->pth_sender, NULL))) {
LOGEMERG("Connector sender thread shutdown, exiting");
ret = 1;
goto out;
}
if (unlikely(!pthread_tryjoin_np(ci->pth_receiver, NULL))) {
LOGEMERG("Connector receiver thread shutdown, exiting");
ret = 1;
goto out;
}
Close(sockd); Close(sockd);
sockd = accept(us->sockd, NULL, NULL); sockd = accept(us->sockd, NULL, NULL);
if (sockd < 0) { if (sockd < 0) {
@ -657,7 +670,6 @@ out:
int connector(proc_instance_t *pi) int connector(proc_instance_t *pi)
{ {
pthread_t pth_sender, pth_receiver;
char *url = NULL, *port = NULL; char *url = NULL, *port = NULL;
ckpool_t *ckp = pi->ckp; ckpool_t *ckp = pi->ckp;
int sockd, ret = 0; int sockd, ret = 0;
@ -734,8 +746,8 @@ int connector(proc_instance_t *pi)
ci.nfds = 0; ci.nfds = 0;
mutex_init(&sender_lock); mutex_init(&sender_lock);
cond_init(&sender_cond); cond_init(&sender_cond);
create_pthread(&pth_sender, sender, &ci); create_pthread(&ci.pth_sender, sender, &ci);
create_pthread(&pth_receiver, receiver, &ci); create_pthread(&ci.pth_receiver, receiver, &ci);
ret = connector_loop(pi, &ci); ret = connector_loop(pi, &ci);
out: out:

Loading…
Cancel
Save