Async fixes for IRC module.
This commit is contained in:
parent
1047c4414c
commit
c841a09592
1 changed files with 13 additions and 6 deletions
|
|
@ -33,7 +33,12 @@ type
|
||||||
address: string
|
address: string
|
||||||
port: TPort
|
port: TPort
|
||||||
nick, user, realname, serverPass: string
|
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
|
status: TInfo
|
||||||
lastPing: float
|
lastPing: float
|
||||||
lastPong: float
|
lastPong: float
|
||||||
|
|
@ -44,8 +49,6 @@ type
|
||||||
|
|
||||||
PAsyncIRC* = ref TAsyncIRC
|
PAsyncIRC* = ref TAsyncIRC
|
||||||
TAsyncIRC* = object of TIRC
|
TAsyncIRC* = object of TIRC
|
||||||
handleEvent: proc (irc: var TAsyncIRC, ev: TIRCEvent) {.closure.}
|
|
||||||
asyncSock: PAsyncSocket
|
|
||||||
|
|
||||||
TIRCMType* = enum
|
TIRCMType* = enum
|
||||||
MUnknown,
|
MUnknown,
|
||||||
|
|
@ -92,7 +95,10 @@ proc send*(irc: var TIRC, message: string, sendImmediately = false) =
|
||||||
|
|
||||||
if sendMsg:
|
if sendMsg:
|
||||||
try:
|
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:
|
except EOS:
|
||||||
# Assuming disconnection of every EOS could be bad,
|
# Assuming disconnection of every EOS could be bad,
|
||||||
# but I can't exactly check for EBrokenPipe.
|
# but I can't exactly check for EBrokenPipe.
|
||||||
|
|
@ -359,10 +365,10 @@ proc handleRead(s: PAsyncSocket, irc: PAsyncIRC) =
|
||||||
var ev: TIRCEvent
|
var ev: TIRCEvent
|
||||||
irc[].close()
|
irc[].close()
|
||||||
ev.typ = EvDisconnected
|
ev.typ = EvDisconnected
|
||||||
irc.handleEvent(irc[], ev)
|
irc[].handleEvent(irc[], ev)
|
||||||
else:
|
else:
|
||||||
var ev = irc[].processLine(line.string)
|
var ev = irc[].processLine(line.string)
|
||||||
irc.handleEvent(irc[], ev)
|
irc[].handleEvent(irc[], ev)
|
||||||
|
|
||||||
discard """proc handleRead(h: PObject) =
|
discard """proc handleRead(h: PObject) =
|
||||||
var irc = PAsyncIRC(h)
|
var irc = PAsyncIRC(h)
|
||||||
|
|
@ -409,6 +415,7 @@ proc asyncIRC*(address: string, port: TPort = 6667.TPort,
|
||||||
## synchronous IRC client implementation, use ``irc`` for that.
|
## synchronous IRC client implementation, use ``irc`` for that.
|
||||||
|
|
||||||
new(result)
|
new(result)
|
||||||
|
result.isAsync = true
|
||||||
result.address = address
|
result.address = address
|
||||||
result.port = port
|
result.port = port
|
||||||
result.nick = nick
|
result.nick = nick
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue