Skip to content

Instantly share code, notes, and snippets.

@dom96 dom96/debug_for_11231.diff Secret
Created May 11, 2019

Embed
What would you like to do?
diff --git a/lib/posix/kqueue.nim b/lib/posix/kqueue.nim
index 18b47f5d5..6df22b151 100644
--- a/lib/posix/kqueue.nim
+++ b/lib/posix/kqueue.nim
@@ -149,12 +149,39 @@ type
proc kqueue*(): cint {.importc: "kqueue", header: "<sys/event.h>".}
## Creates new queue and returns its descriptor.
-proc kevent*(kqFD: cint,
+proc kevent_ex(kqFD: cint,
changelist: ptr KEvent, nchanges: cint,
eventlist: ptr KEvent, nevents: cint, timeout: ptr Timespec): cint
{.importc: "kevent", header: "<sys/event.h>".}
## Manipulates queue for given ``kqFD`` descriptor.
+
+proc kevent*(kqFD: cint,
+ changelist: ptr KEvent, nchanges: cint,
+ eventlist: ptr KEvent, nevents: cint, timeout: ptr Timespec): cint
+ =
+ ## Manipulates queue for given ``kqFD`` descriptor.
+ var clist = cast[ptr array[1000, KEvent]](changelist)
+ var elist = cast[ptr array[1000, KEvent]](eventlist)
+ echo("kevent(", kqFD, ", ")
+ if not clist.isNil:
+ echo("changelist:")
+ for i in 0 ..< nchanges:
+ echo(clist[i])
+ else:
+ echo("changelist: nil")
+ if elist.isNil:
+ echo("eventlist:")
+ for i in 0 ..< nevents:
+ echo(elist[i])
+ else:
+ echo("eventlist: nil")
+ if not timeout.isNil:
+ echo("timespec: ", timeout[])
+ echo(")")
+ kevent_ex(kqFd, changeList, nchanges, eventlist, nevents, timeout)
+
+
proc EV_SET*(event: ptr KEvent, ident: uint, filter: cshort, flags: cushort,
fflags: cuint, data: int, udata: pointer)
{.importc: "EV_SET", header: "<sys/event.h>".}
diff --git a/lib/pure/asyncdispatch.nim b/lib/pure/asyncdispatch.nim
index 3cc574afd..a70147333 100644
--- a/lib/pure/asyncdispatch.nim
+++ b/lib/pure/asyncdispatch.nim
@@ -1136,6 +1136,8 @@ else:
p.selector.registerHandle(fd.SocketHandle, {}, data)
proc closeSocket*(sock: AsyncFD) =
+ echo("closing socket ", sock.int)
+ stdout.flushFile()
let disp = getGlobalDispatcher()
disp.selector.unregister(sock.SocketHandle)
sock.SocketHandle.close()
diff --git a/lib/pure/ioselects/ioselectors_kqueue.nim b/lib/pure/ioselects/ioselectors_kqueue.nim
index 0e133f650..e005facf5 100644
--- a/lib/pure/ioselects/ioselectors_kqueue.nim
+++ b/lib/pure/ioselects/ioselectors_kqueue.nim
@@ -44,8 +44,8 @@ elif defined(netbsd) or defined(openbsd):
when hasThreadSupport:
type
SelectorImpl[T] = object
- kqFD : cint
- maxFD : int
+ kqFD: cint
+ maxFD: int
changes: ptr SharedArray[KEvent]
fds: ptr SharedArray[SelectorKey[T]]
count: int
@@ -57,8 +57,8 @@ when hasThreadSupport:
else:
type
SelectorImpl[T] = object
- kqFD : cint
- maxFD : int
+ kqFD: cint
+ maxFD: int
changes: seq[KEvent]
fds: seq[SelectorKey[T]]
count: int
@@ -209,6 +209,7 @@ else:
template flushKQueue[T](s: Selector[T]) =
let length = cint(len(s.changes))
if length > 0:
+ # echo("Performing changes: ", s.changes)
if kevent(s.kqFD, addr(s.changes[0]), length,
nil, 0, nil) == -1:
raiseIOSelectorsError(osLastError())
@@ -373,7 +374,7 @@ proc unregister*[T](s: Selector[T], fd: int|SocketHandle) =
var pkey = addr(s.fds[fdi])
doAssert(pkey.ident != InvalidIdent,
"Descriptor [" & $fdi & "] is not registered in the queue!")
-
+ echo("unregistering ", fd.int)
if pkey.events != {}:
if pkey.events * {Event.Read, Event.Write} != {}:
if Event.Read in pkey.events:
@@ -460,6 +461,12 @@ proc selectInto*[T](s: Selector[T], timeout: int,
if maxres > len(results):
maxres = len(results)
+ echo("SelectInto")
+ for i in 0 .. 10:
+ echo(i, " has events: ", s.fds[i].events)
+ let f = fcntl(i.SocketHandle, F_GETFD)
+ echo("fcntl: ", f)
+
var count = 0
when not declared(CACHE_EVENTS):
count = kevent(s.kqFD, nil, cint(0), addr(resTable[0]), cint(maxres), ptv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.