One more attempt to fix GC bug.
This commit is contained in:
parent
d28e4d0c49
commit
898e3602bd
|
@ -169,7 +169,7 @@ when defined(windows):
|
||||||
(t).wwsabuf.buf = cast[cstring](v.buf)
|
(t).wwsabuf.buf = cast[cstring](v.buf)
|
||||||
(t).wwsabuf.len = cast[int32](v.buflen)
|
(t).wwsabuf.len = cast[int32](v.buflen)
|
||||||
|
|
||||||
proc writeStreamLoop(udata: pointer) {.gcsafe.} =
|
proc writeStreamLoop(udata: pointer) {.gcsafe, nimcall.} =
|
||||||
var bytesCount: int32
|
var bytesCount: int32
|
||||||
if isNil(udata):
|
if isNil(udata):
|
||||||
return
|
return
|
||||||
|
@ -260,7 +260,7 @@ when defined(windows):
|
||||||
if len(transp.queue) == 0:
|
if len(transp.queue) == 0:
|
||||||
transp.state.incl(WritePaused)
|
transp.state.incl(WritePaused)
|
||||||
|
|
||||||
proc readStreamLoop(udata: pointer) {.gcsafe.} =
|
proc readStreamLoop(udata: pointer) {.gcsafe, nimcall.} =
|
||||||
if isNil(udata):
|
if isNil(udata):
|
||||||
return
|
return
|
||||||
var ovl = cast[PtrCustomOverlapped](udata)
|
var ovl = cast[PtrCustomOverlapped](udata)
|
||||||
|
@ -371,7 +371,7 @@ when defined(windows):
|
||||||
result.fail(newException(OSError, osErrorMsg(osLastError())))
|
result.fail(newException(OSError, osErrorMsg(osLastError())))
|
||||||
|
|
||||||
proc continuation(udata: pointer) =
|
proc continuation(udata: pointer) =
|
||||||
var ovl = cast[PtrCustomOverlapped](udata)
|
var ovl = cast[RefCustomOverlapped](udata)
|
||||||
if not retFuture.finished:
|
if not retFuture.finished:
|
||||||
if ovl.data.errCode == OSErrorCode(-1):
|
if ovl.data.errCode == OSErrorCode(-1):
|
||||||
if setsockopt(SocketHandle(sock), cint(SOL_SOCKET),
|
if setsockopt(SocketHandle(sock), cint(SOL_SOCKET),
|
||||||
|
@ -385,8 +385,10 @@ when defined(windows):
|
||||||
else:
|
else:
|
||||||
sock.closeAsyncSocket()
|
sock.closeAsyncSocket()
|
||||||
retFuture.fail(newException(OSError, osErrorMsg(ovl.data.errCode)))
|
retFuture.fail(newException(OSError, osErrorMsg(ovl.data.errCode)))
|
||||||
|
GC_unref(ovl)
|
||||||
|
|
||||||
povl = RefCustomOverlapped()
|
povl = RefCustomOverlapped()
|
||||||
|
GC_ref(povl)
|
||||||
povl.data = CompletionData(fd: sock, cb: continuation)
|
povl.data = CompletionData(fd: sock, cb: continuation)
|
||||||
var res = loop.connectEx(SocketHandle(sock),
|
var res = loop.connectEx(SocketHandle(sock),
|
||||||
cast[ptr SockAddr](addr saddr),
|
cast[ptr SockAddr](addr saddr),
|
||||||
|
@ -396,6 +398,7 @@ when defined(windows):
|
||||||
if not res:
|
if not res:
|
||||||
let err = osLastError()
|
let err = osLastError()
|
||||||
if int32(err) != ERROR_IO_PENDING:
|
if int32(err) != ERROR_IO_PENDING:
|
||||||
|
GC_unref(povl)
|
||||||
sock.closeAsyncSocket()
|
sock.closeAsyncSocket()
|
||||||
retFuture.fail(newException(OSError, osErrorMsg(err)))
|
retFuture.fail(newException(OSError, osErrorMsg(err)))
|
||||||
return retFuture
|
return retFuture
|
||||||
|
|
Loading…
Reference in New Issue