merged some windows fixes from RC_0_16

This commit is contained in:
Arvid Norberg 2013-01-06 18:38:33 +00:00
parent 38d7e58177
commit d8c2228ff3
4 changed files with 32 additions and 1 deletions

View File

@ -1209,6 +1209,19 @@ namespace libtorrent
size_type file::readv(size_type file_offset, iovec_t const* bufs, int num_bufs, error_code& ec) size_type file::readv(size_type file_offset, iovec_t const* bufs, int num_bufs, error_code& ec)
{ {
#ifdef TORRENT_WINDOWS
if (m_file_handle == INVALID_HANDLE_VALUE)
{
ec = error_code(ERROR_INVALID_HANDLE, get_system_category());
return -1;
}
#else
if (m_file_handle == -1)
{
ec = error_code(EBADF, get_system_category());
return -1;
}
#endif
TORRENT_ASSERT((m_open_mode & rw_mask) == read_only || (m_open_mode & rw_mask) == read_write); TORRENT_ASSERT((m_open_mode & rw_mask) == read_only || (m_open_mode & rw_mask) == read_write);
TORRENT_ASSERT(bufs); TORRENT_ASSERT(bufs);
TORRENT_ASSERT(num_bufs > 0); TORRENT_ASSERT(num_bufs > 0);
@ -1420,6 +1433,19 @@ namespace libtorrent
size_type file::writev(size_type file_offset, iovec_t const* bufs, int num_bufs, error_code& ec) size_type file::writev(size_type file_offset, iovec_t const* bufs, int num_bufs, error_code& ec)
{ {
#ifdef TORRENT_WINDOWS
if (m_file_handle == INVALID_HANDLE_VALUE)
{
ec = error_code(ERROR_INVALID_HANDLE, get_system_category());
return -1;
}
#else
if (m_file_handle == -1)
{
ec = error_code(EBADF, get_system_category());
return -1;
}
#endif
TORRENT_ASSERT((m_open_mode & rw_mask) == write_only || (m_open_mode & rw_mask) == read_write); TORRENT_ASSERT((m_open_mode & rw_mask) == write_only || (m_open_mode & rw_mask) == read_write);
TORRENT_ASSERT(bufs); TORRENT_ASSERT(bufs);
TORRENT_ASSERT(num_bufs > 0); TORRENT_ASSERT(num_bufs > 0);

View File

@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/config.hpp> #include <boost/config.hpp>
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> // for exit()
int test_main(); int test_main();

View File

@ -232,12 +232,16 @@ void create_random_files(std::string const& path, const int file_sizes[], int nu
snprintf(filename, sizeof(filename), "%s/test%d", path.c_str(), i); snprintf(filename, sizeof(filename), "%s/test%d", path.c_str(), i);
int to_write = file_sizes[i]; int to_write = file_sizes[i];
file f(filename, file::write_only, ec); file f(filename, file::write_only, ec);
if (ec) fprintf(stderr, "failed to create file \"%s\": (%d) %s\n"
, filename, ec.value(), ec.message().c_str());
size_type offset = 0; size_type offset = 0;
while (to_write > 0) while (to_write > 0)
{ {
int s = (std::min)(to_write, 300000); int s = (std::min)(to_write, 300000);
file::iovec_t b = { random_data, s}; file::iovec_t b = { random_data, s};
f.writev(offset, &b, 1, ec); f.writev(offset, &b, 1, ec);
if (ec) fprintf(stderr, "failed to write file \"%s\": (%d) %s\n"
, filename, ec.value(), ec.message().c_str());
offset += s; offset += s;
to_write -= s; to_write -= s;
} }

View File

@ -101,7 +101,7 @@ void test_checking(bool read_only_files, bool corrupt_files = false)
char path[1024]; char path[1024];
snprintf(path, sizeof(path), "tmp1_checking/test_torrent_dir/test%d", i); snprintf(path, sizeof(path), "tmp1_checking/test_torrent_dir/test%d", i);
#ifdef TORRENT_WINDOWS #ifdef TORRENT_WINDOWS
SetFileAttributes(path, FILE_ATTRIBUTE_READONLY); SetFileAttributesA(path, FILE_ATTRIBUTE_READONLY);
#else #else
chmod(path, S_IRUSR); chmod(path, S_IRUSR);
#endif #endif