Merge pull request #19 from john-peterson/rt2

support winrt
This commit is contained in:
Arvid Norberg 2015-07-04 10:06:30 -04:00
commit bf20af1e05
6 changed files with 33 additions and 12 deletions

View File

@ -3,11 +3,18 @@
#include <boost/system/error_code.hpp> #include <boost/system/error_code.hpp>
#include <boost/system/system_error.hpp> #include <boost/system/system_error.hpp>
#include "libtorrent/config.hpp"
#include "libtorrent/ed25519.hpp" #include "libtorrent/ed25519.hpp"
#ifndef ED25519_NO_SEED #ifndef ED25519_NO_SEED
#ifdef _WIN32 #if TORRENT_USE_CRYPTOGRAPHIC_BUFFER
#include <robuffer.h>
#include <wrl/client.h>
using namespace Windows::Security::Cryptography;
using namespace Windows::Storage::Streams;
using namespace Microsoft::WRL;
#elif defined _WIN32
#include <Windows.h> #include <Windows.h>
#include <Wincrypt.h> #include <Wincrypt.h>
#else #else
@ -15,7 +22,12 @@
#endif #endif
void ed25519_create_seed(unsigned char *seed) { void ed25519_create_seed(unsigned char *seed) {
#ifdef _WIN32 #if TORRENT_USE_CRYPTOGRAPHIC_BUFFER
IBuffer^ seedBuffer = CryptographicBuffer::GenerateRandom(32);
ComPtr<IBufferByteAccess> bufferByteAccess;
reinterpret_cast<IInspectable*>(seedBuffer)->QueryInterface(IID_PPV_ARGS(&bufferByteAccess));
bufferByteAccess->Buffer(&seed);
#elif defined _WIN32
HCRYPTPROV prov; HCRYPTPROV prov;
if (!CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { if (!CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {

View File

@ -1279,7 +1279,7 @@ namespace libtorrent
virtual std::string message() const; virtual std::string message() const;
TORRENT_NOT_DISCARDABLE TORRENT_NOT_DISCARDABLE
#ifndef TORRENT_NO_DEPRECATE #if !defined(TORRENT_NO_DEPRECATE) && !defined(TORRENT_WINRT)
// the interface libtorrent attempted to listen on // the interface libtorrent attempted to listen on
std::string interface; std::string interface;
#endif #endif

View File

@ -275,6 +275,15 @@ POSSIBILITY OF SUCH DAMAGE.
#define TORRENT_USE_PREADV 1 #define TORRENT_USE_PREADV 1
#define TORRENT_USE_PWRITEV 1 #define TORRENT_USE_PWRITEV 1
// ==== WINRT ===
#if defined(WINAPI_FAMILY_PARTITION)
# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) \
&& !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
# define TORRENT_WINRT
# define TORRENT_USE_CRYPTOGRAPHIC_BUFFER 1
# endif
#endif
// ==== SOLARIS === // ==== SOLARIS ===
#elif defined sun || defined __sun #elif defined sun || defined __sun
#define TORRENT_SOLARIS #define TORRENT_SOLARIS

View File

@ -65,16 +65,16 @@ namespace libtorrent
int get_file_attributes(std::string const& p) int get_file_attributes(std::string const& p)
{ {
#ifdef TORRENT_WINDOWS #ifdef TORRENT_WINDOWS
WIN32_FILE_ATTRIBUTE_DATA attr;
#if TORRENT_USE_WSTRING #if TORRENT_USE_WSTRING
std::wstring path = convert_to_wstring(p); std::wstring path = convert_to_wstring(p);
DWORD attr = GetFileAttributesW(path.c_str()); GetFileAttributesExW(path.c_str(), GetFileExInfoStandard, &attr);
#else #else
std::string path = convert_to_native(p); std::string path = convert_to_native(p);
DWORD attr = GetFileAttributesA(path.c_str()); GetFileAttributesExA(path.c_str(), GetFileExInfoStandard, &attr);
#endif // TORRENT_USE_WSTRING #endif // TORRENT_USE_WSTRING
if (attr == INVALID_FILE_ATTRIBUTES) return 0; if (attr.dwFileAttributes == INVALID_FILE_ATTRIBUTES) return 0;
if (attr & FILE_ATTRIBUTE_HIDDEN) return file_storage::attribute_hidden; if (attr.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) return file_storage::attribute_hidden;
return 0; return 0;
#else #else
struct stat s; struct stat s;

View File

@ -63,7 +63,7 @@ using libtorrent::dht::node;
using libtorrent::dht::node_id; using libtorrent::dht::node_id;
using libtorrent::dht::packet_t; using libtorrent::dht::packet_t;
using libtorrent::dht::msg; using libtorrent::dht::msg;
using namespace libtorrent::detail; using libtorrent::detail::write_endpoint;
enum enum
{ {

View File

@ -105,7 +105,7 @@ namespace libtorrent
condition_variable::condition_variable() condition_variable::condition_variable()
: m_num_waiters(0) : m_num_waiters(0)
{ {
m_sem = CreateSemaphore(0, 0, INT_MAX, 0); m_sem = CreateSemaphoreEx(0, 0, INT_MAX, 0, 0, SEMAPHORE_ALL_ACCESS);
} }
condition_variable::~condition_variable() condition_variable::~condition_variable()
@ -118,7 +118,7 @@ namespace libtorrent
TORRENT_ASSERT(l.locked()); TORRENT_ASSERT(l.locked());
++m_num_waiters; ++m_num_waiters;
l.unlock(); l.unlock();
WaitForSingleObject(m_sem, INFINITE); WaitForSingleObjectEx(m_sem, INFINITE, FALSE);
l.lock(); l.lock();
--m_num_waiters; --m_num_waiters;
} }
@ -128,7 +128,7 @@ namespace libtorrent
TORRENT_ASSERT(l.locked()); TORRENT_ASSERT(l.locked());
++m_num_waiters; ++m_num_waiters;
l.unlock(); l.unlock();
WaitForSingleObject(m_sem, total_milliseconds(rel_time)); WaitForSingleObjectEx(m_sem, total_milliseconds(rel_time), FALSE);
l.lock(); l.lock();
--m_num_waiters; --m_num_waiters;
} }