summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rwxr-xr-xexamples/echo/server.scm8
-rw-r--r--src/channel-type.c11
3 files changed, 20 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 5b1f154..30fd194 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,11 +1,18 @@
2014-01-04 Artyom Poptsov <poptsov.artyom@gmail.com>
+ * examples/echo/server.scm (main): Use `char-ready?' predicate
+ instead of the custom procedure `channel-poll'.
+
* src/channel-type.c (ptob_close): New procedure.
(print_channel): Don't try to get state of a channel if its port
is closed because it leads to segfaults. Closed port means closed
channel.
(init_channel_type): Register `ptob_close' with
`scm_set_port_close'.
+ (ptob_input_waiting): Call `ssh_channel_poll'.
+ (init_channel_type): Register callback with
+ `scm_set_port_input_waiting' procedure.
+
* examples/echo/client.scm (main): Call `close' on a channel.
* examples/echo/server.scm (main): Likewise.
diff --git a/examples/echo/server.scm b/examples/echo/server.scm
index b13675a..8aa07b7 100755
--- a/examples/echo/server.scm
+++ b/examples/echo/server.scm
@@ -120,13 +120,13 @@
((request-channel-open)
(set! channel (handle-req-channel-open msg msg-type))
- (let poll ((count #f))
- (if (or (not count) (zero? count))
- (poll (channel-poll channel #f))
+ (let poll ((ready? #f))
+ (if ready?
(let ((str (read-line channel)))
(format #t "Received message: ~a~%" str)
(display "Echoing back...\n")
- (display str channel))))
+ (display str channel))
+ (poll (char-ready? channel))))
(close channel))
((request-channel)
diff --git a/src/channel-type.c b/src/channel-type.c
index 14fc215..fd33399 100644
--- a/src/channel-type.c
+++ b/src/channel-type.c
@@ -82,10 +82,16 @@ ptob_flush (SCM channel)
static int
ptob_input_waiting (SCM channel)
+#define FUNC_NAME "input-waiting"
{
- /* DEBUG */
- scm_puts ("input_waiting: Called.\n", scm_current_output_port ());
+ struct channel_data *cd = _scm_to_ssh_channel (channel);
+ int res = ssh_channel_poll (cd->ssh_channel, cd->is_stderr);
+ if (res < 0)
+ guile_ssh_error1 (FUNC_NAME, "An error occured.", channel);
+
+ return res;
}
+#undef FUNC_NAME
static int
ptob_close (SCM channel)
@@ -240,6 +246,7 @@ init_channel_type (void)
&ptob_write);
scm_set_port_close (channel_tag, ptob_close);
scm_set_port_flush (channel_tag, ptob_flush);
+ scm_set_port_input_waiting (channel_tag, ptob_input_waiting);
scm_set_port_mark (channel_tag, mark_channel);
scm_set_port_free (channel_tag, free_channel);
scm_set_port_print (channel_tag, print_channel);