summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-console/filetransfer.cpp
Side-by-side diff
Diffstat (limited to 'noncore/apps/opie-console/filetransfer.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/filetransfer.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/noncore/apps/opie-console/filetransfer.cpp b/noncore/apps/opie-console/filetransfer.cpp
index 7eebc65..6e2d2d5 100644
--- a/noncore/apps/opie-console/filetransfer.cpp
+++ b/noncore/apps/opie-console/filetransfer.cpp
@@ -1,54 +1,55 @@
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
+#include <opie2/odebug.h>
#include <qsocketnotifier.h>
#include "procctl.h"
#include "filetransfer.h"
FileTransfer::FileTransfer( Type t, IOLayer* lay )
: FileTransferLayer( lay ), m_type( t ), m_pid ( 0 ) {
signal(SIGPIPE, SIG_IGN );
m_pid = 0;
m_not = 0l;
m_proc = 0l;
}
FileTransfer::~FileTransfer() {
}
/**
* now we will send the file.
*
* we request an fd. The IOLayer should be closed
* then we will setup a pipe for progress communication
* then we will dup2 the m_fd in the forked process
* to do direct IO from and to the fd
*/
void FileTransfer::sendFile( const QString& file ) {
m_prog =-1;
m_fd = layer()->rawIO();
//
// m_fd = ::open("/dev/ttyS0", O_RDWR);
m_file = file;
if ( pipe( m_comm ) < 0 )
m_comm[0] = m_comm[1] = 0;
if ( pipe( m_info ) < 0 )
m_info[0] = m_info[1] = 0;
m_pid = fork();
switch( m_pid ) {
case -1:
emit error( StartError, tr("Was not able to fork") );
slotExec();
break;
case 0:{
setupChild();
/* exec */
char* verbose = "-vv";
@@ -189,60 +190,61 @@ void FileTransfer::slotProgress( const QStringList& list ) {
if ( m_type != SZ )
return;
bool complete = true;
int min, sec;
int bps;
unsigned long sent, total;
min = sec = bps = -1;
sent = total = 0;
// Data looks like this
// 0 1 2 3 4 5
// Bytes Sent 65536/11534336 BPS:7784 ETA 24:33
QStringList progi = QStringList::split('/', list[2].simplifyWhiteSpace() );
sent = progi[0].toULong(&complete );
if (!complete ) return;
total = progi[1].toULong(&complete );
if (!complete || total == 0) {
return;
}
double pro = (double)sent/total;
int prog = pro * 100;
// speed
progi = QStringList::split(':', list[3].simplifyWhiteSpace() );
bps = progi[1].toInt();
// time
progi = QStringList::split(':', list[5].simplifyWhiteSpace() );
min = progi[0].toInt();
sec = progi[1].toInt();
if ( prog > m_prog ) {
m_prog = prog;
emit progress(m_file, m_prog, bps, -1, min , sec );
}
}
void FileTransfer::cancel() {
if(m_pid > 0) ::kill(m_pid,9 );
}
void FileTransfer::slotExec() {
char buf[2];
- ::read(m_term[0], buf, 1 );
+ if (::read(m_term[0], buf, 1 ) == -1)
+ owarn << "read of m_term[0] failed" << oendl;
delete m_proc;
delete m_not;
m_proc = m_not = 0l;
close( m_term[0] );
close( m_term[1] );
close( m_comm[0] );
close( m_comm[1] );
layer()->closeRawIO( m_fd );
emit sent();
m_pid = 0;
}