mirror of
https://github.com/radio95-rnt/rds95.git
synced 2026-07-29 16:29:17 +02:00
remove delimeters
This commit is contained in:
+8
-41
@@ -33,7 +33,6 @@ int open_udp_server(int port) {
|
||||
|
||||
void poll_udp_server() {
|
||||
static char buf[BUF_SIZE];
|
||||
static char cmd_buf[BUF_SIZE];
|
||||
static char cmd_output[BUF_SIZE];
|
||||
|
||||
if (poll(&poller, 1, UDP_READ_TIMEOUT_MS) <= 0) return;
|
||||
@@ -41,49 +40,17 @@ void poll_udp_server() {
|
||||
|
||||
memset(buf, 0, BUF_SIZE);
|
||||
client_len = sizeof(client_addr);
|
||||
ssize_t bytes_read = recvfrom(sockfd, buf, BUF_SIZE - 1, 0, (struct sockaddr *)&client_addr, &client_len);
|
||||
ssize_t bytes_read = recvfrom(sockfd, buf, BUF_SIZE - 1, 0, (struct sockaddr *)&client_addr, &client_len);
|
||||
if (bytes_read <= 0) return;
|
||||
|
||||
size_t start = 0;
|
||||
memset(cmd_output, 0, BUF_SIZE);
|
||||
size_t out_len = 0;
|
||||
run_lua(buf, bytes_read, cmd_output, &out_len);
|
||||
|
||||
for (ssize_t i = 0; i < bytes_read; i++) {
|
||||
if (buf[i] == '\n' || (unsigned char)buf[i] == 0xFF) {
|
||||
size_t len = i - start;
|
||||
|
||||
if (len > 0 && len < BUF_SIZE) {
|
||||
memset(cmd_buf, 0, BUF_SIZE);
|
||||
memcpy(cmd_buf, buf + start, len);
|
||||
memset(cmd_output, 0, BUF_SIZE);
|
||||
|
||||
size_t out_len = 0;
|
||||
run_lua(cmd_buf, len, cmd_output, &out_len);
|
||||
|
||||
if (out_len > 0 &&
|
||||
sendto(sockfd, cmd_output, out_len, 0,
|
||||
(struct sockaddr *)&client_addr, client_len) == -1) {
|
||||
perror("sendto");
|
||||
}
|
||||
}
|
||||
|
||||
start = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (start < (size_t)bytes_read) {
|
||||
size_t len = bytes_read - start;
|
||||
|
||||
if (len > 0 && len < BUF_SIZE) {
|
||||
memcpy(cmd_buf, buf + start, len);
|
||||
|
||||
size_t out_len = 0;
|
||||
run_lua(cmd_buf, len, cmd_output, &out_len);
|
||||
|
||||
if (out_len > 0 &&
|
||||
sendto(sockfd, cmd_output, out_len, 0,
|
||||
(struct sockaddr *)&client_addr, client_len) == -1) {
|
||||
perror("sendto");
|
||||
}
|
||||
}
|
||||
if (out_len > 0 &&
|
||||
sendto(sockfd, cmd_output, out_len, 0,
|
||||
(struct sockaddr *)&client_addr, client_len) == -1) {
|
||||
perror("sendto");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user