Skip to content

Commit

Permalink
add noexcept
Browse files Browse the repository at this point in the history
  • Loading branch information
actboy168 committed Apr 23, 2024
1 parent 43715d9 commit 8988bdf
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 64 deletions.
12 changes: 6 additions & 6 deletions bee/net/bpoll.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ namespace bee::net {
};
#endif

fd_t bpoll_create();
bool bpoll_close(fd_t fd);
bool bpoll_ctl_add(fd_t fd, fd_t socket, const bpoll_event_t& event);
bool bpoll_ctl_mod(fd_t fd, fd_t socket, const bpoll_event_t& event);
bool bpoll_ctl_del(fd_t fd, fd_t socket);
int bpoll_wait(fd_t fd, const span<bpoll_event_t>& events, int timeout);
fd_t bpoll_create() noexcept;
bool bpoll_close(fd_t fd) noexcept;
bool bpoll_ctl_add(fd_t fd, fd_t socket, const bpoll_event_t& event) noexcept;
bool bpoll_ctl_mod(fd_t fd, fd_t socket, const bpoll_event_t& event) noexcept;
bool bpoll_ctl_del(fd_t fd, fd_t socket) noexcept;
int bpoll_wait(fd_t fd, const span<bpoll_event_t>& events, int timeout) noexcept;
}
12 changes: 6 additions & 6 deletions bee/net/bpoll_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,27 @@ namespace bee::net {
static_assert(std::to_underlying(bpoll_event::rdhup) == EPOLLRDHUP);
static_assert(std::to_underlying(bpoll_event::oneshot) == EPOLLONESHOT);

fd_t bpoll_create() {
fd_t bpoll_create() noexcept {
return (fd_t)::epoll_create1(EPOLL_CLOEXEC);
}

bool bpoll_close(fd_t epfd) {
bool bpoll_close(fd_t epfd) noexcept {
return ::close(epfd) == 0;
}

bool bpoll_ctl_add(fd_t epfd, fd_t socket, const bpoll_event_t& event) {
bool bpoll_ctl_add(fd_t epfd, fd_t socket, const bpoll_event_t& event) noexcept {
return ::epoll_ctl(epfd, EPOLL_CTL_ADD, socket, (struct epoll_event*)&event) != -1;
}

bool bpoll_ctl_mod(fd_t epfd, fd_t socket, const bpoll_event_t& event) {
bool bpoll_ctl_mod(fd_t epfd, fd_t socket, const bpoll_event_t& event) noexcept {
return ::epoll_ctl(epfd, EPOLL_CTL_MOD, socket, (struct epoll_event*)&event) != -1;
}

bool bpoll_ctl_del(fd_t epfd, fd_t socket) {
bool bpoll_ctl_del(fd_t epfd, fd_t socket) noexcept {
return ::epoll_ctl(epfd, EPOLL_CTL_DEL, socket, NULL) != -1;
}

int bpoll_wait(fd_t epfd, const span<bpoll_event_t>& events, int timeout) {
int bpoll_wait(fd_t epfd, const span<bpoll_event_t>& events, int timeout) noexcept {
return ::epoll_wait(epfd, (struct epoll_event*)events.data(), (int)events.size(), timeout);
}
}
22 changes: 11 additions & 11 deletions bee/net/bpoll_osx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ namespace bee::net {
constexpr uint16_t KQUEUE_STATE_REGISTERED = 0x0001;
constexpr uint16_t KQUEUE_STATE_EPOLLRDHUP = 0x0002;

static bool invalid_fd(int fd) {
static bool invalid_fd(int fd) noexcept {
return (fd < 0 || ((uint32_t)fd & ~(((uint32_t)1 << KEY_BITS) - 1)));
}

static int set_state(int kq, uint32_t key, uint16_t val) {
static int set_state(int kq, uint32_t key, uint16_t val) noexcept {
if ((key & ~(((uint32_t)1 << KEY_BITS) - 1)) || (val & ~(((uint16_t)1 << VAL_BITS) - 1))) {
return EINVAL;
}
Expand All @@ -46,7 +46,7 @@ namespace bee::net {
return 0;
}

static bool get_state(int kq, uint32_t key, uint16_t* val) {
static bool get_state(int kq, uint32_t key, uint16_t* val) noexcept {
if ((key & ~(((uint32_t)1 << KEY_BITS) - 1))) {
errno = EINVAL;
return false;
Expand Down Expand Up @@ -79,7 +79,7 @@ namespace bee::net {
return true;
}

static bool set_kevent(int epfd, int fd, int read_flags, int write_flags, void* udata) {
static bool set_kevent(int epfd, int fd, int read_flags, int write_flags, void* udata) noexcept {
struct kevent ev[2];
EV_SET(&ev[0], fd, EVFILT_READ, read_flags | EV_RECEIPT, 0, 0, udata);
EV_SET(&ev[1], fd, EVFILT_WRITE, write_flags | EV_RECEIPT, 0, 0, udata);
Expand All @@ -99,7 +99,7 @@ namespace bee::net {

constexpr bpoll_event AllowBpollEvents = bpoll_event::in | bpoll_event::out | bpoll_event::hup | bpoll_event::rdhup | bpoll_event::err;

static bool bpoll_ctl(int kq, int fd, const bpoll_event_t& ev, bool add) {
static bool bpoll_ctl(int kq, int fd, const bpoll_event_t& ev, bool add) noexcept {
int flags = 0;
int read_flags, write_flags;
if (bitmask_has(ev.events, ~AllowBpollEvents)) {
Expand Down Expand Up @@ -147,23 +147,23 @@ namespace bee::net {
return ok;
}

fd_t bpoll_create() {
fd_t bpoll_create() noexcept {
return kqueue();
}

bool bpoll_close(fd_t kq) {
bool bpoll_close(fd_t kq) noexcept {
return ::close(kq) == 0;
}

bool bpoll_ctl_add(fd_t kq, fd_t fd, const bpoll_event_t& event) {
bool bpoll_ctl_add(fd_t kq, fd_t fd, const bpoll_event_t& event) noexcept {
return bpoll_ctl(kq, fd, event, true);
}

bool bpoll_ctl_mod(fd_t kq, fd_t fd, const bpoll_event_t& event) {
bool bpoll_ctl_mod(fd_t kq, fd_t fd, const bpoll_event_t& event) noexcept {
return bpoll_ctl(kq, fd, event, false);
}

bool bpoll_ctl_del(fd_t kq, fd_t fd) {
bool bpoll_ctl_del(fd_t kq, fd_t fd) noexcept {
if (invalid_fd(fd)) {
errno = EBADF;
return false;
Expand All @@ -175,7 +175,7 @@ namespace bee::net {
return ok;
}

int bpoll_wait(fd_t kq, const span<bpoll_event_t>& events, int timeout) {
int bpoll_wait(fd_t kq, const span<bpoll_event_t>& events, int timeout) noexcept {
struct kevent kev[events.size()];
struct timespec t, *timeop = &t;
if (timeout < 0) {
Expand Down
12 changes: 6 additions & 6 deletions bee/net/bpoll_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <bee/win/afd/poller.h>

namespace bee::net {
fd_t bpoll_create() {
fd_t bpoll_create() noexcept {
afd::afd_context ctx;
if (!afd::afd_create(ctx)) {
return retired_fd;
Expand All @@ -18,7 +18,7 @@ namespace bee::net {
return (fd_t)ep;
}

bool bpoll_close(fd_t fd) {
bool bpoll_close(fd_t fd) noexcept {
if (fd == retired_fd) {
SetLastError(ERROR_INVALID_HANDLE);
return false;
Expand All @@ -28,7 +28,7 @@ namespace bee::net {
return true;
}

bool bpoll_ctl_add(fd_t fd, fd_t socket, const bpoll_event_t& event) {
bool bpoll_ctl_add(fd_t fd, fd_t socket, const bpoll_event_t& event) noexcept {
if (fd == retired_fd) {
SetLastError(ERROR_INVALID_HANDLE);
return false;
Expand All @@ -46,7 +46,7 @@ namespace bee::net {
return true;
}

bool bpoll_ctl_mod(fd_t fd, fd_t socket, const bpoll_event_t& event) {
bool bpoll_ctl_mod(fd_t fd, fd_t socket, const bpoll_event_t& event) noexcept {
if (fd == retired_fd) {
SetLastError(ERROR_INVALID_HANDLE);
return false;
Expand All @@ -64,7 +64,7 @@ namespace bee::net {
return true;
}

bool bpoll_ctl_del(fd_t fd, fd_t socket) {
bool bpoll_ctl_del(fd_t fd, fd_t socket) noexcept {
if (fd == retired_fd) {
SetLastError(ERROR_INVALID_HANDLE);
return false;
Expand All @@ -82,7 +82,7 @@ namespace bee::net {
return true;
}

int bpoll_wait(fd_t fd, const span<bpoll_event_t>& events, int timeout) {
int bpoll_wait(fd_t fd, const span<bpoll_event_t>& events, int timeout) noexcept {
if (fd == retired_fd) {
SetLastError(ERROR_INVALID_HANDLE);
return -1;
Expand Down
4 changes: 2 additions & 2 deletions bee/net/ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace bee::net::ip {
template <typename T>
static constexpr T host_to_network(T v) {
static constexpr T host_to_network(T v) noexcept {
static_assert(std::is_integral_v<T> && (sizeof(T) == 2 || sizeof(T) == 4));
if constexpr (std::endian::native == std::endian::big) {
return v;
Expand All @@ -23,7 +23,7 @@ namespace bee::net::ip {
}

template <size_t N>
static constexpr ptrdiff_t rfind(const char (&str)[N], size_t from, char c) {
static constexpr ptrdiff_t rfind(const char (&str)[N], size_t from, char c) noexcept {
for (ptrdiff_t i = from; i >= 0; i--) {
if (str[i] == c) {
return i;
Expand Down
64 changes: 32 additions & 32 deletions bee/utility/bitmask.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,38 @@

#include <type_traits>

#define BEE_BITMASK_OPERATORS(bitmask) \
[[nodiscard]] constexpr bitmask operator~(bitmask a) { \
return static_cast<bitmask>( \
~static_cast<std::underlying_type_t<bitmask>>(a) \
); \
} \
[[nodiscard]] constexpr bitmask operator|(bitmask a, bitmask b) { \
return static_cast<bitmask>( \
static_cast<std::underlying_type_t<bitmask>>(a) | \
static_cast<std::underlying_type_t<bitmask>>(b) \
); \
} \
[[nodiscard]] constexpr bitmask operator&(bitmask a, bitmask b) { \
return static_cast<bitmask>( \
static_cast<std::underlying_type_t<bitmask>>(a) & \
static_cast<std::underlying_type_t<bitmask>>(b) \
); \
} \
[[nodiscard]] constexpr bitmask operator^(bitmask a, bitmask b) { \
return static_cast<bitmask>( \
static_cast<std::underlying_type_t<bitmask>>(a) ^ \
static_cast<std::underlying_type_t<bitmask>>(b) \
); \
} \
constexpr bitmask& operator|=(bitmask& a, bitmask b) { \
return a = a | b; \
} \
constexpr bitmask& operator&=(bitmask& a, bitmask b) { \
return a = a & b; \
} \
constexpr bitmask& operator^=(bitmask& a, bitmask b) { \
return a = a ^ b; \
#define BEE_BITMASK_OPERATORS(bitmask) \
[[nodiscard]] constexpr bitmask operator~(bitmask a) noexcept { \
return static_cast<bitmask>( \
~static_cast<std::underlying_type_t<bitmask>>(a) \
); \
} \
[[nodiscard]] constexpr bitmask operator|(bitmask a, bitmask b) noexcept { \
return static_cast<bitmask>( \
static_cast<std::underlying_type_t<bitmask>>(a) | \
static_cast<std::underlying_type_t<bitmask>>(b) \
); \
} \
[[nodiscard]] constexpr bitmask operator&(bitmask a, bitmask b) noexcept { \
return static_cast<bitmask>( \
static_cast<std::underlying_type_t<bitmask>>(a) & \
static_cast<std::underlying_type_t<bitmask>>(b) \
); \
} \
[[nodiscard]] constexpr bitmask operator^(bitmask a, bitmask b) noexcept { \
return static_cast<bitmask>( \
static_cast<std::underlying_type_t<bitmask>>(a) ^ \
static_cast<std::underlying_type_t<bitmask>>(b) \
); \
} \
constexpr bitmask& operator|=(bitmask& a, bitmask b) noexcept { \
return a = a | b; \
} \
constexpr bitmask& operator&=(bitmask& a, bitmask b) noexcept { \
return a = a & b; \
} \
constexpr bitmask& operator^=(bitmask& a, bitmask b) noexcept { \
return a = a ^ b; \
}

namespace bee {
Expand Down
2 changes: 1 addition & 1 deletion bee/utility/span.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace bee {
: data_(nullptr)
, size_(0) {
}
constexpr span(pointer ptr, size_type count)
constexpr span(pointer ptr, size_type count) noexcept
: data_(ptr)
, size_(count) {
}
Expand Down

0 comments on commit 8988bdf

Please sign in to comment.