Quelle ToastNotificationHeaderOnlyUtils.h
Sprache: C
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
/** * This header is intended for self-contained, header-only, utility code to * share between Windows toast notification code in firefox.exe and * notificationserver.dll.
*/
// Use XPCOM logging if we're in a XUL context, otherwise use Windows Event // logging. // NOTE: The `printf` `format` equivalent argument to `NOTIFY_LOG` is converted // to a wide string when outside of a XUL context. String format specifiers need // to specify they're a wide string with `%ls` or narrow string with `%hs`. #include"mozilla/Logging.h" #ifdef IMPL_LIBXUL namespace mozilla::widget { extern LazyLogModule sWASLog;
} // namespace mozilla::widget # define NOTIFY_LOG(_level, _args) \
MOZ_LOG(mozilla::widget::sWASLog, _level, _args) #else # include "mozilla/WindowsEventLog.h"
/* Handles running overlapped transactions for a Windows pipe. This function * manages lifetimes of Event and OVERLAPPED objects to ensure they are not used
* while an overlapped operation is pending. */ inlinebool SyncDoOverlappedIOWithTimeout( const nsAutoHandle& pipe, const size_t bytesExpected, const std::function<BOOL(OVERLAPPED&)>& transactPipe) {
nsAutoHandle event(CreateEventW(nullptr, TRUE, FALSE, nullptr)); if (!event) {
NOTIFY_LOG(
LogLevel::Error,
("Error creating pipe transaction event, error %lu", GetLastError())); returnfalse;
}
OVERLAPPED overlapped{};
overlapped.hEvent = event.get(); BOOL result = transactPipe(overlapped);
if (!result && GetLastError() != ERROR_IO_PENDING) {
NOTIFY_LOG(LogLevel::Error,
("Error reading from pipe, error %lu", GetLastError())); returnfalse;
}
if (!WaitEventWithTimeout(overlapped.hEvent)) {
NOTIFY_LOG(LogLevel::Warning, ("Pipe transaction timed out, canceling " "(transaction may still succeed)."));
CancelIo(pipe.get());
// Transaction may still succeed before cancellation is handled; fall // through to normal handling.
}
DWORD bytesTransferred = 0; // Pipe transfer has either been signaled or cancelled by this point, so it // should be safe to wait on. BOOL overlappedResult =
GetOverlappedResult(pipe.get(), &overlapped, &bytesTransferred, TRUE);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.