فهرست منبع

2010-01-24 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Fixed compile error with i586-mingw32msvc-g++.  Always Cut console
	readout by 80 characters in mingw32 build.  Catch exception in
	DHTMessageReceiver::receiveMessage().
	* src/AbstractDiskWriter.cc
	* src/ConsoleStatCalc.cc
	* src/DHTMessageReceiver.cc
	* src/File.cc
	* src/RequestGroupMan.cc
	* src/a2io.h
	* test/FileTest.cc
Tatsuhiro Tsujikawa 15 سال پیش
والد
کامیت
b39ede01a7
8فایلهای تغییر یافته به همراه54 افزوده شده و 30 حذف شده
  1. 13 0
      ChangeLog
  2. 1 1
      src/AbstractDiskWriter.cc
  3. 11 10
      src/ConsoleStatCalc.cc
  4. 6 6
      src/DHTMessageReceiver.cc
  5. 1 1
      src/File.cc
  6. 7 2
      src/RequestGroupMan.cc
  7. 14 9
      src/a2io.h
  8. 1 1
      test/FileTest.cc

+ 13 - 0
ChangeLog

@@ -1,3 +1,16 @@
+2010-01-24  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Fixed compile error with i586-mingw32msvc-g++.  Always Cut console
+	readout by 80 characters in mingw32 build.  Catch exception in
+	DHTMessageReceiver::receiveMessage().
+	* src/AbstractDiskWriter.cc
+	* src/ConsoleStatCalc.cc
+	* src/DHTMessageReceiver.cc
+	* src/File.cc
+	* src/RequestGroupMan.cc
+	* src/a2io.h
+	* test/FileTest.cc
+
 2010-01-24  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Fixed compile error with intel compiler

+ 1 - 1
src/AbstractDiskWriter.cc

