gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [gnunet-nim] branch master updated (7ed9750 -> b95e5ca)


From: gnunet
Subject: [GNUnet-SVN] [gnunet-nim] branch master updated (7ed9750 -> b95e5ca)
Date: Sat, 18 Aug 2018 01:46:57 +0200

This is an automated email from the git hooks/post-receive script.

lurchi pushed a change to branch master
in repository gnunet-nim.

    from 7ed9750  Merge branch 'master' of ssh://gnunet.org/gnunet-nim
     new f7e6bc7  workaround for missing notification about disconnected cadet 
channels
     new b95e5ca  restructure groupchat application

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 asynccadet.nim         |  4 +++-
 examples/groupchat.nim | 38 +++++++++++++++++---------------------
 2 files changed, 20 insertions(+), 22 deletions(-)

diff --git a/asynccadet.nim b/asynccadet.nim
index 92b421a..bb57571 100644
--- a/asynccadet.nim
+++ b/asynccadet.nim
@@ -22,9 +22,11 @@ type
 proc channelDisconnectCb(cls: pointer,
                          gnunetChannel: ptr GNUNET_CADET_Channel) {.cdecl.} =
   let channel = cast[ptr CadetChannel](cls)
-  GNUNET_CADET_receive_done(channel.handle)
   channel.handle = nil
   channel.messages.complete()
+  # workaround: if poll in main is called with a timeout > 0, the stream 
reader is
+  # not notified about the end of the stream (Nim bug?). So call poll here, 
too.
+  poll(0)
 
 proc channelConnectCb(cls: pointer,
                       gnunetChannel: ptr GNUNET_CADET_Channel,
diff --git a/examples/groupchat.nim b/examples/groupchat.nim
index 26f9848..93d4323 100644
--- a/examples/groupchat.nim
+++ b/examples/groupchat.nim
@@ -21,21 +21,17 @@ proc processClientMessages(channel: ref CadetChannel,
     chat.publish(message = message, sender = channel)
 
 proc processServerMessages(channel: ref CadetChannel) {.async.} =
-  let inputFile = openAsync("/dev/stdin", fmRead)
-  var inputFuture = inputFile.readline()
-  var messageFuture = channel.messages.read()
   while true:
-    await inputFuture or messageFuture
-    if inputFuture.finished():
-      let input = inputFuture.read()
-      channel.sendMessage(input)
-      inputFuture = inputFile.readline()
-    else:
-      let (hasData, message) = messageFuture.read()
-      if not hasData:
-        break
-      echo getDateStr()," ",getClockStr()," ",message
-      messageFuture = channel.messages.read()
+    let (hasData, message) = await channel.messages.read()
+    if not hasData:
+      shutdownGnunetApplication()
+      return
+    echo getDateStr()," ",getClockStr()," ",message
+
+proc processInput(inputFile: AsyncFile, channel: ref CadetChannel) {.async.} =
+  while true:
+    let input = await inputFile.readline()
+    channel.sendMessage(input)
 
 proc firstTask(gnunetApp: ref GnunetApplication,
                server: string,
@@ -44,8 +40,10 @@ proc firstTask(gnunetApp: ref GnunetApplication,
   var chat = new(Chat)
   chat.channels = newSeq[ref CadetChannel]()
   if not server.isNil():
+    let inputFile = openAsync("/dev/stdin", fmRead)
     let channel = cadet.createChannel(server, port)
-    processServerMessages(channel).addCallback(shutdownGnunetApplication)
+    await processServerMessages(channel) or processInput(inputFile, channel)
+    inputFile.close()
   else:
     let cadetPort = cadet.openPort(port)
     while true:
@@ -80,12 +78,10 @@ proc main() =
       assert(false)
   var gnunetApp = initGnunetApplication(configfile)
   asyncCheck firstTask(gnunetApp, server, port)
-  try:
-    while true:
-      poll(gnunetApp.millisecondsUntilTimeout())
-      gnunetApp.doWork()
-  except ValueError:
-    echo "quitting"
+  while hasPendingOperations():
+    poll(gnunetApp.millisecondsUntilTimeout())
+    gnunetApp.doWork()
+  echo "quitting"
 
 main()
 GC_fullCollect()

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]