#include "core/poll.h"
#include "mem/sys.h"
void ray_poll_exit(ray_poll_t* poll, int64_t code)
{
if (poll) poll->code = code;
}
ray_selector_t* ray_poll_get(ray_poll_t* poll, int64_t id)
{
if (!poll || id < 0 || (uint32_t)id >= poll->n_sels)
return NULL;
return poll->sels[id];
}
ray_poll_buf_t* ray_poll_buf_new(int64_t size)
{
ray_poll_buf_t* buf = (ray_poll_buf_t*)ray_sys_alloc(
sizeof(ray_poll_buf_t) + (size_t)size);
if (!buf) return NULL;
buf->next = NULL;
buf->size = size;
buf->offset = 0;
return buf;
}
void ray_poll_buf_free(ray_poll_buf_t* buf)
{
while (buf) {
ray_poll_buf_t* next = buf->next;
ray_sys_free(buf);
buf = next;
}
}
void ray_poll_rx_request(ray_poll_t* poll, ray_selector_t* sel, int64_t size)
{
(void)poll;
if (sel->rx.buf) {
if (sel->rx.buf->size >= size) {
sel->rx.buf->offset = 0;
sel->rx.buf->size = size;
return;
}
ray_poll_buf_free(sel->rx.buf);
}
sel->rx.buf = ray_poll_buf_new(size);
}