[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[vidalia-svn] r1451: Really close the read channel when we want to stop reading f (trunk/src/control)



Author: edmanm
Date: 2006-11-09 00:00:52 -0500 (Thu, 09 Nov 2006)
New Revision: 1451

Modified:
   trunk/src/control/torprocess.cpp
   trunk/src/control/torprocess.h
Log:
Really close the read channel when we want to stop reading from stdout. Also
remove some includes we don't need anymore (which explains my previous
commit).


Modified: trunk/src/control/torprocess.cpp
===================================================================
--- trunk/src/control/torprocess.cpp	2006-11-09 04:57:49 UTC (rev 1450)
+++ trunk/src/control/torprocess.cpp	2006-11-09 05:00:52 UTC (rev 1451)
@@ -25,8 +25,7 @@
  * \brief Starts and stops a Tor process
  */
 
-#include <QFileInfo>
-#include <QCoreApplication>
+#include <QString>
 
 /* Needed for _PROCESS_INFORMATION so that pid() works on Win32 */
 #if defined (Q_OS_WIN32)
@@ -35,8 +34,6 @@
   
 #include "torprocess.h"
 
-/** Format of log message timestamps Tor prints to stdout */
-#define FMT_TIMESTAMP "MMM dd hh:mm:ss.zzz yyyy"
 
 /** Default constructor */
 TorProcess::TorProcess()
@@ -112,7 +109,6 @@
 void
 TorProcess::openStdout()
 {
-  _logState = Open;
   setReadChannelMode(QProcess::MergedChannels);
   setReadChannel(QProcess::StandardOutput);
 }
@@ -122,8 +118,10 @@
 void
 TorProcess::closeStdout()
 {
-  _logState = Closing;
-  _logCloseTime = QDateTime::currentDateTime();
+  /* Close the stdout channel */
+  closeReadChannel(QProcess::StandardOutput);
+  /* Read anything left waiting on the buffer */
+  onReadyRead();
 }
 
 /** Called when there is data to be read from stdout */
@@ -131,32 +129,15 @@
 TorProcess::onReadyRead()
 {
   int i, j;
+  QString line;
+  
   while (canReadLine()) {
-    /* Pull the waiting data from the buffer. Note that we do this even if the
-     * log event won't be emitted, so that the size of the waiting buffer doesn't 
-     * keep growing. */
-    QString line = readLine();
-    if (_logState == Closed) {
-      continue;
-    }
-    
-    /* If _logState != Closed, then we will parse the log message and emit log() */
-    i = line.indexOf("[");
-    j = line.indexOf("]");
-    if (i > 0 && j > 0) {
-      if (_logState == Closing) {
-        /* Parse the timestamp from this log message */
-        QString msgTime = QString("%1 %2").arg(line.mid(0, i-1))
-                                          .arg(_logCloseTime.date().year());
-          
-        if (_logCloseTime < QDateTime::fromString(msgTime, FMT_TIMESTAMP)) {
-          /* We've read all log messages from stdout since closeStdout() was
-           * called, so go ahead and close stdout for real. */
-          _logState = Closed;
-          closeReadChannel(QProcess::StandardOutput);
-        }
-      }
-      if (_logState != Closed) {
+    line = readLine();
+    if (!line.isEmpty()) {
+      /* Parse the log message and emit log() */
+      i = line.indexOf("[");
+      j = line.indexOf("]");
+      if (i > 0 && j > i && line.length() >= j+2) {
         emit log(line.mid(i+1, j-i-1), line.mid(j+2));
       }
     }

Modified: trunk/src/control/torprocess.h
===================================================================
--- trunk/src/control/torprocess.h	2006-11-09 04:57:49 UTC (rev 1450)
+++ trunk/src/control/torprocess.h	2006-11-09 05:00:52 UTC (rev 1451)
@@ -29,10 +29,6 @@
 #define _TORPROCESS_H
 
 #include <QProcess>
-#include <QFileInfo>
-#include <QVariant>
-#include <QMap>
-#include <QDateTime>
 
 
 class TorProcess : public QProcess
@@ -48,7 +44,6 @@
   /** Stop the Tor process */
   bool stop(QString *errmsg = 0);
 
-
   /** Return the Tor process's PID (workaround for some Windows funkiness) */
   quint64 pid();
 
@@ -69,18 +64,6 @@
   void onReadyRead();
   /** Called when an error occurs in the process. */
   void onError(QProcess::ProcessError error);
-
-private:
-  /** Status of logging to stdout. */
-  enum LogState {
-    Open,     /**< stdout logs enabled. */
-    Closing,  /**< stdout in the process of closing. */
-    Closed    /**< stdout logs closed. */
-  };
-  /** Current state of logging on stdout. */
-  LogState _logState;
-  /** Timestamp of when stdout logs closed. */
-  QDateTime _logCloseTime;
 };
 
 #endif