summary refs log tree commit diff stats
path: root/lib/pure
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pure')
-rw-r--r--lib/pure/irc.nim15
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/pure/irc.nim b/lib/pure/irc.nim
index 6e9e30281..8946a9d8f 100644
--- a/lib/pure/irc.nim
+++ b/lib/pure/irc.nim
@@ -119,6 +119,13 @@ proc part*(irc: var TIRC, channel, message: string) =
   ## Leaves ``channel`` with ``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 =
   ## Checks if `s` contains only numbers.
   var i = 0
@@ -224,6 +231,7 @@ proc irc*(address: string, port: TPort = 6667.TPort,
 
 proc processLine(irc: var TIRC, line: string): TIRCEvent =
   if line.len == 0:
+    irc.close()
     result.typ = EvDisconnected
   else:
     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.cmd == MError:
+      irc.close()
       result.typ = EvDisconnected
       return
 
@@ -252,6 +261,7 @@ proc processOther(irc: var TIRC, ev: var TIRCEvent): bool =
     irc.send("PING :" & formatFloat(irc.lastPing), true)
 
   if epochTime() - irc.lastPong >= 120.0 and irc.lastPong != -1.0:
+    irc.close()
     ev.typ = EvDisconnected # TODO: EvTimeout?
     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
   ## 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 socks = @[irc.sock]
   var ret = socks.select(timeout)
@@ -333,6 +345,7 @@ proc handleRead(h: PObject) =
       string(irc.lineBuffer).add(line.string)
   of RecvDisconnected:
     var ev: TIRCEvent
+    irc[].close()
     ev.typ = EvDisconnected
     irc.handleEvent(irc[], ev, irc.userArg)
   of RecvFail: nil
ground-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
REM - Run the full testsuite;  testament\tester all

REM - Uncomment the list of changes in news.txt
REM - write a news ticker entry
REM - Update the version

REM - Generate the full docs;  koch web0
REM - Generate the installers;
REM - Update the version in system.nim
REM - Test the installers
REM - Tag the release
REM - Merge devel into master
REM - Update csources

set NIMVER=%1

Rem Build -docs file:
koch web0
cd web\upload
7z a -tzip docs-%NIMVER%.zip *.html
move /y docs-%NIMVER%.zip download
cd ..\..

Rem Build csources
koch csources -d:release || exit /b

rem Grab C sources and nimsuggest
git clone --depth 1 https://github.com/nim-lang/csources.git

set PATH=%CD%\bin;%PATH%

ReM Build Win32 version:

set PATH=C:\Users\araq\projects\mingw32\bin;%PATH%
cd csources
call build.bat
cd ..
ReM Rebuilding koch is necessary because it uses its pointer size to determine
ReM which mingw link to put in the NSIS installer.
nim c --out:koch_temp koch || exit /b
koch_temp boot -d:release || exit /b
koch_temp nsis -d:release || exit /b
koch_temp zip -d:release || exit /b
dir build
move /y build\nim_%NIMVER%.exe build\nim-%NIMVER%_x32.exe || exit /b
move /y build\nim-%NIMVER%.zip build\nim-%NIMVER%_x32.zip || exit /b


ReM Build Win64 version:
set PATH=C:\Users\araq\projects\mingw64\bin;%PATH%
cd csources
call build64.bat
cd ..
nim c --out:koch_temp koch || exit /b
koch_temp boot -d:release || exit /b
koch_temp nsis -d:release || exit /b
koch_temp zip -d:release || exit /b
move /y build\nim_%NIMVER%.exe build\nim-%NIMVER%_x64.exe || exit /b
move /y build\nim-%NIMVER%.zip build\nim-%NIMVER%_x64.zip || exit /b