Skip to content

Commit

Permalink
fixes warning
Browse files Browse the repository at this point in the history
  • Loading branch information
actboy168 committed Apr 28, 2024
1 parent b222516 commit b4e9d05
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
1 change: 1 addition & 0 deletions bee/net/bpoll.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace bee::net {
};
using bpoll_handle = uintptr_t;
#endif
constexpr bpoll_handle invalid_bpoll_handle = (bpoll_handle)-1;

bpoll_handle bpoll_create() noexcept;
bool bpoll_close(bpoll_handle handle) noexcept;
Expand Down
15 changes: 7 additions & 8 deletions bee/net/bpoll_osx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace bee::net {
constexpr uint16_t KQUEUE_STATE_REGISTERED = 0x0001;
constexpr uint16_t KQUEUE_STATE_EPOLLRDHUP = 0x0002;
constexpr bpoll_event AllowBpollEvents = bpoll_event::in | bpoll_event::out | bpoll_event::hup | bpoll_event::rdhup | bpoll_event::err;
constexpr bpoll_handle InvalidHandle = (bpoll_handle)-1;

template <typename T>
static bool invalid_fd(T fd) noexcept {
Expand Down Expand Up @@ -164,19 +163,19 @@ namespace bee::net {
bpoll_handle bpoll_create() noexcept {
int kq = ::kqueue();
if (kq == -1) {
return InvalidHandle;
return invalid_bpoll_handle;
}
poller* ep = new (std::nothrow) poller(kq);
if (ep == NULL) {
::close(kq);
errno = ENOMEM;
return InvalidHandle;
return invalid_bpoll_handle;
}
return (bpoll_handle)ep;
}

bool bpoll_close(bpoll_handle handle) noexcept {
if (handle == InvalidHandle) {
if (handle == invalid_bpoll_handle) {
errno = EBADF;
return false;
}
Expand All @@ -186,7 +185,7 @@ namespace bee::net {
}

bool bpoll_ctl_add(bpoll_handle handle, fd_t fd, const bpoll_event_t& event) noexcept {
if (handle == InvalidHandle) {
if (handle == invalid_bpoll_handle) {
errno = EBADF;
return false;
}
Expand All @@ -195,7 +194,7 @@ namespace bee::net {
}

bool bpoll_ctl_mod(bpoll_handle handle, fd_t fd, const bpoll_event_t& event) noexcept {
if (handle == InvalidHandle) {
if (handle == invalid_bpoll_handle) {
errno = EBADF;
return false;
}
Expand All @@ -204,7 +203,7 @@ namespace bee::net {
}

bool bpoll_ctl_del(bpoll_handle handle, fd_t fd) noexcept {
if (handle == InvalidHandle) {
if (handle == invalid_bpoll_handle) {
errno = EBADF;
return false;
}
Expand All @@ -217,7 +216,7 @@ namespace bee::net {
}

int bpoll_wait(bpoll_handle handle, const span<bpoll_event_t>& events, int timeout) noexcept {
if (handle == InvalidHandle) {
if (handle == invalid_bpoll_handle) {
errno = EBADF;
return -1;
}
Expand Down
19 changes: 14 additions & 5 deletions binding/lua_epoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace bee::lua_epoll {
if (!net::bpoll_close(fd)) {
return false;
}
fd = net::retired_fd;
fd = net::invalid_bpoll_handle;
return true;
}
};
Expand All @@ -50,7 +50,10 @@ namespace bee::lua_epoll {
}

static int ep_wait(lua_State *L) {
auto &ep = lua::checkudata<lua_epoll>(L, 1);
auto &ep = lua::checkudata<lua_epoll>(L, 1);
if (ep.fd == net::invalid_bpoll_handle) {
return lua::push_error(L, error::crt_errmsg("epoll_wait", std::errc::bad_file_descriptor));
}
int timeout = lua::optinteger<int, -1>(L, 2);
int n = net::bpoll_wait(ep.fd, ep.events, timeout);
if (n == -1) {
Expand Down Expand Up @@ -115,7 +118,7 @@ namespace bee::lua_epoll {

static int ep_event_add(lua_State *L) {
auto &ep = lua::checkudata<lua_epoll>(L, 1);
if (ep.fd == net::retired_fd) {
if (ep.fd == net::invalid_bpoll_handle) {
return lua::push_error(L, error::crt_errmsg("epoll_ctl", std::errc::bad_file_descriptor));
}
net::fd_t fd = ep_tofd(L, 2);
Expand All @@ -141,7 +144,10 @@ namespace bee::lua_epoll {
}

static int ep_event_mod(lua_State *L) {
auto &ep = lua::checkudata<lua_epoll>(L, 1);
auto &ep = lua::checkudata<lua_epoll>(L, 1);
if (ep.fd == net::invalid_bpoll_handle) {
return lua::push_error(L, error::crt_errmsg("epoll_ctl", std::errc::bad_file_descriptor));
}
net::fd_t fd = ep_tofd(L, 2);
int r = findref(L);
if (r == LUA_NOREF) {
Expand All @@ -162,7 +168,10 @@ namespace bee::lua_epoll {
}

static int ep_event_del(lua_State *L) {
auto &ep = lua::checkudata<lua_epoll>(L, 1);
auto &ep = lua::checkudata<lua_epoll>(L, 1);
if (ep.fd == net::invalid_bpoll_handle) {
return lua::push_error(L, error::crt_errmsg("epoll_ctl", std::errc::bad_file_descriptor));
}
net::fd_t fd = ep_tofd(L, 2);
if (!net::bpoll_ctl_del(ep.fd, fd)) {
return lua::push_error(L, error::net_errmsg("epoll_ctl"));
Expand Down

0 comments on commit b4e9d05

Please sign in to comment.