summaryrefslogtreecommitdiff
path: root/switchctl.c
diff options
context:
space:
mode:
Diffstat (limited to 'switchctl.c')
-rw-r--r--switchctl.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/switchctl.c b/switchctl.c
index 9b704bb..59f7e8d 100644
--- a/switchctl.c
+++ b/switchctl.c
@@ -559,6 +559,35 @@ int process_cmd(const char* cmd, int fd, cmd_t **cmd_q, client_t* client_lst, op
return 0;
}
+int nonblock_recvline(read_buffer_t* buffer, int fd, cmd_t** cmd_q, client_t* client_lst, options_t* opt)
+{
+ int ret = 0;
+ for(;;) {
+ ret = recv(fd, &buffer->buf[buffer->offset], 1, 0);
+ if(!ret)
+ return 2;
+ if(ret == -1 && errno == EAGAIN)
+ return 0;
+ else if(ret < 0)
+ break;
+
+ if(buffer->buf[buffer->offset] == '\n') {
+ buffer->buf[buffer->offset] = 0;
+ ret = process_cmd(buffer->buf, fd, cmd_q, client_lst, opt);
+ buffer->offset = 0;
+ break;
+ }
+
+ buffer->offset++;
+ if(buffer->offset >= sizeof(buffer->buf)) {
+ log_printf(DEBUG, "string too long (fd=%d)", fd);
+ buffer->offset = 0;
+ return 0;
+ }
+ }
+
+ return ret;
+}
#define SEND_TO_LISTENER(STRING, LEN, FLAG) \
if(!strncmp(buffer->buf, STRING, LEN)) { \