#define CONN_PORT 15828
#define CONN_MSG_SIZE 128
#define CONN_MSG_FMT "%04hx:%08x:%08x:%08x:%s"
-
+#define CONN_MAX_RETRY 10
#define LOGPRINTF if (verbose) printf
static void flush_evds(void)
.ai_socktype = SOCK_STREAM
};
char *service;
- int n;
+ int n, retry;
int sockfd = -1;
if (asprintf(&service, "%d", port) < 0)
return n;
}
- for (t = res; t; t = t->ai_next) {
- sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);
- if (sockfd >= 0) {
- if (!connect(sockfd, t->ai_addr, t->ai_addrlen))
- break;
- close(sockfd);
- sockfd = -1;
+ for (retry = CONN_MAX_RETRY; retry > 0; retry--) {
+ for (t = res; t; t = t->ai_next) {
+ sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);
+ if (sockfd >= 0) {
+ if (!connect(sockfd, t->ai_addr, t->ai_addrlen))
+ break;
+ close(sockfd);
+ sockfd = -1;
+ }
}
+ if (sockfd < 0)
+ sleep (1);
+ else
+ break;
}
freeaddrinfo(res);