[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnunet-nim] branch master updated: add support for input a
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnunet-nim] branch master updated: add support for input and output file |
Date: |
Sun, 05 Aug 2018 00:21:10 +0200 |
This is an automated email from the git hooks/post-receive script.
lurchi pushed a commit to branch master
in repository gnunet-nim.
The following commit(s) were added to refs/heads/master by this push:
new d7313ad add support for input and output file
d7313ad is described below
commit d7313ad13da34de5c5ee769e709bb062a6c259b7
Author: lurchi <address@hidden>
AuthorDate: Sun Aug 5 00:20:55 2018 +0200
add support for input and output file
---
gnunet_nim.nim | 58 ++++++++++++++++++++++++++++++++++++++++------------------
1 file changed, 40 insertions(+), 18 deletions(-)
diff --git a/gnunet_nim.nim b/gnunet_nim.nim
index ed02352..e82b9bd 100644
--- a/gnunet_nim.nim
+++ b/gnunet_nim.nim
@@ -6,7 +6,9 @@ import strutils
proc firstTask(gnunetApp: ref GnunetApplication,
peer: string,
- port: string) {.async.} =
+ port: string,
+ inputFilename: string,
+ outputFilename: string) {.async.} =
var cadet = await gnunetApp.connectCadet()
var cadetChannel: ref CadetChannel
if peer.isNil() and not port.isNil():
@@ -17,25 +19,43 @@ proc firstTask(gnunetApp: ref GnunetApplication,
cadetChannel = channel
elif not peer.isNil() and not port.isNil():
cadetChannel = cadet.createChannel(peer, port)
- let stdinFile = openAsync("/dev/stdin", fmRead)
- var messagesFuture = cadetChannel.messages.read()
- var stdinFuture = stdinFile.readline()
- while true:
- await messagesFuture or stdinFuture
- if messagesFuture.finished():
- let (hasData, message) = messagesFuture.read()
+ if not inputFilename.isNil():
+ let inputFile = openAsync(inputFilename, fmRead)
+ while true:
+ # 64k is close to the limit of GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE
+ let content = await inputFile.read(64000)
+ if content.len() == 0:
+ break
+ cadetChannel.sendMessage(content)
+ inputFile.close()
+ elif not outputFilename.isNil():
+ let outputFile = openAsync(outputFilename, fmWrite)
+ while true:
+ let (hasData, message) = await cadetChannel.messages.read()
if not hasData:
- break;
- echo message.strip(leading = false)
- messagesFuture = cadetChannel.messages.read()
- if stdinFuture.finished():
- let input = stdinFuture.read() & '\n'
- cadetChannel.sendMessage(input)
- stdinFuture = stdinFile.readline()
- stdinFile.close()
+ break
+ asyncCheck outputFile.write(message)
+ outputFile.close()
+ else:
+ let stdinFile = openAsync("/dev/stdin", fmRead)
+ var messagesFuture = cadetChannel.messages.read()
+ var stdinFuture = stdinFile.readline()
+ while true:
+ await messagesFuture or stdinFuture
+ if messagesFuture.finished():
+ let (hasData, message) = messagesFuture.read()
+ if not hasData:
+ break
+ echo message.strip(leading = false)
+ messagesFuture = cadetChannel.messages.read()
+ if stdinFuture.finished():
+ let input = stdinFuture.read() & '\n'
+ cadetChannel.sendMessage(input)
+ stdinFuture = stdinFile.readline()
+ stdinFile.close()
proc main() =
- var peer, port, configfile: string
+ var peer, port, configfile, inputFilename, outputFilename: string
var optParser = initOptParser()
for kind, key, value in optParser.getopt():
case kind
@@ -45,10 +65,12 @@ proc main() =
case key
of "port", "p": port = value
of "config", "c": configfile = value
+ of "file", "f": inputFilename = value
+ of "output", "o": outputFilename = value
of cmdEnd:
assert(false)
var gnunetApp = initGnunetApplication(configfile)
- asyncCheck firstTask(gnunetApp, peer, port)
+ asyncCheck firstTask(gnunetApp, peer, port, inputFilename, outputFilename)
try:
while true:
#echo "polling, timeout = ", gnunetApp.millisecondsUntilTimeout()
--
To stop receiving notification emails like this one, please contact
address@hidden
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] [gnunet-nim] branch master updated: add support for input and output file,
gnunet <=