Commit 17fdb597 authored by Tom Hughes's avatar Tom Hughes Committed by ǝɹʇʇɐʃǝ◖ xıʃǝɟ
Browse files

Make render_list reconnect if the renderd connection is lost

parent a9e49577
......@@ -222,13 +222,10 @@ void enqueue(const char *xmlname, int x, int y, int z)
pthread_mutex_unlock(&qLock);
}
void *thread_main(void *arg)
int make_connection(const char *spath)
{
const char *spath = (const char *)arg;
int fd;
struct sockaddr_un addr;
struct protocol * cmd;
fd = socket(PF_UNIX, SOCK_STREAM, 0);
......@@ -242,19 +239,44 @@ void *thread_main(void *arg)
strncpy(addr.sun_path, spath, sizeof(addr.sun_path) - 1);
if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
fprintf(stderr, "socket connect failed for: %s\n", spath);
close(fd);
return -1;
}
return fd;
}
void *thread_main(void *arg)
{
const char *spath = (const char *)arg;
int fd = make_connection(spath);
if (fd < 0) {
fprintf(stderr, "socket connect failed for: %s\n", spath);
return NULL;
}
while (1) {
struct protocol * cmd;
check_load();
if (!(cmd = fetch())) {
break;
}
process(cmd, fd);
if (process(cmd, fd) < 1) {
fprintf(stderr, "connection to renderd lost");
close(fd);
fd = -1;
while (fd < 0) {
fprintf(stderr, "sleeping for 30 seconds");
sleep(30);
fprintf(stderr, "attempting to reconnect");
fd = make_connection(spath);
}
}
free(cmd);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment