mirror of
https://github.com/openstreetmap/mod_tile.git
synced 2025-08-03 07:49:53 +00:00
Improve backwards and forward compatibility for renderd protocol v3/v2
This commit is contained in:
12
Makefile.am
12
Makefile.am
@ -13,19 +13,19 @@ noinst_PROGRAMS = gen_tile_test
|
|||||||
man_MANS = docs/renderd.8 docs/render_expired.1 docs/render_list.1 docs/render_old.1 docs/render_speedtest.1
|
man_MANS = docs/renderd.8 docs/render_expired.1 docs/render_list.1 docs/render_old.1 docs/render_speedtest.1
|
||||||
|
|
||||||
renderddir = $(sysconfdir)
|
renderddir = $(sysconfdir)
|
||||||
renderd_SOURCES = src/daemon.c src/daemon_compat.c src/gen_tile.cpp src/sys_utils.c src/request_queue.c src/cache_expire.c src/metatile.cpp src/parameterize_style.cpp $(STORE_SOURCES) iniparser3.0b/libiniparser.la
|
renderd_SOURCES = src/daemon.c src/daemon_compat.c src/gen_tile.cpp src/sys_utils.c src/request_queue.c src/cache_expire.c src/metatile.cpp src/parameterize_style.cpp src/protocol_helper.c $(STORE_SOURCES) iniparser3.0b/libiniparser.la
|
||||||
renderd_LDADD = $(FT2_LIBS) $(PTHREAD_CFLAGS) $(MAPNIK_LDFLAGS) $(BOOST_LDFLAGS) $(ICU_LDFLAGS) $(STORE_LDFLAGS) -Liniparser3.0b/.libs -liniparser
|
renderd_LDADD = $(FT2_LIBS) $(PTHREAD_CFLAGS) $(MAPNIK_LDFLAGS) $(BOOST_LDFLAGS) $(ICU_LDFLAGS) $(STORE_LDFLAGS) -Liniparser3.0b/.libs -liniparser
|
||||||
renderd_DATA = renderd.conf
|
renderd_DATA = renderd.conf
|
||||||
render_speedtest_SOURCES = src/speedtest.cpp src/render_submit_queue.c src/sys_utils.c
|
render_speedtest_SOURCES = src/speedtest.cpp src/protocol_helper.c src/render_submit_queue.c src/sys_utils.c
|
||||||
render_speedtest_LDADD = $(PTHREAD_CFLAGS)
|
render_speedtest_LDADD = $(PTHREAD_CFLAGS)
|
||||||
render_list_SOURCES = src/render_list.c src/sys_utils.c src/render_submit_queue.c $(STORE_SOURCES)
|
render_list_SOURCES = src/render_list.c src/sys_utils.c src/protocol_helper.c src/render_submit_queue.c $(STORE_SOURCES)
|
||||||
render_list_LDADD = $(PTHREAD_CFLAGS) $(STORE_LDFLAGS)
|
render_list_LDADD = $(PTHREAD_CFLAGS) $(STORE_LDFLAGS)
|
||||||
render_expired_SOURCES = src/render_expired.c src/render_submit_queue.c src/sys_utils.c $(STORE_SOURCES)
|
render_expired_SOURCES = src/render_expired.c src/protocol_helper.c src/render_submit_queue.c src/sys_utils.c $(STORE_SOURCES)
|
||||||
render_expired_LDADD = $(PTHREAD_CFLAGS) $(STORE_LDFLAGS)
|
render_expired_LDADD = $(PTHREAD_CFLAGS) $(STORE_LDFLAGS)
|
||||||
render_old_SOURCES = src/store_file_utils.c src/render_old.c src/sys_utils.c src/render_submit_queue.c
|
render_old_SOURCES = src/store_file_utils.c src/render_old.c src/sys_utils.c src/protocol_helper.c src/render_submit_queue.c
|
||||||
render_old_LDADD = $(PTHREAD_CFLAGS)
|
render_old_LDADD = $(PTHREAD_CFLAGS)
|
||||||
#convert_meta_SOURCES = src/dir_utils.c src/store.c src/convert_meta.c
|
#convert_meta_SOURCES = src/dir_utils.c src/store.c src/convert_meta.c
|
||||||
gen_tile_test_SOURCES = src/gen_tile_test.cpp src/metatile.cpp src/request_queue.c src/daemon.c src/daemon_compat.c src/gen_tile.cpp src/sys_utils.c src/cache_expire.c src/parameterize_style.cpp $(STORE_SOURCES) iniparser3.0b/libiniparser.la
|
gen_tile_test_SOURCES = src/gen_tile_test.cpp src/metatile.cpp src/request_queue.c src/protocol_helper.c src/daemon.c src/daemon_compat.c src/gen_tile.cpp src/sys_utils.c src/cache_expire.c src/parameterize_style.cpp $(STORE_SOURCES) iniparser3.0b/libiniparser.la
|
||||||
gen_tile_test_CFLAGS = -DMAIN_ALREADY_DEFINED $(PTHREAD_CFLAGS)
|
gen_tile_test_CFLAGS = -DMAIN_ALREADY_DEFINED $(PTHREAD_CFLAGS)
|
||||||
gen_tile_test_LDADD = $(FT2_LIBS) $(MAPNIK_LDFLAGS) $(BOOST_LDFLAGS) $(ICU_LDFLAGS) $(STORE_LDFLAGS) -Liniparser3.0b/.libs -liniparser
|
gen_tile_test_LDADD = $(FT2_LIBS) $(MAPNIK_LDFLAGS) $(BOOST_LDFLAGS) $(ICU_LDFLAGS) $(STORE_LDFLAGS) -Liniparser3.0b/.libs -liniparser
|
||||||
|
|
||||||
|
17
includes/protocol_helper.h
Normal file
17
includes/protocol_helper.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#ifndef DAEMONHELPER_H
|
||||||
|
#define DAEMONHELPER_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "protocol.h"
|
||||||
|
|
||||||
|
int send_cmd(struct protocol * cmd, int fd);
|
||||||
|
int recv_cmd(struct protocol * cmd, int fd);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
64
src/daemon.c
64
src/daemon.c
@ -23,6 +23,7 @@
|
|||||||
#include "daemon.h"
|
#include "daemon.h"
|
||||||
#include "gen_tile.h"
|
#include "gen_tile.h"
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
|
#include "protocol_helper.h"
|
||||||
#include "request_queue.h"
|
#include "request_queue.h"
|
||||||
|
|
||||||
#define PIDFILE "/var/run/renderd/renderd.pid"
|
#define PIDFILE "/var/run/renderd/renderd.pid"
|
||||||
@ -59,6 +60,9 @@ static const char *cmdStr(enum protoCmd c)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void send_response(struct item *item, enum protoCmd rsp, int render_time) {
|
void send_response(struct item *item, enum protoCmd rsp, int render_time) {
|
||||||
struct protocol *req = &item->req;
|
struct protocol *req = &item->req;
|
||||||
struct item *prev;
|
struct item *prev;
|
||||||
@ -71,24 +75,8 @@ void send_response(struct item *item, enum protoCmd rsp, int render_time) {
|
|||||||
if ((item->fd != FD_INVALID) && ((req->cmd == cmdRender) || (req->cmd == cmdRenderPrio) || (req->cmd == cmdRenderBulk))) {
|
if ((item->fd != FD_INVALID) && ((req->cmd == cmdRender) || (req->cmd == cmdRenderPrio) || (req->cmd == cmdRenderBulk))) {
|
||||||
req->cmd = rsp;
|
req->cmd = rsp;
|
||||||
//fprintf(stderr, "Sending message %s to %d\n", cmdStr(rsp), item->fd);
|
//fprintf(stderr, "Sending message %s to %d\n", cmdStr(rsp), item->fd);
|
||||||
syslog(LOG_DEBUG, "DEBUG: Sending reply with protocol version %i\n", req->ver);
|
|
||||||
switch (req->ver) {
|
send_cmd(req, item->fd);
|
||||||
case 1:
|
|
||||||
ret = send(item->fd, req, sizeof(struct protocol_v1), 0);
|
|
||||||
if (ret != sizeof(struct protocol_v1))
|
|
||||||
perror("send error during send_done");
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
ret = send(item->fd, req, sizeof(struct protocol_v2), 0);
|
|
||||||
if (ret != sizeof(struct protocol_v2))
|
|
||||||
perror("send error during send_done");
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
ret = send(item->fd, req, sizeof(*req), 0);
|
|
||||||
if (ret != sizeof(*req))
|
|
||||||
perror("send error during send_done");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
prev = item;
|
prev = item;
|
||||||
@ -226,7 +214,7 @@ void process_loop(int listen_fd)
|
|||||||
memset(&cmd,0,sizeof(cmd));
|
memset(&cmd,0,sizeof(cmd));
|
||||||
|
|
||||||
// TODO: to get highest performance we should loop here until we get EAGAIN
|
// TODO: to get highest performance we should loop here until we get EAGAIN
|
||||||
ret = recv(fd, &cmd, sizeof(struct protocol_v1), MSG_DONTWAIT);
|
ret = recv_cmd(&cmd, fd);
|
||||||
if (ret < 1) {
|
if (ret < 1) {
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
@ -236,37 +224,13 @@ void process_loop(int listen_fd)
|
|||||||
connections[j] = connections[j+1];
|
connections[j] = connections[j+1];
|
||||||
request_queue_clear_requests_by_fd(render_request_queue, fd);
|
request_queue_clear_requests_by_fd(render_request_queue, fd);
|
||||||
close(fd);
|
close(fd);
|
||||||
} else {
|
} else {
|
||||||
syslog(LOG_DEBUG, "DEBUG: Got incoming request with protocol version %i\n", cmd.ver);
|
enum protoCmd rsp = rx_request(&cmd, fd);
|
||||||
switch (cmd.ver) {
|
|
||||||
case 2: ret += recv(fd, ((void*)&cmd) + sizeof(struct protocol_v1), sizeof(struct protocol_v2) + 1 - sizeof(struct protocol_v1), MSG_DONTWAIT);
|
|
||||||
break;
|
|
||||||
case 3: ret += recv(fd, ((void*)&cmd) + sizeof(struct protocol_v1), sizeof(struct protocol) - sizeof(struct protocol_v1), MSG_DONTWAIT);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if ((ret == sizeof(cmd)) || (ret == sizeof(struct protocol_v1)) || (ret == sizeof(struct protocol_v2))) {
|
|
||||||
enum protoCmd rsp = rx_request(&cmd, fd);
|
|
||||||
|
|
||||||
if (rsp == cmdNotDone) {
|
if (rsp == cmdNotDone) {
|
||||||
cmd.cmd = rsp;
|
cmd.cmd = rsp;
|
||||||
syslog(LOG_DEBUG, "DEBUG: Sending NotDone response(%d)\n", rsp);
|
syslog(LOG_DEBUG, "DEBUG: Sending NotDone response(%d)\n", rsp);
|
||||||
ret = send(fd, &cmd, sizeof(cmd), 0);
|
ret = send_cmd(&cmd, fd);
|
||||||
if (ret != sizeof(cmd))
|
|
||||||
perror("response send error");
|
|
||||||
}
|
|
||||||
} else if (!ret) {
|
|
||||||
int j;
|
|
||||||
|
|
||||||
num_connections--;
|
|
||||||
syslog(LOG_DEBUG, "DEBUG: Connection %d, fd %d closed, now %d left\n", i, fd, num_connections);
|
|
||||||
for (j=i; j < num_connections; j++)
|
|
||||||
connections[j] = connections[j+1];
|
|
||||||
request_queue_clear_requests_by_fd(render_request_queue, fd);
|
|
||||||
close(fd);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
syslog(LOG_ERR, "Recv Error on fd %d (%s). Read %i bytes", fd, strerror(errno), ret);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -555,7 +519,7 @@ void *slave_thread(void * arg) {
|
|||||||
syslog(LOG_INFO,
|
syslog(LOG_INFO,
|
||||||
"Dispatching request to slave thread on fd %i", pfd);
|
"Dispatching request to slave thread on fd %i", pfd);
|
||||||
do {
|
do {
|
||||||
ret_size = send(pfd, req_slave, sizeof(struct protocol), 0);
|
ret_size = send_cmd(req_slave, pfd);
|
||||||
|
|
||||||
if (ret_size == sizeof(struct protocol)) {
|
if (ret_size == sizeof(struct protocol)) {
|
||||||
//correctly sent command to slave
|
//correctly sent command to slave
|
||||||
|
@ -257,6 +257,9 @@ static int request_tile(request_rec *r, struct protocol *cmd, int renderImmediat
|
|||||||
strerror(errno));
|
strerror(errno));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (resp.ver == 3) {
|
||||||
|
ret += recv(fd, ((void*)&resp) + sizeof(struct protocol_v2), sizeof(struct protocol) - sizeof(struct protocol_v2), 0);
|
||||||
|
}
|
||||||
|
|
||||||
if (cmd->x == resp.x && cmd->y == resp.y && cmd->z == resp.z && !strcmp(cmd->xmlname, resp.xmlname)) {
|
if (cmd->x == resp.x && cmd->y == resp.y && cmd->z == resp.z && !strcmp(cmd->xmlname, resp.xmlname)) {
|
||||||
close(fd);
|
close(fd);
|
||||||
|
57
src/protocol_helper.c
Normal file
57
src/protocol_helper.c
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
#include "protocol.h"
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <syslog.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int send_cmd(struct protocol * cmd, int fd) {
|
||||||
|
int ret;
|
||||||
|
syslog(LOG_DEBUG, "DEBUG: Sending render cmd with protocol version %i\n", cmd->ver);
|
||||||
|
switch (cmd->ver) {
|
||||||
|
case 1:
|
||||||
|
ret = send(fd, cmd, sizeof(struct protocol_v1), 0);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
ret = send(fd, cmd, sizeof(struct protocol_v2), 0);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
ret = send(fd, cmd, sizeof(struct protocol), 0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ((ret != sizeof(struct protocol)) && (ret != sizeof(struct protocol_v2)) && (ret != sizeof(struct protocol_v1))) {
|
||||||
|
perror("send error");
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int recv_cmd(struct protocol * cmd, int fd) {
|
||||||
|
int ret, ret2;
|
||||||
|
memset(cmd,0,sizeof(*cmd));
|
||||||
|
ret = recv(fd, cmd, sizeof(struct protocol_v1), MSG_DONTWAIT);
|
||||||
|
if (ret < 1) {
|
||||||
|
return -1;
|
||||||
|
} else if (ret < sizeof(struct protocol_v1)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
syslog(LOG_DEBUG, "DEBUG: Got incoming request with protocol version %i\n", cmd->ver);
|
||||||
|
switch (cmd->ver) {
|
||||||
|
case 2: ret2 = recv(fd, ((void*)cmd) + sizeof(struct protocol_v1), sizeof(struct protocol_v2) - sizeof(struct protocol_v1), MSG_DONTWAIT);
|
||||||
|
break;
|
||||||
|
case 3: ret2 = recv(fd, ((void*)cmd) + sizeof(struct protocol_v1), sizeof(struct protocol) - sizeof(struct protocol_v1), MSG_DONTWAIT);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret2 < 1) {
|
||||||
|
syslog(LOG_WARNING, "WARNING: Socket prematurely closed: %i\n", fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret += ret2;
|
||||||
|
|
||||||
|
if ((ret == sizeof(struct protocol)) || (ret == sizeof(struct protocol_v1)) || (ret == sizeof(struct protocol_v2))) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
syslog(LOG_WARNING, "WARNING: Socket read wrong number of bytes: %i -> %li, %li\n", ret, sizeof(struct protocol_v2), sizeof(struct protocol));
|
||||||
|
return 0;
|
||||||
|
}
|
@ -11,6 +11,7 @@
|
|||||||
#include "render_submit_queue.h"
|
#include "render_submit_queue.h"
|
||||||
#include "sys_utils.h"
|
#include "sys_utils.h"
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
|
#include "protocol_helper.h"
|
||||||
#include "render_config.h"
|
#include "render_config.h"
|
||||||
|
|
||||||
#define QMAX 32
|
#define QMAX 32
|
||||||
@ -70,19 +71,14 @@ static int process(struct protocol * cmd, int fd)
|
|||||||
t1 = tim.tv_sec*1000+(tim.tv_usec/1000);
|
t1 = tim.tv_sec*1000+(tim.tv_usec/1000);
|
||||||
|
|
||||||
//printf("Sending request\n");
|
//printf("Sending request\n");
|
||||||
ret = send(fd, cmd, sizeof(*cmd), 0);
|
if (send_cmd(cmd, fd) < 1) {
|
||||||
if (ret != sizeof(*cmd)) {
|
|
||||||
perror("send error");
|
perror("send error");
|
||||||
}
|
};
|
||||||
|
|
||||||
//printf("Waiting for response\n");
|
//printf("Waiting for response\n");
|
||||||
bzero(&rsp, sizeof(rsp));
|
bzero(&rsp, sizeof(rsp));
|
||||||
ret = recv(fd, &rsp, sizeof(rsp), 0);
|
ret = recv_cmd(&rsp, fd);
|
||||||
if (ret != sizeof(rsp))
|
if (ret < 1) return 0;
|
||||||
{
|
|
||||||
perror("recv error");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
//printf("Got response\n");
|
//printf("Got response\n");
|
||||||
|
|
||||||
if (rsp.cmd != cmdDone)
|
if (rsp.cmd != cmdDone)
|
||||||
|
Reference in New Issue
Block a user