@@ -70,22 +70,24 @@ proc receiveAsync*(conn: ZConnection): Future[string] =
7070 # # See https://github.com/zeromq/libzmq/issues/2941 and https://github.com/zeromq/pyzmq/issues/1411
7171 let fut = newFuture [string ](" receiveAsync" )
7272 result = fut
73+ let sock = conn.socket
7374
7475 proc cb (fd: AsyncFD ): bool {.closure , gcsafe .} =
76+ # the cb should work on the low level socket and not the ZConnection object
7577 result = true
7678
7779 # ignore if already finished
7880 if fut.finished: return
7981
8082 try :
81- let status = getsockopt [cint ](conn , ZSockOptions .EVENTS )
83+ let status = getsockopt [cint ](sock , ZSockOptions .EVENTS )
8284 if (status and ZMQ_POLLIN ) == 0 :
8385 # waiting for messages
8486 addRead (fd, cb)
8587 else :
8688 # ready to read
8789 unregister (fd)
88- fut.complete conn .receive (DONTWAIT )
90+ fut.complete sock .receive (DONTWAIT )
8991 except :
9092 unregister (fd)
9193 fut.fail getCurrentException ()
@@ -103,6 +105,7 @@ proc sendAsync*(conn: ZConnection, msg: string, flags: ZSendRecvOptions = DONTWA
103105 # # See https://github.com/zeromq/libzmq/issues/2941 and https://github.com/zeromq/pyzmq/issues/1411
104106 let fut = newFuture [void ](" sendAsync" )
105107 result = fut
108+ let sock = conn.socket
106109
107110 let status = getsockopt [cint ](conn, ZSockOptions .EVENTS )
108111 if (status and ZMQ_POLLOUT ) == 0 :
@@ -114,12 +117,12 @@ proc sendAsync*(conn: ZConnection, msg: string, flags: ZSendRecvOptions = DONTWA
114117 if fut.finished: return
115118
116119 try :
117- let status = getsockopt [cint ](conn , ZSockOptions .EVENTS )
120+ let status = getsockopt [cint ](sock , ZSockOptions .EVENTS )
118121 if (status and ZMQ_POLLOUT ) == 0 :
119122 # waiting for messages
120123 addWrite (fd, cb)
121124 else :
122- conn .send (msg, flags)
125+ sock .send (msg, flags)
123126 unregister (fd)
124127 fut.complete ()
125128 except :
0 commit comments