upsilon/software/src/main.c

59 lines
1.0 KiB
C
Raw Normal View History

2022-07-13 12:07:03 -04:00
#include <zephyr/zephyr.h>
2022-09-16 18:01:34 -04:00
#include <errno.h>
#include <zephyr/net/socket.h>
2022-07-13 12:07:03 -04:00
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
2022-09-16 18:01:34 -04:00
#include "sock.h"
LOG_MODULE_REGISTER(main);
#define PORT 6626
enum fds {
CLIENT_FD,
SCANDATA_FD,
MAXFDS
};
static void
process_client(int cli)
{
struct zsock_pollfd fds[MAXFDS] = {0};
struct clireadbuf readbuf = {0};
client_buf_reset(&readbuf);
fds[CLIENT_FD].fd = cli;
fds[CLIENT_FD].events = ZSOCK_POLLIN;
// Currently not used
fds[SCANDATA_FD].fd = -1;
while (zsock_poll(fds, MAXFDS, 0) >= 0) {
if (fds[CLIENT_FD].revents | POLLIN) {
if (!client_read_into_buf(cli, &readbuf)) {
INFO_WRN("client_read_into_buf: %d", errno);
goto cleanup;
}
if (readbuf.st == MSG_READY) {
msg_parse_dispatch(cli, &readbuf);
client_buf_reset(&buf);
}
}
}
cleanup:
}
2022-07-13 12:07:03 -04:00
void
main(void)
{
2022-09-16 18:01:34 -04:00
int srv = server_init_sock(PORT);
2022-07-13 12:07:03 -04:00
for (;;) {
2022-09-16 18:01:34 -04:00
int cli = server_get_client(server_sock);
process_client(cli);
LOG_INF("Closing client socket");
zsock_close(cli);
2022-07-13 12:07:03 -04:00
}
}