Browse Source

Retry binding the connector to the socket for up to 2 minutes

master
Con Kolivas 11 years ago
parent
commit
8be725bde6
  1. 20
      src/connector.c

20
src/connector.c

@ -329,6 +329,7 @@ int connector(proc_instance_t *pi)
ckpool_t *ckp = pi->ckp; ckpool_t *ckp = pi->ckp;
int sockd, ret = 0; int sockd, ret = 0;
conn_instance_t ci; conn_instance_t ci;
int tries = 0;
if (ckp->serverurl) { if (ckp->serverurl) {
if (!extract_sockaddr(ckp->serverurl, &url, &port)) { if (!extract_sockaddr(ckp->serverurl, &url, &port)) {
@ -336,11 +337,18 @@ int connector(proc_instance_t *pi)
ret = 1; ret = 1;
goto out; goto out;
} }
do {
sockd = bind_socket(url, port); sockd = bind_socket(url, port);
if (sockd > 0)
break;
LOGWARNING("Connector failed to bind to socket, retrying in 5s");
sleep(5);
} while (++tries < 25);
dealloc(url); dealloc(url);
dealloc(port); dealloc(port);
if (sockd < 0) { if (sockd < 0) {
LOGERR("Connector failed to bind to socket"); LOGERR("Connector failed to bind to socket for 2 minutes");
ret = 1; ret = 1;
goto out; goto out;
} }
@ -357,13 +365,21 @@ int connector(proc_instance_t *pi)
serv_addr.sin_family = AF_INET; serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
serv_addr.sin_port = htons(3333); serv_addr.sin_port = htons(3333);
do {
ret = bind(sockd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)); ret = bind(sockd, (struct sockaddr*)&serv_addr, sizeof(serv_addr));
if (!ret)
break;
LOGWARNING("Connector failed to bind to socket, retrying in 5s");
sleep(5);
} while (++tries < 25);
if (ret < 0) { if (ret < 0) {
LOGERR("Connector failed to bind to socket"); LOGERR("Connector failed to bind to socket for 2 minutes");
close(sockd); close(sockd);
goto out; goto out;
} }
} }
if (tries)
LOGWARNING("Connector successfully bound to socket");
ret = listen(sockd, 10); ret = listen(sockd, 10);
if (ret < 0) { if (ret < 0) {

Loading…
Cancel
Save