enable error handle

This commit is contained in:
Cloud Wu
2020-10-13 12:04:08 +08:00
parent e75d033066
commit 77311c7243
4 changed files with 69 additions and 23 deletions

View File

@@ -55,17 +55,19 @@ sp_add(int kfd, int sock, void *ud) {
return 0;
}
static void
static int
sp_enable(int kfd, int sock, void *ud, bool read_enable, bool write_enable) {
int ret = 0;
struct kevent ke;
EV_SET(&ke, sock, EVFILT_READ, read_enable ? EV_ENABLE : EV_DISABLE, 0, 0, ud);
if (kevent(kfd, &ke, 1, NULL, 0, NULL) == -1 || ke.flags & EV_ERROR) {
// todo: check error
ret |= 1;
}
EV_SET(&ke, sock, EVFILT_WRITE, write_enable ? EV_ENABLE : EV_DISABLE, 0, 0, ud);
if (kevent(kfd, &ke, 1, NULL, 0, NULL) == -1 || ke.flags & EV_ERROR) {
// todo: check error
ret |= 1;
}
return ret;
}
static int