mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-31 10:22:15 +00:00
Async fixes for IRC module.
This commit is contained in:
@@ -33,7 +33,12 @@ type
|
||||
address: string
|
||||
port: TPort
|
||||
nick, user, realname, serverPass: string
|
||||
sock: TSocket
|
||||
case isAsync: bool
|
||||
of false:
|
||||
sock: TSocket
|
||||
of true:
|
||||
handleEvent: proc (irc: var TAsyncIRC, ev: TIRCEvent) {.closure.}
|
||||
asyncSock: PAsyncSocket
|
||||
status: TInfo
|
||||
lastPing: float
|
||||
lastPong: float
|
||||
@@ -44,8 +49,6 @@ type
|
||||
|
||||
PAsyncIRC* = ref TAsyncIRC
|
||||
TAsyncIRC* = object of TIRC
|
||||
handleEvent: proc (irc: var TAsyncIRC, ev: TIRCEvent) {.closure.}
|
||||
asyncSock: PAsyncSocket
|
||||
|
||||
TIRCMType* = enum
|
||||
MUnknown,
|
||||
@@ -92,7 +95,10 @@ proc send*(irc: var TIRC, message: string, sendImmediately = false) =
|
||||
|
||||
if sendMsg:
|
||||
try:
|
||||
irc.sock.send(message & "\c\L")
|
||||
if irc.isAsync:
|
||||
irc.asyncSock.send(message & "\c\L")
|
||||
else:
|
||||
irc.sock.send(message & "\c\L")
|
||||
except EOS:
|
||||
# Assuming disconnection of every EOS could be bad,
|
||||
# but I can't exactly check for EBrokenPipe.
|
||||
@@ -359,10 +365,10 @@ proc handleRead(s: PAsyncSocket, irc: PAsyncIRC) =
|
||||
var ev: TIRCEvent
|
||||
irc[].close()
|
||||
ev.typ = EvDisconnected
|
||||
irc.handleEvent(irc[], ev)
|
||||
irc[].handleEvent(irc[], ev)
|
||||
else:
|
||||
var ev = irc[].processLine(line.string)
|
||||
irc.handleEvent(irc[], ev)
|
||||
irc[].handleEvent(irc[], ev)
|
||||
|
||||
discard """proc handleRead(h: PObject) =
|
||||
var irc = PAsyncIRC(h)
|
||||
@@ -409,6 +415,7 @@ proc asyncIRC*(address: string, port: TPort = 6667.TPort,
|
||||
## synchronous IRC client implementation, use ``irc`` for that.
|
||||
|
||||
new(result)
|
||||
result.isAsync = true
|
||||
result.address = address
|
||||
result.port = port
|
||||
result.nick = nick
|
||||
|
||||
Reference in New Issue
Block a user