In the IRC module the socket is now closed when EvDisconnected event is created.
This commit is contained in:
parent
b6ee92f384
commit
38eafd30ae
1 changed files with 14 additions and 1 deletions
|
|
@ -119,6 +119,13 @@ proc part*(irc: var TIRC, channel, message: string) =
|
||||||
## Leaves ``channel`` with ``message``.
|
## Leaves ``channel`` with ``message``.
|
||||||
irc.send("PART " & channel & " :" & message)
|
irc.send("PART " & channel & " :" & message)
|
||||||
|
|
||||||
|
proc close*(irc: var TIRC) =
|
||||||
|
## Closes connection to an IRC server.
|
||||||
|
##
|
||||||
|
## **Warning:** This procedure does not send a ``QUIT`` message to the server.
|
||||||
|
irc.status = SockClosed
|
||||||
|
irc.sock.close()
|
||||||
|
|
||||||
proc isNumber(s: string): bool =
|
proc isNumber(s: string): bool =
|
||||||
## Checks if `s` contains only numbers.
|
## Checks if `s` contains only numbers.
|
||||||
var i = 0
|
var i = 0
|
||||||
|
|
@ -224,6 +231,7 @@ proc irc*(address: string, port: TPort = 6667.TPort,
|
||||||
|
|
||||||
proc processLine(irc: var TIRC, line: string): TIRCEvent =
|
proc processLine(irc: var TIRC, line: string): TIRCEvent =
|
||||||
if line.len == 0:
|
if line.len == 0:
|
||||||
|
irc.close()
|
||||||
result.typ = EvDisconnected
|
result.typ = EvDisconnected
|
||||||
else:
|
else:
|
||||||
result = parseMessage(line)
|
result = parseMessage(line)
|
||||||
|
|
@ -232,6 +240,7 @@ proc processLine(irc: var TIRC, line: string): TIRCEvent =
|
||||||
if result.origin == irc.nick: result.origin = result.nick
|
if result.origin == irc.nick: result.origin = result.nick
|
||||||
|
|
||||||
if result.cmd == MError:
|
if result.cmd == MError:
|
||||||
|
irc.close()
|
||||||
result.typ = EvDisconnected
|
result.typ = EvDisconnected
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -252,6 +261,7 @@ proc processOther(irc: var TIRC, ev: var TIRCEvent): bool =
|
||||||
irc.send("PING :" & formatFloat(irc.lastPing), true)
|
irc.send("PING :" & formatFloat(irc.lastPing), true)
|
||||||
|
|
||||||
if epochTime() - irc.lastPong >= 120.0 and irc.lastPong != -1.0:
|
if epochTime() - irc.lastPong >= 120.0 and irc.lastPong != -1.0:
|
||||||
|
irc.close()
|
||||||
ev.typ = EvDisconnected # TODO: EvTimeout?
|
ev.typ = EvDisconnected # TODO: EvTimeout?
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
|
@ -276,7 +286,9 @@ proc poll*(irc: var TIRC, ev: var TIRCEvent,
|
||||||
## not need to be running many time critical tasks in the background. If you
|
## not need to be running many time critical tasks in the background. If you
|
||||||
## require this, use the asyncio implementation.
|
## require this, use the asyncio implementation.
|
||||||
|
|
||||||
if not (irc.status == SockConnected): ev.typ = EvDisconnected
|
if not (irc.status == SockConnected):
|
||||||
|
# Do not close the socket here, it is already closed!
|
||||||
|
ev.typ = EvDisconnected
|
||||||
var line = TaintedString""
|
var line = TaintedString""
|
||||||
var socks = @[irc.sock]
|
var socks = @[irc.sock]
|
||||||
var ret = socks.select(timeout)
|
var ret = socks.select(timeout)
|
||||||
|
|
@ -333,6 +345,7 @@ proc handleRead(h: PObject) =
|
||||||
string(irc.lineBuffer).add(line.string)
|
string(irc.lineBuffer).add(line.string)
|
||||||
of RecvDisconnected:
|
of RecvDisconnected:
|
||||||
var ev: TIRCEvent
|
var ev: TIRCEvent
|
||||||
|
irc[].close()
|
||||||
ev.typ = EvDisconnected
|
ev.typ = EvDisconnected
|
||||||
irc.handleEvent(irc[], ev, irc.userArg)
|
irc.handleEvent(irc[], ev, irc.userArg)
|
||||||
of RecvFail: nil
|
of RecvFail: nil
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue