1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2014 UnitedStack <haomai@unitedstack.com>
8 * Author: Haomai Wang <haomaiwang@gmail.com>
10 * This is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License version 2.1, as published by the Free Software
13 * Foundation. See file COPYING.
17 #include "common/errno.h"
18 #include "EventSelect.h"
21 #include <sys/select.h>
22 #define dout_subsys ceph_subsys_ms
25 #define dout_prefix *_dout << "SelectDriver."
27 int SelectDriver::init(EventCenter *c, int nevent)
29 ldout(cct, 0) << "Select isn't suitable for production env, just avoid "
30 << "compiling error or special purpose" << dendl;
37 int SelectDriver::add_event(int fd, int cur_mask, int add_mask)
39 ldout(cct, 10) << __func__ << " add event to fd=" << fd << " mask=" << add_mask
42 int mask = cur_mask | add_mask;
43 if (mask & EVENT_READABLE)
45 if (mask & EVENT_WRITABLE)
53 int SelectDriver::del_event(int fd, int cur_mask, int delmask)
55 ldout(cct, 10) << __func__ << " del event fd=" << fd << " cur mask=" << cur_mask
58 if (delmask & EVENT_READABLE)
60 if (delmask & EVENT_WRITABLE)
65 int SelectDriver::resize_events(int newsize)
70 int SelectDriver::event_wait(vector<FiredFileEvent> &fired_events, struct timeval *tvp)
72 int retval, numevents = 0;
74 memcpy(&_rfds, &rfds, sizeof(fd_set));
75 memcpy(&_wfds, &wfds, sizeof(fd_set));
77 retval = select(max_fd+1, &_rfds, &_wfds, NULL, tvp);
79 for (int j = 0; j <= max_fd; j++) {
81 struct FiredFileEvent fe;
82 if (FD_ISSET(j, &_rfds))
83 mask |= EVENT_READABLE;
84 if (FD_ISSET(j, &_wfds))
85 mask |= EVENT_WRITABLE;
89 fired_events.push_back(fe);