Esempio n. 1
0
	HICON image_accessor::icon(const nana::paint::image& img)
	{
		auto ico_res = dynamic_cast<paint::detail::image_ico_resource*>(img.image_ptr_.get());
		if (ico_res)
			return reinterpret_cast<HICON>(ico_res->native_handle());

		auto ico = dynamic_cast<paint::detail::image_ico*>(img.image_ptr_.get());
		if (ico)
			return reinterpret_cast<HICON>(ico->native_handle());

		return nullptr;
	}
Esempio n. 2
0
	// this has to be thread safe and atomic. i.e. on posix systems it has to be
	// turned into a series of pread() calls
	std::int64_t file::readv(std::int64_t file_offset, span<iovec_t const> bufs
		, error_code& ec, open_mode_t flags)
	{
		if (m_file_handle == INVALID_HANDLE_VALUE)
		{
#ifdef TORRENT_WINDOWS
			ec = error_code(ERROR_INVALID_HANDLE, system_category());
#else
			ec = error_code(boost::system::errc::bad_file_descriptor, generic_category());
#endif
			return -1;
		}
		TORRENT_ASSERT((m_open_mode & open_mode::rw_mask) == open_mode::read_only
			|| (m_open_mode & open_mode::rw_mask) == open_mode::read_write);
		TORRENT_ASSERT(!bufs.empty());
		TORRENT_ASSERT(is_open());

#if TORRENT_USE_PREADV
		TORRENT_UNUSED(flags);
		std::int64_t ret = iov(&::preadv, native_handle(), file_offset, bufs, ec);
#else

		// there's no point in coalescing single buffer writes
		if (bufs.size() == 1)
		{
			flags &= ~open_mode::coalesce_buffers;
		}

		iovec_t tmp;
		span<iovec_t const> tmp_bufs = bufs;
		if (flags & open_mode::coalesce_buffers)
		{
			if (!coalesce_read_buffers(tmp_bufs, tmp))
				// ok, that failed, don't coalesce this read
				flags &= ~open_mode::coalesce_buffers;
		}

#if TORRENT_USE_PREAD
		std::int64_t ret = iov(&::pread, native_handle(), file_offset, tmp_bufs, ec);
#else
		std::int64_t ret = iov(&::read, native_handle(), file_offset, tmp_bufs, ec);
#endif

		if (flags & open_mode::coalesce_buffers)
			coalesce_read_buffers_end(bufs
				, tmp.data(), !ec);

#endif
		return ret;
	}
Esempio n. 3
0
	std::int64_t file::sparse_end(std::int64_t start) const
	{
#ifdef TORRENT_WINDOWS

#ifndef FSCTL_QUERY_ALLOCATED_RANGES
typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
	LARGE_INTEGER FileOffset;
	LARGE_INTEGER Length;
} FILE_ALLOCATED_RANGE_BUFFER;
#define FSCTL_QUERY_ALLOCATED_RANGES ((0x9 << 16) | (1 << 14) | (51 << 2) | 3)
#endif // TORRENT_MINGW

		FILE_ALLOCATED_RANGE_BUFFER buffer;
		DWORD bytes_returned = 0;
		FILE_ALLOCATED_RANGE_BUFFER in;
		error_code ec;
		std::int64_t file_size = get_size(ec);
		if (ec) return start;

		in.FileOffset.QuadPart = start;
		in.Length.QuadPart = file_size - start;

		if (!DeviceIoControl(native_handle(), FSCTL_QUERY_ALLOCATED_RANGES
			, &in, sizeof(FILE_ALLOCATED_RANGE_BUFFER)
			, &buffer, sizeof(FILE_ALLOCATED_RANGE_BUFFER), &bytes_returned, 0))
		{
			if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) return start;
		}

		// if there are no allocated regions within the rest
		// of the file, return the end of the file
		if (bytes_returned == 0) return file_size;

		// assume that this range overlaps the start of the
		// region we were interested in, and that start actually
		// resides in an allocated region.
		if (buffer.FileOffset.QuadPart < start) return start;

		// return the offset to the next allocated region
		return buffer.FileOffset.QuadPart;

