mirror of
https://github.com/radio95-rnt/rds95.git
synced 2026-07-31 01:09:17 +02:00
this commit is bad
This commit is contained in:
+33
-33
@@ -8,43 +8,43 @@ static int fd;
|
||||
static struct pollfd poller;
|
||||
|
||||
int open_control_pipe(char *filename) {
|
||||
fd = open(filename, O_RDONLY | O_NONBLOCK);
|
||||
if (fd == -1) return -1;
|
||||
|
||||
poller.fd = fd;
|
||||
poller.events = POLLIN;
|
||||
return 0;
|
||||
fd = open(filename, O_RDONLY | O_NONBLOCK);
|
||||
if (fd == -1) return -1;
|
||||
|
||||
poller.fd = fd;
|
||||
poller.events = POLLIN;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void poll_control_pipe(RDSModulator* mod) {
|
||||
static char pipe_buf[CTL_BUFFER_SIZE];
|
||||
static char cmd_buf[CMD_BUFFER_SIZE];
|
||||
int bytes_read;
|
||||
char *token;
|
||||
|
||||
if (poll(&poller, 1, READ_TIMEOUT_MS) <= 0) return;
|
||||
if (!(poller.revents & POLLIN)) return;
|
||||
|
||||
memset(pipe_buf, 0, CTL_BUFFER_SIZE);
|
||||
bytes_read = read(fd, pipe_buf, CTL_BUFFER_SIZE - 1);
|
||||
|
||||
if (bytes_read <= 0) return;
|
||||
|
||||
token = strtok((char *)pipe_buf, "\r\n");
|
||||
if(token == NULL) token = strtok((char *)pipe_buf, "\x1A");
|
||||
while (token != NULL) {
|
||||
size_t cmd_len = strlen(token);
|
||||
if (cmd_len > 0 && cmd_len < CMD_BUFFER_SIZE) {
|
||||
memset(cmd_buf, 0, CMD_BUFFER_SIZE);
|
||||
strncpy((char *)cmd_buf, token, CMD_BUFFER_SIZE - 1);
|
||||
process_ascii_cmd(mod, cmd_buf);
|
||||
}
|
||||
token = strtok(NULL, "\r\n");
|
||||
if(token == NULL) token = strtok(NULL, "\x1A");
|
||||
}
|
||||
static char pipe_buf[CTL_BUFFER_SIZE];
|
||||
static char cmd_buf[CMD_BUFFER_SIZE];
|
||||
int bytes_read;
|
||||
char *token;
|
||||
|
||||
if (poll(&poller, 1, READ_TIMEOUT_MS) <= 0) return;
|
||||
if (!(poller.revents & POLLIN)) return;
|
||||
|
||||
memset(pipe_buf, 0, CTL_BUFFER_SIZE);
|
||||
bytes_read = read(fd, pipe_buf, CTL_BUFFER_SIZE - 1);
|
||||
|
||||
if (bytes_read <= 0) return;
|
||||
|
||||
token = strtok((char *)pipe_buf, "\r\n");
|
||||
if(token == NULL) token = strtok((char *)pipe_buf, "\x1A");
|
||||
while (token != NULL) {
|
||||
size_t cmd_len = strlen(token);
|
||||
if (cmd_len > 0 && cmd_len < CMD_BUFFER_SIZE) {
|
||||
memset(cmd_buf, 0, CMD_BUFFER_SIZE);
|
||||
strncpy((char *)cmd_buf, token, CMD_BUFFER_SIZE - 1);
|
||||
process_ascii_cmd(mod, cmd_buf);
|
||||
}
|
||||
token = strtok(NULL, "\r\n");
|
||||
if(token == NULL) token = strtok(NULL, "\x1A");
|
||||
}
|
||||
}
|
||||
|
||||
void close_control_pipe() {
|
||||
if (fd > 0) close(fd);
|
||||
fd = -1;
|
||||
if (fd > 0) close(fd);
|
||||
fd = -1;
|
||||
}
|
||||
Reference in New Issue
Block a user