diff options
| author | ruki <[email protected]> | 2019-12-14 10:03:51 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-12-14 10:03:51 +0800 |
| commit | 22f2823a1b6cf40df62790e04eb770c2a6659daf (patch) | |
| tree | 0e7f2e603a04643064ff84a819708ec1c3ee49ff /xmake/core/base/scheduler.lua | |
| parent | 13f84aad1c1a3b5af36160f108839eae8407c555 (diff) | |
cancel socket from scheduler
Diffstat (limited to 'xmake/core/base/scheduler.lua')
| -rw-r--r-- | xmake/core/base/scheduler.lua | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/xmake/core/base/scheduler.lua b/xmake/core/base/scheduler.lua index 5c916bdce..6aafead43 100644 --- a/xmake/core/base/scheduler.lua +++ b/xmake/core/base/scheduler.lua @@ -166,7 +166,7 @@ function scheduler:co_count() end -- wait socket events -function scheduler:waitsock(sock, events, timeout) +function scheduler:sock_wait(sock, events, timeout) -- get the running coroutine local running = self:co_running() @@ -257,6 +257,23 @@ function scheduler:waitsock(sock, events, timeout) return self:co_suspend() end +-- cancel socket events +function scheduler:sock_cancel(sock) + + -- get the previous socket events + local events_prev = self:_sockevents(sock:csock()) + if events_prev ~= 0 then + + -- remove the waiting socket from the poller + local ok, errors = poller:remove(poller.OT_SOCK, sock) + if not ok then + return false, errors + end + self:_sockevents_set(sock:csock(), 0) + end + return true +end + -- sleep some times (ms) function scheduler:sleep(ms) |
