Commit b082bfb4 authored by knowledge4igor's avatar knowledge4igor

Tiny code improvements

parent c5fd213e
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
namespace Pistache { namespace Pistache {
typedef int Fd; using Fd = int;
uint hardware_concurrency(); uint hardware_concurrency();
bool make_non_blocking(int fd); bool make_non_blocking(int fd);
...@@ -87,8 +87,10 @@ inline constexpr bool operator==(Tag lhs, Tag rhs) { ...@@ -87,8 +87,10 @@ inline constexpr bool operator==(Tag lhs, Tag rhs) {
} }
struct Event { struct Event {
explicit Event(Tag _tag) : explicit Event(Tag _tag)
tag(_tag) : flags()
, fd(-1)
, tag(_tag)
{ } { }
Flags<NotifyOn> flags; Flags<NotifyOn> flags;
...@@ -111,8 +113,8 @@ public: ...@@ -111,8 +113,8 @@ public:
std::chrono::milliseconds timeout = std::chrono::milliseconds(0)) const; std::chrono::milliseconds timeout = std::chrono::milliseconds(0)) const;
private: private:
int toEpollEvents(Flags<NotifyOn> interest) const; static int toEpollEvents(const Flags<NotifyOn>& interest);
Flags<NotifyOn> toNotifyOn(int events) const; static Flags<NotifyOn> toNotifyOn(int events);
int epoll_fd; int epoll_fd;
}; };
......
...@@ -25,13 +25,13 @@ uint hardware_concurrency() { ...@@ -25,13 +25,13 @@ uint hardware_concurrency() {
} }
bool make_non_blocking(int sfd) bool make_non_blocking(int fd)
{ {
int flags = fcntl (sfd, F_GETFL, 0); int flags = fcntl (fd, F_GETFL, 0);
if (flags == -1) return false; if (flags == -1) return false;
flags |= O_NONBLOCK; flags |= O_NONBLOCK;
int ret = fcntl (sfd, F_SETFL, flags); int ret = fcntl (fd, F_SETFL, flags);
if (ret == -1) return false; if (ret == -1) return false;
return true; return true;
...@@ -206,7 +206,7 @@ namespace Polling { ...@@ -206,7 +206,7 @@ namespace Polling {
} }
int int
Epoll::toEpollEvents(Flags<NotifyOn> interest) const { Epoll::toEpollEvents(const Flags<NotifyOn>& interest) {
int events = 0; int events = 0;
if (interest.hasFlag(NotifyOn::Read)) if (interest.hasFlag(NotifyOn::Read))
...@@ -222,7 +222,7 @@ namespace Polling { ...@@ -222,7 +222,7 @@ namespace Polling {
} }
Flags<NotifyOn> Flags<NotifyOn>
Epoll::toNotifyOn(int events) const { Epoll::toNotifyOn(int events) {
Flags<NotifyOn> flags; Flags<NotifyOn> flags;
if (events & EPOLLIN) if (events & EPOLLIN)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment