diff options
author | Øyvind Harboe <oyvind.harboe@zylin.com> | 2010-09-27 08:48:31 +0200 |
---|---|---|
committer | Øyvind Harboe <oyvind.harboe@zylin.com> | 2010-10-01 10:21:33 +0200 |
commit | 6c137a2fc0bf53b9c0b8eda51e6f5361552b0112 (patch) | |
tree | 6adbd7dd5dc88bd6d21240b6668ea4a22ae92a89 /src/server/server.c | |
parent | cb2dba2c1257e0aa80edc9a171a9c5cd7b2822f8 (diff) |
server: specify port as a string
This will allow switching to using named pipes.
Split this out as a seperate commit to make changes
easier to follow.
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
Diffstat (limited to 'src/server/server.c')
-rw-r--r-- | src/server/server.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/server/server.c b/src/server/server.c index 1c556638..435ddbb7 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -238,6 +238,29 @@ int add_service(char *name, enum connection_type type, unsigned short port, int return ERROR_OK; } +int add_service_pipe(char *name, const char *port, int max_connections, + new_connection_handler_t new_connection_handler, input_handler_t input_handler, + connection_closed_handler_t connection_closed_handler, void *priv) +{ + enum connection_type type = CONNECTION_TCP; + long portnumber; + char *end; + strtol(port, &end, 0); + if (!*end) + { + if ((parse_long(port, &portnumber) == ERROR_OK) && (portnumber == 0)) + { + type = CONNECTION_PIPE; + } + } else + { + LOG_ERROR("Illegal port number %s", port); + return ERROR_FAIL; + } + return add_service(name, type, portnumber, max_connections, new_connection_handler, + input_handler, connection_closed_handler, priv); +} + static int remove_services(void) { struct service *c = services; @@ -250,6 +273,12 @@ static int remove_services(void) if (c->name) free(c->name); + if (c->type == CONNECTION_PIPE) + { + if (c->fd != -1) + close(c->fd); + } + if (c->priv) free(c->priv); @@ -591,3 +620,23 @@ SERVER_PORT_COMMAND() } return ERROR_OK; } + +SERVER_PIPE_COMMAND() +{ + switch (CMD_ARGC) { + case 0: + command_print(CMD_CTX, "%s", *out); + break; + case 1: + { + const char * t = strdup(CMD_ARGV[0]); + free((void *)*out); + *out = t; + break; + } + default: + return ERROR_INVALID_ARGUMENTS; + } + return ERROR_OK; +} + |