event/PollResult: use size_t for size and index
This commit is contained in:
parent
13ac74e0a2
commit
497e0669ff
@ -188,7 +188,7 @@ EventLoop::Run()
|
||||
}
|
||||
|
||||
/* invoke sockets */
|
||||
for (int i = 0; i < poll_result.GetSize(); ++i) {
|
||||
for (size_t i = 0; i < poll_result.GetSize(); ++i) {
|
||||
auto events = poll_result.GetEvents(i);
|
||||
if (events != 0) {
|
||||
if (quit)
|
||||
|
@ -33,17 +33,17 @@ class PollResultEPoll
|
||||
friend class PollGroupEPoll;
|
||||
|
||||
std::array<epoll_event, 16> events;
|
||||
int n_events;
|
||||
size_t n_events;
|
||||
public:
|
||||
PollResultEPoll() : n_events(0) { }
|
||||
|
||||
int GetSize() const { return n_events; }
|
||||
unsigned GetEvents(int i) const { return events[i].events; }
|
||||
void *GetObject(int i) const { return events[i].data.ptr; }
|
||||
size_t GetSize() const { return n_events; }
|
||||
unsigned GetEvents(size_t i) const { return events[i].events; }
|
||||
void *GetObject(size_t i) const { return events[i].data.ptr; }
|
||||
void Reset() { n_events = 0; }
|
||||
|
||||
void Clear(void *obj) {
|
||||
for (int i = 0; i < n_events; ++i)
|
||||
for (size_t i = 0; i < n_events; ++i)
|
||||
if (events[i].data.ptr == obj)
|
||||
events[i].events = 0;
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ void PollGroupWinSelect::Modify(PollGroupWinSelect::Item &item, int fd,
|
||||
if (index < 0 && HasEvent(events, event_id))
|
||||
item.index[event_id] = set.Add(fd);
|
||||
else if (index >= 0 && !HasEvent(events, event_id)) {
|
||||
if (index != set.Size() - 1) {
|
||||
if (size_t(index) != set.Size() - 1) {
|
||||
set.MoveToEnd(index);
|
||||
items[set[index]].index[event_id] = index;
|
||||
}
|
||||
@ -142,13 +142,13 @@ void PollGroupWinSelect::ReadEvents(PollResultGeneric &result, int timeout_ms)
|
||||
if (ret == 0 || ret == SOCKET_ERROR)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < read_set.Size(); ++i)
|
||||
for (size_t i = 0; i < read_set.Size(); ++i)
|
||||
items[read_set[i]].events |= READ;
|
||||
|
||||
for (int i = 0; i < write_set.Size(); ++i)
|
||||
for (size_t i = 0; i < write_set.Size(); ++i)
|
||||
items[write_set[i]].events |= WRITE;
|
||||
|
||||
for (int i = 0; i < except_set.Size(); ++i)
|
||||
for (size_t i = 0; i < except_set.Size(); ++i)
|
||||
items[except_set[i]].events |= WRITE;
|
||||
|
||||
for (auto i = items.begin(); i != items.end(); ++i)
|
||||
|
@ -51,23 +51,23 @@ public:
|
||||
}
|
||||
|
||||
fd_set *GetPtr() { return &set; }
|
||||
int Size() { return set.fd_count; }
|
||||
size_t Size() { return set.fd_count; }
|
||||
bool IsEmpty() { return set.fd_count == 0; }
|
||||
bool IsFull() { return set.fd_count == FD_SETSIZE; }
|
||||
|
||||
int operator[](int index) {
|
||||
assert(index >= 0 && (u_int)index < set.fd_count);
|
||||
int operator[](size_t index) const noexcept {
|
||||
assert(index < set.fd_count);
|
||||
return set.fd_array[index];
|
||||
}
|
||||
|
||||
int Add(int fd) {
|
||||
size_t Add(int fd) {
|
||||
assert(!IsFull());
|
||||
set.fd_array[set.fd_count] = fd;
|
||||
return set.fd_count++;
|
||||
}
|
||||
|
||||
void MoveToEnd(int index) {
|
||||
assert(index >= 0 && (u_int)index < set.fd_count);
|
||||
void MoveToEnd(size_t index) {
|
||||
assert(index < set.fd_count);
|
||||
std::swap(set.fd_array[index], set.fd_array[set.fd_count - 1]);
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,8 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
class PollResultGeneric
|
||||
{
|
||||
struct Item
|
||||
@ -38,9 +40,9 @@ class PollResultGeneric
|
||||
|
||||
std::vector<Item> items;
|
||||
public:
|
||||
int GetSize() const { return items.size(); }
|
||||
unsigned GetEvents(int i) const { return items[i].events; }
|
||||
void *GetObject(int i) const { return items[i].obj; }
|
||||
size_t GetSize() const { return items.size(); }
|
||||
unsigned GetEvents(size_t i) const { return items[i].events; }
|
||||
void *GetObject(size_t i) const { return items[i].obj; }
|
||||
void Reset() { items.clear(); }
|
||||
|
||||
void Clear(void *obj) {
|
||||
|
Loading…
Reference in New Issue
Block a user