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"
|
2023-01-01 16:10:02 -05:00
|
|
|
#include "buf.h"
|
|
|
|
|
2022-09-16 18:01:34 -04:00
|
|
|
LOG_MODULE_REGISTER(main);
|
|
|
|
|
|
|
|
static void
|
|
|
|
process_client(int cli)
|
|
|
|
{
|
2023-01-01 16:10:02 -05:00
|
|
|
enum fds {
|
|
|
|
CLIENT_FD,
|
|
|
|
SCANDATA_FD,
|
|
|
|
MAXFDS
|
|
|
|
};
|
2022-09-16 18:01:34 -04:00
|
|
|
struct zsock_pollfd fds[MAXFDS] = {0};
|
|
|
|
|
|
|
|
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) {
|
2023-01-01 16:10:02 -05:00
|
|
|
if (fds[CLIENT_FD].revents | POLLIN)
|
|
|
|
client_parse(cli);
|
2022-09-16 18:01:34 -04:00
|
|
|
}
|
|
|
|
}
|
2022-07-13 12:07:03 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
main(void)
|
|
|
|
{
|
2023-03-03 03:06:50 -05:00
|
|
|
int srv = server_init_sock(6626);
|
2022-09-16 18:01:34 -04:00
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|