Use bitmask instead of std::vector

This commit is contained in:
Tatsuhiro Tsujikawa 2012-06-08 22:52:08 +09:00
parent 6df709b441
commit 183cce1707
2 changed files with 8 additions and 9 deletions

View File

@ -30,7 +30,7 @@ namespace shrpx {
IOControl::IOControl(bufferevent *bev)
: bev_(bev),
ctrlv_(SHRPX_REASON_MAX)
rdbits_(0)
{}
IOControl::~IOControl()
@ -43,14 +43,14 @@ void IOControl::set_bev(bufferevent *bev)
void IOControl::pause_read(IOCtrlReason reason)
{
ctrlv_[reason] = 1;
rdbits_ |= reason;
bufferevent_disable(bev_, EV_READ);
}
bool IOControl::resume_read(IOCtrlReason reason)
{
ctrlv_[reason] = 0;
if(std::find(ctrlv_.begin(), ctrlv_.end(), 1) == ctrlv_.end()) {
rdbits_ &= ~reason;
if(rdbits_ == 0) {
bufferevent_enable(bev_, EV_READ);
return true;
} else {
@ -60,7 +60,7 @@ bool IOControl::resume_read(IOCtrlReason reason)
void IOControl::force_resume_read()
{
std::fill(ctrlv_.begin(), ctrlv_.end(), 0);
rdbits_ = 0;
bufferevent_enable(bev_, EV_READ);
}

View File

@ -35,9 +35,8 @@
namespace shrpx {
enum IOCtrlReason {
SHRPX_NO_BUFFER = 0,
SHRPX_MSG_BLOCK,
SHRPX_REASON_MAX
SHRPX_NO_BUFFER = 1 << 0,
SHRPX_MSG_BLOCK = 1 << 1
};
class IOControl {
@ -52,7 +51,7 @@ public:
void force_resume_read();
private:
bufferevent *bev_;
std::vector<int> ctrlv_;
uint32_t rdbits_;
};
} // namespace shrpx