#include "netpoll.hpp"
#include "util.hpp"
-#define container_of(ptr, type, member) ((type *)((char *)(ptr) - offsetof(type, member)))
-
namespace netpoll {
struct pollfd {
void *assoc;
}
static void cb(uv_poll_t *handle, int status, int events)
{
- pollfd *pfd = container_of(handle, pollfd, handle);
+ pollfd *pfd = static_cast<pollfd *>(handle->data);
if (status == 0) {
pfd->revents = events;
}
pfd->assoc = assoc;
pfd->type = type;
uv_poll_init_socket(uvloop, &pfd->handle, pfd->fd);
+ pfd->handle.data = pfd;
}
void del_and_close(uv_os_sock_t fd)
{
auto it = search(fd);
- pollfd *pfd = *it;
- uv_close((uv_handle_t *)&pfd->handle, [](uv_handle_t *handle){
- pollfd *pfd = container_of(handle, pollfd, handle);
+ uv_close((uv_handle_t *)&(*it)->handle, [](uv_handle_t *handle){
+ pollfd *pfd = static_cast<pollfd *>(handle->data);
close(pfd->fd);
delete pfd;
});