#elif defined SEEK_DATA
		// this is supported on solaris
		std::int64_t ret = ::lseek(native_handle(), start, SEEK_DATA);
		if (ret < 0) return start;
		return start;
#else
		return start;
#endif
	}
Esempio n. 4
0
	void sdl_window::activate()
	{
		SDL_RaiseWindow(iHandle);
#ifdef WIN32
		SetWindowPos(static_cast<HWND>(native_handle()), 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
#endif
	}
Esempio n. 5
0
void EasyTreeWidgetLoader::interrupt(bool _wait)
{
    m_bInterrupt.store(true);
    if (m_thread.joinable())
        m_thread.join();

    m_bInterrupt.store(false);
    m_bDone.store(false);
    m_progress.store(0);

    if (!_wait)
    {
        auto deleter_thread = ::std::thread([](decltype(m_topLevelItems) _items) {
            for (auto item : _items)
                delete item.second;
        }, ::std::move(m_topLevelItems));

#ifdef _WIN32
        SetThreadPriority(deleter_thread.native_handle(), THREAD_PRIORITY_LOWEST);
#endif

        deleter_thread.detach();
    }
    else
    {
        for (auto item : m_topLevelItems)
            delete item.second;
    }

    m_items.clear();
    m_topLevelItems.clear();
}
Esempio n. 6
0
bool WorldSocket::SendPacket(const WorldPacket& pct)
{
    if (IsClosed())
        return false;

    // Dump outgoing packet.
    sLog.outWorldPacketDump(native_handle(), pct.GetOpcode(), pct.GetOpcodeName(), &pct, false);

    ServerPktHeader header(pct.size() + 2, pct.GetOpcode());
    crypt_.EncryptSend((uint8*) header.header, header.getHeaderLength());

    GuardType Guard(out_buffer_lock_);

    if (out_buffer_->space() >= pct.size() + header.getHeaderLength())
    {
        // Put the packet on the buffer.
        if (!out_buffer_->Write(header.header, header.getHeaderLength()))
            MANGOS_ASSERT(false);

        if (!pct.empty() && !out_buffer_->Write(pct.contents(), pct.size()))
            MANGOS_ASSERT(false);
    }
    else
    {
        // Enqueue the packet.
        throw std::exception("network write buffer is too small to accommodate packet");
    }

    StartAsyncSend();

    return true;
}
Esempio n. 7
0
	void sdl_window::hide()
	{
#ifdef WIN32
		ShowWindow(static_cast<HWND>(native_handle()), SW_HIDE);
#else
		SDL_HideWindow(iHandle);
#endif
	}
Esempio n. 8
0
_posix_mutex::_posix_mutex(int mutex_type) {
  pthread_mutexattr_t mutex_attribute;
  handle_err_return(pthread_mutexattr_init(&mutex_attribute));
  handle_err_return(pthread_mutexattr_settype(&mutex_attribute,
                                              mutex_type));
  handle_err_return(pthread_mutex_init(native_handle(), &mutex_attribute));
  handle_err_return(pthread_mutexattr_destroy(&mutex_attribute));
}
void peer_connection_handle::add_extension(boost::shared_ptr<peer_plugin> ext)
{
#ifndef TORRENT_DISABLE_EXTENSIONS
	boost::shared_ptr<peer_connection> pc = native_handle();
	TORRENT_ASSERT(pc);
	pc->add_extension(ext);
#endif
}
Esempio n. 10
0
void bt_peer_connection_handle::switch_recv_crypto(boost::shared_ptr<crypto_plugin> crypto)
{
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
	boost::shared_ptr<bt_peer_connection> pc = native_handle();
	TORRENT_ASSERT(pc);
	pc->switch_recv_crypto(crypto);
#endif
}
Esempio n. 11
0
	void sdl_window::show(bool aActivate)
	{
#ifdef WIN32
		ShowWindow(static_cast<HWND>(native_handle()), aActivate ? SW_SHOW : SW_SHOWNA);
#else
		SDL_ShowWindow(iHandle);
#endif
	}
Esempio n. 12
0
torrent_handle peer_connection_handle::associated_torrent() const
{
	boost::shared_ptr<peer_connection> pc = native_handle();
	if (!pc) return torrent_handle();
	boost::shared_ptr<torrent> t = pc->associated_torrent().lock();
	if (!t) return torrent_handle();
	return t->get_handle();
}
Esempio n. 13
0
bool _posix_mutex::try_lock() {
  int result = pthread_mutex_trylock(native_handle());
  if (result == 0) {
    return true;
  } else if (result != EBUSY) {
    handle_err_return(result);
  }
  return false;
}
Esempio n. 14
0
	void file::close()
	{
		if (!is_open()) return;

#ifdef TORRENT_WINDOWS

		// if this file is open for writing, has the sparse
		// flag set, but there are no sparse regions, unset
		// the flag
		open_mode_t const rw_mode = m_open_mode & open_mode::rw_mask;
		if ((rw_mode != open_mode::read_only)
			&& (m_open_mode & open_mode::sparse)
			&& !is_sparse(native_handle()))
		{
			overlapped_t ol;
			// according to MSDN, clearing the sparse flag of a file only
			// works on windows vista and later
#ifdef TORRENT_MINGW
			typedef struct _FILE_SET_SPARSE_BUFFER {
				BOOLEAN SetSparse;
			} FILE_SET_SPARSE_BUFFER;
#endif
			DWORD temp;
			FILE_SET_SPARSE_BUFFER b;
			b.SetSparse = FALSE;
			BOOL ret = ::DeviceIoControl(native_handle(), FSCTL_SET_SPARSE, &b, sizeof(b)
				, 0, 0, &temp, &ol.ol);
			error_code ec;
			if (ret == FALSE && GetLastError() == ERROR_IO_PENDING)
			{
				ol.wait(native_handle(), ec);
			}
		}

		CloseHandle(native_handle());
#else
		if (m_file_handle != INVALID_HANDLE_VALUE)
			::close(m_file_handle);
#endif

		m_file_handle = INVALID_HANDLE_VALUE;

		m_open_mode = open_mode_t{};
	}
Esempio n. 15
0
void IOCPPool::svc_worker()
{

	DWORD BytesTransferred;

	Session* pkey=NULL;
	MyOverLapped* pdat;
	BOOL bRet;

	while(!test_canceled())
	{

		bRet = GetQueuedCompletionStatus(hIOCPhandler.get(), &BytesTransferred, (PULONG_PTR)&pkey, (LPOVERLAPPED*)&pdat,100);
		if(bRet == 0)
		{
			int r=::WSAGetLastError();

			if(r==WAIT_TIMEOUT)
			{
				continue;
			}

			if(pdat==NULL)
			{
				System::LogError("NULL Overlapped, worker exit!");
				break;
			}

			if(r!=ERROR_OPERATION_ABORTED && r!=ERROR_NETNAME_DELETED && r!=1236)
			{
				System::CheckError("GetQueuedCompletionStatus");
			}

			pkey->Disconnect();

		}

		if(!pdat)
		{
			if(pkey->m_nPendingSend.get()==0 && pkey->m_nPendingRecv.get()==1)
			{
				--pkey->m_nPendingRecv;
			}
			else
			{
				PostQueuedCompletionStatus(native_handle(),0,(ULONG_PTR)pkey,NULL);
			}
		}
		else
		{
			pdat->size=BytesTransferred;
			ccc_handle_iocp(pkey,pdat);
		}

	}
}
Esempio n. 16
0
peer_plugin const* peer_connection_handle::find_plugin(char const* type)
{
#ifndef TORRENT_DISABLE_EXTENSIONS
	boost::shared_ptr<peer_connection> pc = native_handle();
	TORRENT_ASSERT(pc);
	return pc->find_plugin(type);
#else
	return NULL;
#endif
}
Esempio n. 17
0
bool bt_peer_connection_handle::supports_encryption() const
{
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
	boost::shared_ptr<bt_peer_connection> pc = native_handle();
	TORRENT_ASSERT(pc);
	return pc->supports_encryption();
#else
	return false;
#endif
}
Esempio n. 18
0
bool peer_connection_handle::should_log(peer_log_alert::direction_t direction) const
{
#ifndef TORRENT_DISABLE_LOGGING
	std::shared_ptr<peer_connection> pc = native_handle();
	TORRENT_ASSERT(pc);
	return pc->should_log(direction);
#else
	TORRENT_UNUSED(direction);
	return false;
#endif
}
Esempio n. 19
0
	std::int64_t file::get_size(error_code& ec) const
	{
#ifdef TORRENT_WINDOWS
		LARGE_INTEGER file_size;
		if (!GetFileSizeEx(native_handle(), &file_size))
		{
			ec.assign(GetLastError(), system_category());
			return -1;
		}
		return file_size.QuadPart;
#else
		struct stat fs;
		if (::fstat(native_handle(), &fs) != 0)
		{
			ec.assign(errno, system_category());
			return -1;
		}
		return fs.st_size;
#endif
	}
Esempio n. 20
0
	ITERATOR send(ITERATOR begin, ITERATOR end) const {
		std::vector<uint8_t> data;

		for(auto it = begin; it != end; ++it) {
			uint8_t byte = *it;

			data.push_back(byte);
		}

		return std::next(begin, socket_send(native_handle(), &data[0], data.size()));
	}
Esempio n. 21
0
	void sdl_window::set_capture()
	{
		if (!iCapturingMouse)
		{
			iCapturingMouse = true; 
			SDL_CaptureMouse(SDL_TRUE);
#ifdef WIN32
			SetCapture(static_cast<HWND>(native_handle()));
#endif
		}
	}
Esempio n. 22
0
void peer_connection_handle::peer_log(peer_log_alert::direction_t direction
	, char const* event, char const* fmt, ...) const
{
#ifndef TORRENT_DISABLE_LOGGING
	boost::shared_ptr<peer_connection> pc = native_handle();
	TORRENT_ASSERT(pc);
	va_list v;
	va_start(v, fmt);
	pc->peer_log(direction, event, fmt, v);
	va_end(v);
#endif
}
void peer_connection_handle::peer_log(peer_log_alert::direction_t direction
	, char const* event, char const* fmt, ...) const
{
	boost::shared_ptr<peer_connection> pc = native_handle();
	TORRENT_ASSERT(pc);
	va_list v;
	va_start(v, fmt);
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-nonliteral"
#endif
	pc->peer_log(direction, event, fmt, v);
#ifdef __clang__
#pragma clang diagnostic pop
#endif
	va_end(v);
}
Esempio n. 24
0
	void sdl_window::close()
	{
		if (iHandle != 0)
		{
			release_capture();
			event_handler().native_window_closing();
			if (!iDestroyed)
			{
#ifdef WIN32
				DestroyWindow(static_cast<HWND>(native_handle()));
#endif
				SDL_DestroyWindow(iHandle);
			}
			iHandle = 0;
			event_handler().native_window_closed();
		}
	}
Esempio n. 25
0
std::shared_ptr<ssl_context> WSService::make_ssl_ctx() {
	auto ssl_ctx_ptr = std::make_shared<ssl_context>(ssl_context::tlsv12);

	// SSL settings
	ssl_ctx_ptr->set_options(
		ssl_context::default_workarounds |
			ssl_context::single_dh_use |
			ssl_context::no_sslv2 |
			ssl_context::no_sslv3 |
			ssl_context::no_tlsv1 |
			ssl_context::no_tlsv1_1
	);

	ssl_ctx_ptr->set_verify_mode(boost::asio::ssl::verify_peer | boost::asio::ssl::verify_fail_if_no_peer_cert);
	ssl_ctx_ptr->use_certificate_file(Config::get()->paths().cert_path.string(std::codecvt_utf8_utf16<wchar_t>()), ssl_context::pem);
	ssl_ctx_ptr->use_private_key_file(Config::get()->paths().key_path.string(std::codecvt_utf8_utf16<wchar_t>()), ssl_context::pem);
	SSL_CTX_set_cipher_list(ssl_ctx_ptr->native_handle(), "ECDH-ECDSA-AES256-GCM-SHA384:ECDH-ECDSA-AES256-SHA384:ECDH-ECDSA-AES128-GCM-SHA256:ECDH-ECDSA-AES128-SHA256");

	return ssl_ctx_ptr;
}
Esempio n. 26
0
	void sdl_window::init()
	{
		sHandleMap[native_handle()] = this;
#ifdef WIN32
		iSDLWindowProc = (WNDPROC)SetWindowLongPtr(static_cast<HWND>(native_handle()), GWLP_WNDPROC, (LONG_PTR)&CustomWindowProc);
		DWORD existingStyle = GetWindowLongPtr(static_cast<HWND>(native_handle()), GWL_STYLE);
		DWORD newStyle = existingStyle;
		if (iStyle & window::None)
			newStyle |= WS_POPUP;
		if ((iStyle & window::MinimizeBox) != window::MinimizeBox)
			newStyle &= ~WS_MINIMIZEBOX;
		if ((iStyle & window::MaximizeBox) != window::MaximizeBox)
			newStyle &= ~WS_MAXIMIZEBOX;
		if (newStyle != existingStyle)
			SetWindowLongPtr(static_cast<HWND>(native_handle()), GWL_STYLE, newStyle);
		if (iStyle & window::NoActivate)
			SetWindowLongPtr(static_cast<HWND>(native_handle()), GWL_EXSTYLE, GetWindowLongPtr(static_cast<HWND>(native_handle()), GWL_EXSTYLE) | WS_EX_NOACTIVATE | WS_EX_TOPMOST);
		if (iParent != 0)
			SetWindowLongPtr(static_cast<HWND>(native_handle()), GWL_HWNDPARENT, reinterpret_cast<LONG>(iParent->native_handle()));
		SetWindowPos(static_cast<HWND>(native_handle()), 0, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED | SWP_HIDEWINDOW);
#endif
	}
Esempio n. 27
0
void peer_connection_handle::peer_log(peer_log_alert::direction_t direction
	, char const* event, char const* fmt, ...) const
{
#ifndef TORRENT_DISABLE_LOGGING
	std::shared_ptr<peer_connection> pc = native_handle();
	TORRENT_ASSERT(pc);
	va_list v;
	va_start(v, fmt);
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-nonliteral"
#pragma clang diagnostic ignored "-Wclass-varargs"
#endif
	pc->peer_log(direction, event, fmt, v);
#ifdef __clang__
#pragma clang diagnostic pop
#endif
	va_end(v);
#else // TORRENT_DISABLE_LOGGING
	TORRENT_UNUSED(direction);
	TORRENT_UNUSED(event);
	TORRENT_UNUSED(fmt);
#endif
}
Esempio n. 28
0
    ip::udp::socket::native_handle_type native_socket2
      = ::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
    socket1.assign(ip::udp::v4(), native_socket2);
    ip::udp::socket::native_handle_type native_socket3
      = ::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
    socket1.assign(ip::udp::v4(), native_socket3, ec);
#endif // !defined(ASIO_WINDOWS_RUNTIME)

    bool is_open = socket1.is_open();
    (void)is_open;

    socket1.close();
    socket1.close(ec);

    ip::udp::socket::native_handle_type native_socket4
      = socket1.native_handle();
    (void)native_socket4;

    socket1.cancel();
    socket1.cancel(ec);

    bool at_mark1 = socket1.at_mark();
    (void)at_mark1;
    bool at_mark2 = socket1.at_mark(ec);
    (void)at_mark2;

    std::size_t available1 = socket1.available();
    (void)available1;
    std::size_t available2 = socket1.available(ec);
    (void)available2;
Esempio n. 29
0
// native HANDLE: HANDLE for windows, int for non-windows
DSN_API void* dsn_file_native_handle(dsn_handle_t file)
{
    auto dfile = (::dsn::disk_file*)file;
    return dfile->native_handle();
}
Esempio n. 30
0
			void thread::set_context(const context_type& con)
			{
				SetThreadContext(native_handle(), &con);
			}