From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- src/msg/async/EventSelect.cc | 97 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 src/msg/async/EventSelect.cc (limited to 'src/msg/async/EventSelect.cc') diff --git a/src/msg/async/EventSelect.cc b/src/msg/async/EventSelect.cc new file mode 100644 index 000000000..35000ccea --- /dev/null +++ b/src/msg/async/EventSelect.cc @@ -0,0 +1,97 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2014 UnitedStack + * + * Author: Haomai Wang + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#include "common/errno.h" +#include "EventSelect.h" + +#include +#include +#define dout_subsys ceph_subsys_ms + +#undef dout_prefix +#define dout_prefix *_dout << "SelectDriver." + +int SelectDriver::init(EventCenter *c, int nevent) +{ + #ifndef _WIN32 + ldout(cct, 0) << "Select isn't suitable for production env, just avoid " + << "compiling error or special purpose" << dendl; + #endif + FD_ZERO(&rfds); + FD_ZERO(&wfds); + max_fd = 0; + return 0; +} + +int SelectDriver::add_event(int fd, int cur_mask, int add_mask) +{ + ldout(cct, 10) << __func__ << " add event to fd=" << fd << " mask=" << add_mask + << dendl; + + int mask = cur_mask | add_mask; + if (mask & EVENT_READABLE) + FD_SET(fd, &rfds); + if (mask & EVENT_WRITABLE) + FD_SET(fd, &wfds); + if (fd > max_fd) + max_fd = fd; + + return 0; +} + +int SelectDriver::del_event(int fd, int cur_mask, int delmask) +{ + ldout(cct, 10) << __func__ << " del event fd=" << fd << " cur mask=" << cur_mask + << dendl; + + if (delmask & EVENT_READABLE) + FD_CLR(fd, &rfds); + if (delmask & EVENT_WRITABLE) + FD_CLR(fd, &wfds); + return 0; +} + +int SelectDriver::resize_events(int newsize) +{ + return 0; +} + +int SelectDriver::event_wait(std::vector &fired_events, struct timeval *tvp) +{ + int retval, numevents = 0; + + memcpy(&_rfds, &rfds, sizeof(fd_set)); + memcpy(&_wfds, &wfds, sizeof(fd_set)); + + retval = select(max_fd+1, &_rfds, &_wfds, NULL, tvp); + if (retval > 0) { + for (int j = 0; j <= max_fd; j++) { + int mask = 0; + struct FiredFileEvent fe; + if (FD_ISSET(j, &_rfds)) + mask |= EVENT_READABLE; + if (FD_ISSET(j, &_wfds)) + mask |= EVENT_WRITABLE; + if (mask) { + fe.fd = j; + fe.mask = mask; + fired_events.push_back(fe); + numevents++; + } + } + } + return numevents; +} -- cgit v1.2.3