@@ -139,7 +139,7 @@ ssize_t AbstractDiskWriter::readDataInternal(unsigned char* data, size_t len)
 
 void AbstractDiskWriter::seek(off_t offset)
 {
-  if(lseek(fd, offset, SEEK_SET) == (off_t)-1) {
+  if(a2lseek(fd, offset, SEEK_SET) == (off_t)-1) {
     throw DL_ABORT_EX
       (StringFormat(EX_FILE_SEEK, _filename.c_str(), strerror(errno)).str());
   }

+ 11 - 10
src/ConsoleStatCalc.cc

@@ -42,6 +42,7 @@
 #endif // HAVE_SYS_IOCTL_H
 #include <unistd.h>
 
+#include <cstdio>
 #include <iomanip>
 #include <iostream>
 #include <algorithm>
@@ -218,25 +219,25 @@ ConsoleStatCalc::calculateStat(const DownloadEngine* e)
   }
   _cp.reset();
   const SizeFormatter& sizeFormatter = *_sizeFormatter.get();
-  bool isTTY = isatty(STDOUT_FILENO) == 1;
-  unsigned short int cols = 80;
+
 #ifdef __MINGW32__
+  bool isTTY = true;
   // Windows terminal cannot handle at the end of line properly.
-  --cols;
-#endif // __MINGW32__
+  unsigned short int cols = 79;
+#else // !__MINGW32__
+  bool isTTY = isatty(STDOUT_FILENO) == 1;
+  unsigned short int cols = 80;
+#endif // !__MINGW32__
+
   if(isTTY) {
+#ifndef __MINGW32__
 #ifdef HAVE_TERMIOS_H
     struct winsize size;
     if(ioctl(STDOUT_FILENO, TIOCGWINSZ, &size) == 0) {
       cols = size.ws_col;
-#ifdef __MINGW32__
-      if(cols > 0) {
-        // Windows terminal cannot handle at the end of line properly.
-        --cols;
-      }
-#endif // __MINGW32__
     }
 #endif // HAVE_TERMIOS_H
+#endif // !__MINGW32__
     std::cout << '\r' << std::setfill(' ') << std::setw(cols) << ' ' << '\r';
   }
   std::ostringstream o;

+ 6 - 6
src/DHTMessageReceiver.cc

@@ -66,13 +66,13 @@ SharedHandle<DHTMessage> DHTMessageReceiver::receiveMessage()
   std::string remoteAddr;
   uint16_t remotePort;
   unsigned char data[64*1024];
-  ssize_t length = _connection->receiveMessage(data, sizeof(data),
-                                               remoteAddr,
-                                               remotePort);
-  if(length <= 0) {
-    return SharedHandle<DHTMessage>();
-  }
   try {
+    ssize_t length = _connection->receiveMessage(data, sizeof(data),
+                                                 remoteAddr,
+                                                 remotePort);
+    if(length <= 0) {
+      return SharedHandle<DHTMessage>();
+    }
     bool isReply = false;
     const BDE dict = bencode::decode(data, length);
     if(dict.isDict()) {

+ 1 - 1
src/File.cc

@@ -59,7 +59,7 @@ File::File(const std::string& name):name(name) {}
 File::~File() {}
 
 int File::fillStat(a2_struct_stat& fstat) {
-  return stat(name.c_str(), &fstat);
+  return a2stat(name.c_str(), &fstat);
 }
 
 bool File::exists() {

+ 7 - 2
src/RequestGroupMan.cc

@@ -577,8 +577,13 @@ void RequestGroupMan::showDownloadResults(std::ostream& o) const
   o << "\n"
     <<_("Download Results:") << "\n"
     << "gid|stat|avg speed  |path/URI" << "\n"
-    << "===+====+===========+===========================================================" << "\n";
-
+    << "===+====+===========+";
+#ifdef __MINGW32__
+  int pathRowSize = 58;
+#else // !__MINGW32__
+  int pathRowSize = 59;
+#endif // !__MINGW32__
+  o << std::setfill('=') << std::setw(pathRowSize) << '=' << "\n";
   int ok = 0;
   int err = 0;
   int inpr = 0;

+ 14 - 9
src/a2io.h

@@ -113,22 +113,27 @@
 #endif // HAVE_WINSOCK2_H
 
 #ifdef __MINGW32__
-# define lseek(fd, offset, origin) _lseeki64(fd, offset, origin)
-# define fseek(fd, offset, origin) _fseeki64(fd, offset, origin)
-# define fstat(fd, buf) _fstati64(fd, buf)
-# define ftell(fd) _ftelli64(fd)
-# define wstat(path, buf) _wstati64(path, buf)
+# define a2lseek(fd, offset, origin) _lseeki64(fd, offset, origin)
+# define a2fseek(fd, offset, origin) _fseeki64(fd, offset, origin)
+# define a2fstat(fd, buf) _fstati64(fd, buf)
+# define a2ftell(fd) _ftelli64(fd)
+# define a2wstat(path, buf) _wstati64(path, buf)
 # ifdef stat
 #  undef stat
 # endif // stat
 # define a2_struct_stat struct _stati64
-# define stat(path, buf)  _stati64(path, buf)
-# define tell(handle) _telli64(handle)
+# define a2stat(path, buf)  _stati64(path, buf)
+# define a2tell(handle) _telli64(handle)
 # define a2mkdir(path, openMode) mkdir(path)
-#else
+#else // !__MINGW32__
+# define a2lseek(fd, offset, origin) lseek(fd, offset, origin)
+# define a2fseek(fp, offset, origin) fseek(fp, offset, origin)
+# define a2fstat(fp, buf) fstat(fp, buf)
+# define a2ftell(fp) ftell(fp)
 # define a2_struct_stat struct stat
+# define a2stat(path, buf) stat(path, buf)
 # define a2mkdir(path, openMode) mkdir(path, openMode)
-#endif // __MINGW32__
+#endif // !__MINGW32__
 
 #if defined HAVE_POSIX_MEMALIGN && defined O_DIRECT
 # define ENABLE_DIRECT_IO 1

+ 1 - 1
test/FileTest.cc

@@ -222,7 +222,7 @@ void FileTest::testUtime()
   CPPUNIT_ASSERT(f.utime(Time(atime), Time(mtime)));
   
   a2_struct_stat buf;
-  CPPUNIT_ASSERT(0 == stat(f.getPath().c_str(), &buf));
+  CPPUNIT_ASSERT(0 == a2stat(f.getPath().c_str(), &buf));
   CPPUNIT_ASSERT_EQUAL((time_t)atime, buf.st_atime);
   CPPUNIT_ASSERT_EQUAL((time_t)mtime, f.getModifiedTime().getTime());