https://src.bluestatic.org
/
printdrop.git
/ commitdiff
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
4573398
)
Adding a method to clean up the code for reading the channel
author
Robert Sesek <rsesek@bluestatic.org>
Tue, 26 Feb 2008 16:35:15 +0000
(11:35 -0500)
committer
Robert Sesek <rsesek@bluestatic.org>
Tue, 26 Feb 2008 16:35:15 +0000
(11:35 -0500)
* Source/AppController.m
([AppController readChannel:]): New method
Source/AppController.m
patch
|
blob
|
history
diff --git
a/Source/AppController.m
b/Source/AppController.m
index 56a7ae4c92c1a7854ad1e42ed8e97a8da079d128..feaafda8336d321d3d6e5456710012c07a3b6080 100644
(file)
--- a/
Source/AppController.m
+++ b/
Source/AppController.m
@@
-25,6
+25,8
@@
//- (BOOL)uploadFile;
- (void)setStatus:(NSString *)msg isError:(BOOL)error;
//- (BOOL)uploadFile;
- (void)setStatus:(NSString *)msg isError:(BOOL)error;
+- (void)readChannel:(LIBSSH2_CHANNEL *)channel;
+
@end
@end
@@
-72,6
+74,25
@@
}
}
}
}
+/**
+ * Reads through a channel (in non-blocking) mode until there is no more left to read
+ * and then it returns. This calls sleep(1) so that the channel can have time to process.
+ * Be sure this is threaded otherwis the interface will stall.
+ */
+- (void)readChannel:(LIBSSH2_CHANNEL *)channel
+{
+ libssh2_channel_set_blocking(channel, 0);
+
+ char buf[1024];
+ int numbytes;
+ do
+ {
+ memset(&buf, '\0', sizeof(buf));
+ sleep(1);
+ numbytes = libssh2_channel_read(channel, buf, sizeof(buf));
+ } while (numbytes > 0);
+}
+
/**
* Sends an item to the printer
*/
/**
* Sends an item to the printer
*/
@@
-179,36
+200,12
@@
[self setStatus:@"Opened remote SSH shell" isError:NO];
[self setStatus:@"Opened remote SSH shell" isError:NO];
- libssh2_channel_flush_ex(channel, LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL);
-
- /*
- char *e = malloc(1024 * sizeof(char));
- libssh2_session_last_error(ssh, &e, NULL, 0);
- NSLog(@"e = %s", e);
- */
-
- libssh2_channel_set_blocking(channel, 0);
-
- char b[1024];
- int r;
- do
- {
- memset(&b, '\0', sizeof(b));
- sleep(1);
- r = libssh2_channel_read(channel, b, sizeof(b));
- NSLog(@"b(%i) = %s", r, b);
- } while (r > 0);
+ // read the banner
+ [self readChannel:channel];
char *cmd = "touch /u17/ugrad/rsesek/temp.foo\r\n\0";
char *cmd = "touch /u17/ugrad/rsesek/temp.foo\r\n\0";
- NSLog(@"numbytes = %i", libssh2_channel_write(channel, cmd, sizeof(char) * strlen(cmd)));
-
- do
- {
- memset(&b, '\0', sizeof(b));
- sleep(1);
- r = libssh2_channel_read(channel, b, sizeof(b));
- NSLog(@"b(%i) = %s", r, b);
- } while (r > 0);
+ libssh2_channel_write(channel, cmd, sizeof(char) * strlen(cmd));
+ [self readChannel:channel];
[self setStatus:@"Printed!" isError:NO];
[self setStatus:@"Printed!" isError:NO];