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
pull/1/head
Tatsuhiro Tsujikawa 2010-01-24 13:49:07 +00:00
parent 46605f66c3
commit b39ede01a7
8 changed files with 54 additions and 30 deletions

View File

@ -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

View File

@ -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());
}

View File

@ -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();
#ifdef __MINGW32__
bool isTTY = true;
// Windows terminal cannot handle at the end of line properly.
unsigned short int cols = 79;
#else // !__MINGW32__
bool isTTY = isatty(STDOUT_FILENO) == 1;
unsigned short int cols = 80;
#ifdef __MINGW32__
// Windows terminal cannot handle at the end of line properly.
--cols;
#endif // __MINGW32__
#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;

View File

@ -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()) {

View File

@ -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() {

View File

@ -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;

View File

@ -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

View File

@ -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());