From: Christian Pointner Date: Sat, 30 May 2009 02:36:27 +0000 (+0000) Subject: fixed new readline X-Git-Url: https://git.realraum.at/?a=commitdiff_plain;h=ff3d6b186df71348652f0c7dfbbef049e4cf4531;p=svn42.git fixed new readline --- diff --git a/door_daemon/client_list.c b/door_daemon/client_list.c index 01652c6..d989687 100644 --- a/door_daemon/client_list.c +++ b/door_daemon/client_list.c @@ -47,6 +47,7 @@ int client_add(client_t** first, int fd) new_client->fd = fd; new_client->status_listener = 0; new_client->next = NULL; + new_client->buffer.offset = 0; if(!(*first)) { *first = new_client; diff --git a/door_daemon/datatypes.h b/door_daemon/datatypes.h index 3cb3967..4075e73 100644 --- a/door_daemon/datatypes.h +++ b/door_daemon/datatypes.h @@ -39,6 +39,10 @@ struct buffer_struct { }; typedef struct buffer_struct buffer_t; -typedef char read_buffer_t[100]; +struct read_buffer_struct { + u_int32_t offset; + u_int8_t buf[100]; +}; +typedef struct read_buffer_struct read_buffer_t; #endif diff --git a/door_daemon/door_daemon.c b/door_daemon/door_daemon.c index 22068a0..00fbeb7 100644 --- a/door_daemon/door_daemon.c +++ b/door_daemon/door_daemon.c @@ -166,7 +166,7 @@ int process_cmd(const char* cmd, int fd, cmd_t **cmd_q, client_t* client_lst) } else { log_printf(WARNING, "unknown command '%s'", cmd); - return 1; + return 0; } char* param = strchr(cmd, ' '); if(param) @@ -222,24 +222,23 @@ int process_door(const char* str, int door_fd, cmd_t **cmd_q, client_t* client_l int nonblock_readline(read_buffer_t buffer, int fd, cmd_t** cmd_q, client_t* client_lst, int (*cb)(const char*, int, cmd_t**, client_t*)) { int ret = 0; - u_int32_t offset = 0; for(;;) { - ret = read(fd, &buffer[offset], 1); + ret = read(fd, &buffer.buf[buffer.offset], 1); if(!ret) return 2; else if(ret == -1 && errno == EAGAIN) return 0; - else + else if(ret < 0) break; - if(buffer[offset] == '\n') { - buffer[offset] = 0; - ret = (cb)(buffer, fd, cmd_q, client_lst); + if(buffer.buf[buffer.offset] == '\n') { + buffer.buf[buffer.offset] = 0; + ret = (cb)(buffer.buf, fd, cmd_q, client_lst); break; } - offset++; - if(offset >= sizeof(buffer)) { + buffer.offset++; + if(buffer.offset >= sizeof(buffer.buf)) { log_printf(DEBUG, "string too long (fd=%d)", fd); return 0; } @@ -261,6 +260,7 @@ int main_loop(int door_fd, int cmd_listen_fd) client_t* client_lst = NULL; read_buffer_t door_buffer; + door_buffer.offset = 0; int sig_fd = signal_init(); if(sig_fd < 0)