Skip to content
This repository has been archived by the owner on Feb 7, 2023. It is now read-only.

Commit

Permalink
udp_socket,network_driver: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lhmouse committed Feb 7, 2023
1 parent 35e6164 commit e854f76
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions poseidon/socket/udp_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ join_multicast_group(const Socket_Address& maddr, uint8_t ttl, bool loopback, co
// special treatement. `sendto()` is not affected.
if(::memcmp(maddr.data(), "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF", 12) == 0) {
// IPv4
if(ifreq.ifr_name[0] && (::ioctl(this->fd(), (int) SIOCGIFADDR, &ifreq) != 0))
if(ifreq.ifr_name[0] && (::ioctl(this->fd(), SIOCGIFADDR, &ifreq) != 0))
POSEIDON_THROW((
"Failed to get address of interface `$4`",
"[`ioctl()` failed: $3]",
Expand Down Expand Up @@ -231,7 +231,7 @@ join_multicast_group(const Socket_Address& maddr, uint8_t ttl, bool loopback, co
}
else {
// IPv6
if(ifreq.ifr_name[0] && (::ioctl(this->fd(), (int) SIOCGIFINDEX, &ifreq) != 0))
if(ifreq.ifr_name[0] && (::ioctl(this->fd(), SIOCGIFINDEX, &ifreq) != 0))
POSEIDON_THROW((
"Failed to get index of interface `$4`",
"[`ioctl()` failed: $3]",
Expand Down Expand Up @@ -296,7 +296,7 @@ leave_multicast_group(const Socket_Address& maddr, const char* ifname_opt)
// special treatement. `sendto()` is not affected.
if(::memcmp(maddr.data(), "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF", 12) == 0) {
// IPv4
if(ifreq.ifr_name[0] && (::ioctl(this->fd(), (int) SIOCGIFADDR, &ifreq) != 0))
if(ifreq.ifr_name[0] && (::ioctl(this->fd(), SIOCGIFADDR, &ifreq) != 0))
POSEIDON_THROW((
"Failed to get address of interface `$4`",
"[`ioctl()` failed: $3]",
Expand All @@ -316,7 +316,7 @@ leave_multicast_group(const Socket_Address& maddr, const char* ifname_opt)
}
else {
// IPv6
if(ifreq.ifr_name[0] && (::ioctl(this->fd(), (int) SIOCGIFINDEX, &ifreq) != 0))
if(ifreq.ifr_name[0] && (::ioctl(this->fd(), SIOCGIFINDEX, &ifreq) != 0))
POSEIDON_THROW((
"Failed to get index of interface `$4`",
"[`ioctl()` failed: $3]",
Expand Down
12 changes: 6 additions & 6 deletions poseidon/static/network_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace poseidon {
namespace {

void
do_epoll_ctl(int epoll_fd, int op, const shared_ptr<Abstract_Socket>& socket, uint32_t events)
do_epoll_ctl(int epoll_fd, int op, const shared_ptr<Abstract_Socket>& socket, uint32_t events = EPOLLIN | EPOLLPRI | EPOLLOUT | EPOLLET)
{
struct ::epoll_event event;
event.events = events;
Expand Down Expand Up @@ -304,7 +304,7 @@ thread_loop()
// Remove the socket due to an error, or an end-of-file condition.
POSEIDON_LOG_TRACE(("Removing closed socket `$1` (class `$2`)"), socket, typeid(*socket));
this->m_epoll_sockets.erase(socket_it);
do_epoll_ctl(this->m_epoll, EPOLL_CTL_DEL, socket, 0);
do_epoll_ctl(this->m_epoll, EPOLL_CTL_DEL, socket);
}
recursive_mutex::unique_lock io_lock(socket->m_io_mutex);
socket->m_io_driver = this;
Expand Down Expand Up @@ -445,14 +445,14 @@ thread_loop()

bool throttled = socket->m_io_write_queue.size() > throttle_size;
if(throttled != socket->m_io_throttled) {
// If there are too many bytes pending, disable `EPOLLIN` notification.
// The socket will be set to write-only, level-triggered mode.
socket->m_io_throttled = throttled;

// If there are too many bytes pending, disable `EPOLLIN` notification.
// The socket will be set to write-only, level-triggered mode.
if(throttled)
do_epoll_ctl(this->m_epoll, EPOLL_CTL_MOD, socket, EPOLLOUT);
else
do_epoll_ctl(this->m_epoll, EPOLL_CTL_MOD, socket, EPOLLIN | EPOLLPRI | EPOLLOUT | EPOLLET);
do_epoll_ctl(this->m_epoll, EPOLL_CTL_MOD, socket);
}

if(server_ssl_ctx)
Expand All @@ -474,7 +474,7 @@ insert(const shared_ptr<Abstract_Socket>& socket)
// The socket will be deleted from an epoll automatically when it's closed,
// so there is no need to remove it in case of an exception.
plain_mutex::unique_lock lock(this->m_epoll_mutex);
do_epoll_ctl(this->m_epoll, EPOLL_CTL_ADD, socket, EPOLLIN | EPOLLPRI | EPOLLOUT | EPOLLET);
do_epoll_ctl(this->m_epoll, EPOLL_CTL_ADD, socket);
this->m_epoll_sockets[socket.get()] = socket;
}

Expand Down

0 comments on commit e854f76

Please sign in to comment.