Skip to content

Commit

Permalink
fix #17
Browse files Browse the repository at this point in the history
  • Loading branch information
ba0f3 committed Feb 21, 2024
1 parent 2cad2d5 commit 917c78f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/ssh2/private/channel.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import libssh2, types, session, utils
import libssh2, types, session, utils, streams

proc initChannel*(ssh: SSHClient): SSHChannel =
## Establish a generic session channel
Expand Down Expand Up @@ -28,31 +28,35 @@ proc read*(channel: SSHChannel): string =
var
buffer: array[0..1024, char]
rc: cint
stream = newStringStream()

while true:
zeroMem(addr buffer, buffer.len)
rc = channel.impl.channel_read(addr buffer, buffer.len)
if rc > 0:
result.add($cast[cstring](addr buffer))
stream.writeData(addr buffer, rc)
elif rc == LIBSSH2_ERROR_EAGAIN:
discard waitsocket(channel.client)
else:
break
stream.setPosition(0)
result = stream.readAll()

proc readError*(channel: SSHChannel): string =
var
buffer: array[0..1024, char]
rc: cint
stream = newStringStream()

while true:
zeroMem(addr buffer, buffer.len)
rc = channel.impl.channel_read_stderr(addr buffer, buffer.len)
if rc > 0:
result.add($cast[cstring](addr buffer))
stream.writeData(addr buffer, rc)
elif rc == LIBSSH2_ERROR_EAGAIN:
discard waitsocket(channel.client)
else:
break
stream.setPosition(0)
result = stream.readAll()

proc close*(channel: SSHChannel): bool =
var rc: cint
Expand Down
2 changes: 1 addition & 1 deletion ssh2.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.1.5"
version = "0.1.6"
author = "Huy Doan"
description = "SSH, SCP and SFTP client for Nim"
license = "MIT"
Expand Down

0 comments on commit 917c78f

Please sign in to comment.