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/collections/sequtils.nim4
-rw-r--r--lib/pure/ftpclient.nim2
-rw-r--r--lib/pure/irc.nim21
-rwxr-xr-xlib/pure/os.nim2
4 files changed, 22 insertions, 7 deletions
diff --git a/lib/pure/collections/sequtils.nim b/lib/pure/collections/sequtils.nim
index 73713eec9..298e7f27e 100644
--- a/lib/pure/collections/sequtils.nim
+++ b/lib/pure/collections/sequtils.nim
@@ -12,8 +12,8 @@
 ## This module implements operations for the built-in `seq`:idx: type which
 ## were inspired by functional programming languages. If you are looking for
 ## the typical `map` function which applies a function to every element in a
-## sequence, it already exists as the `each` proc in the `system
-## <system.html>`_ module in both mutable and immutable styles.
+## sequence, it already exists in the `system <system.html>`_ module in both
+## mutable and immutable styles.
 ##
 ## Also, for functional style programming you may want to pass `anonymous procs
 ## <manual.html#anonymous-procs>`_ to procs like ``filter`` to reduce typing.
diff --git a/lib/pure/ftpclient.nim b/lib/pure/ftpclient.nim
index e656d001e..b61793866 100644
--- a/lib/pure/ftpclient.nim
+++ b/lib/pure/ftpclient.nim
@@ -114,7 +114,7 @@ proc getDSock(ftp: PFTPClient): TSocket =
 proc getCSock(ftp: PFTPClient): TSocket =
   if ftp.isAsync: return ftp.asyncCSock else: return ftp.csock
 
-template blockingOperation(sock: TSocket, body: stmt) =
+template blockingOperation(sock: TSocket, body: stmt) {.immediate.} =
   if ftp.isAsync:
     sock.setBlocking(true)
   body
diff --git a/lib/pure/irc.nim b/lib/pure/irc.nim
index 8916681f7..aa4e2d557 100644
--- a/lib/pure/irc.nim
+++ b/lib/pure/irc.nim
@@ -32,7 +32,7 @@
 ## **Warning:** The API of this module is unstable, and therefore is subject
 ## to change.
 
-import sockets, strutils, parseutils, times, asyncio
+import sockets, strutils, parseutils, times, asyncio, os
 
 type
   TIRC* = object of TObject
@@ -56,6 +56,7 @@ type
     channelsToJoin: seq[string]
     msgLimit: bool
     messageBuffer: seq[tuple[timeToSend: float, m: string]]
+    lastReconnect: float
 
   PIRC* = ref TIRC
 
@@ -235,12 +236,19 @@ proc connect*(irc: PIRC) =
   irc.send("NICK " & irc.nick, true)
   irc.send("USER $1 * 0 :$2" % [irc.user, irc.realname], true)
 
-proc reconnect*(irc: PIRC) =
+proc reconnect*(irc: PIRC, timeout = 5000) =
   ## Reconnects to an IRC server.
   ##
+  ## ``Timeout`` specifies the time to wait in miliseconds between multiple
+  ## consecutive reconnections.
+  ##
   ## This should be used when an ``EvDisconnected`` event occurs.
+  let secSinceReconnect = int(epochTime() - irc.lastReconnect)
+  if secSinceReconnect < timeout:
+    sleep(timeout - secSinceReconnect)
   irc.sock = socket()
   irc.connect()
+  irc.lastReconnect = epochTime()
 
 proc irc*(address: string, port: TPort = 6667.TPort,
          nick = "NimrodBot",
@@ -409,15 +417,22 @@ proc connect*(irc: PAsyncIRC) =
   
   irc.asyncSock.connect(irc.address, irc.port)
 
-proc reconnect*(irc: PAsyncIRC) =
+proc reconnect*(irc: PAsyncIRC, timeout = 5000) =
   ## Reconnects to an IRC server.
   ##
+  ## ``Timeout`` specifies the time to wait in miliseconds between multiple
+  ## consecutive reconnections.
+  ##
   ## This should be used when an ``EvDisconnected`` event occurs.
   ##
   ## When successfully reconnected an ``EvConnected`` event will occur.
+  let secSinceReconnect = int(epochTime() - irc.lastReconnect)
+  if secSinceReconnect < timeout:
+    sleep(timeout - secSinceReconnect)
   irc.asyncSock = AsyncSocket()
   irc.myDispatcher.register(irc)
   irc.connect()
+  irc.lastReconnect = epochTime()
 
 proc asyncIRC*(address: string, port: TPort = 6667.TPort,
               nick = "NimrodBot",
diff --git a/lib/pure/os.nim b/lib/pure/os.nim
index 9513dbffb..01daf5ad6 100755
--- a/lib/pure/os.nim
+++ b/lib/pure/os.nim
@@ -1449,7 +1449,7 @@ proc sleep*(milsecs: int) {.rtl, extern: "nos$1", tags: [FTime].} =
   else:
     var a, b: Ttimespec
     a.tv_sec = TTime(milsecs div 1000)
-    a.tv_nsec = (milsecs mod 1000) * 1000
+    a.tv_nsec = (milsecs mod 1000) * 1000 * 1000
     discard posix.nanosleep(a, b)
 
 proc getFileSize*(file: string): biggestInt {.rtl, extern: "nos$1",