More build fixes for QUICHE on Windows.
This gets the following to build:
* //third_party/quic/core/io:event_loop_socket_factory_lib
* //third_party/quic/core/io:quic_default_event_loop
* //third_party/quiche/common/platform/api/...
Note that the tests for the latter path currently fail due to some issues related to ICU.
PiperOrigin-RevId: 527603143
diff --git a/quiche/quic/core/io/quic_all_event_loops_test.cc b/quiche/quic/core/io/quic_all_event_loops_test.cc
index ed62824..1467671 100644
--- a/quiche/quic/core/io/quic_all_event_loops_test.cc
+++ b/quiche/quic/core/io/quic_all_event_loops_test.cc
@@ -42,7 +42,7 @@
class MockQuicSocketEventListener : public QuicSocketEventListener {
public:
MOCK_METHOD(void, OnSocketEvent,
- (QuicEventLoop* /*event_loop*/, QuicUdpSocketFd /*fd*/,
+ (QuicEventLoop* /*event_loop*/, SocketFd /*fd*/,
QuicSocketEventMask /*events*/),
(override));
};
diff --git a/quiche/quic/core/io/quic_event_loop.h b/quiche/quic/core/io/quic_event_loop.h
index e02a0f0..6a446ea 100644
--- a/quiche/quic/core/io/quic_event_loop.h
+++ b/quiche/quic/core/io/quic_event_loop.h
@@ -9,9 +9,9 @@
#include <memory>
#include "absl/base/attributes.h"
+#include "quiche/quic/core/io/socket.h"
#include "quiche/quic/core/quic_alarm_factory.h"
#include "quiche/quic/core/quic_clock.h"
-#include "quiche/quic/core/quic_udp_socket.h"
namespace quic {
@@ -28,7 +28,7 @@
public:
virtual ~QuicSocketEventListener() = default;
- virtual void OnSocketEvent(QuicEventLoop* event_loop, QuicUdpSocketFd fd,
+ virtual void OnSocketEvent(QuicEventLoop* event_loop, SocketFd fd,
QuicSocketEventMask events) = 0;
};
@@ -53,20 +53,20 @@
// if it is, the function returns false. The |listener| must be alive for as
// long as it is registered.
virtual ABSL_MUST_USE_RESULT bool RegisterSocket(
- QuicUdpSocketFd fd, QuicSocketEventMask events,
+ SocketFd fd, QuicSocketEventMask events,
QuicSocketEventListener* listener) = 0;
// Removes the listener associated with |fd|. Returns false if the listener
// is not found.
- virtual ABSL_MUST_USE_RESULT bool UnregisterSocket(QuicUdpSocketFd fd) = 0;
+ virtual ABSL_MUST_USE_RESULT bool UnregisterSocket(SocketFd fd) = 0;
// Adds |events| to the list of the listened events for |fd|, given that |fd|
// is already registered. Must be only called if SupportsEdgeTriggered() is
// false.
- virtual ABSL_MUST_USE_RESULT bool RearmSocket(QuicUdpSocketFd fd,
+ virtual ABSL_MUST_USE_RESULT bool RearmSocket(SocketFd fd,
QuicSocketEventMask events) = 0;
// Causes the |fd| to be notified of |events| on the next event loop iteration
// even if none of the specified events has happened.
virtual ABSL_MUST_USE_RESULT bool ArtificiallyNotifyEvent(
- QuicUdpSocketFd fd, QuicSocketEventMask events) = 0;
+ SocketFd fd, QuicSocketEventMask events) = 0;
// Runs a single iteration of the event loop. The iteration will run for at
// most |default_timeout|.
diff --git a/quiche/quic/core/io/quic_poll_event_loop.cc b/quiche/quic/core/io/quic_poll_event_loop.cc
index f56635f..c156ca6 100644
--- a/quiche/quic/core/io/quic_poll_event_loop.cc
+++ b/quiche/quic/core/io/quic_poll_event_loop.cc
@@ -4,8 +4,6 @@
#include "quiche/quic/core/io/quic_poll_event_loop.h"
-#include <poll.h>
-
#include <algorithm>
#include <cerrno>
#include <memory>
@@ -38,8 +36,7 @@
QuicPollEventLoop::QuicPollEventLoop(QuicClock* clock) : clock_(clock) {}
-bool QuicPollEventLoop::RegisterSocket(QuicUdpSocketFd fd,
- QuicSocketEventMask events,
+bool QuicPollEventLoop::RegisterSocket(SocketFd fd, QuicSocketEventMask events,
QuicSocketEventListener* listener) {
auto [it, success] =
registrations_.insert({fd, std::make_shared<Registration>()});
@@ -52,12 +49,11 @@
return true;
}
-bool QuicPollEventLoop::UnregisterSocket(QuicUdpSocketFd fd) {
+bool QuicPollEventLoop::UnregisterSocket(SocketFd fd) {
return registrations_.erase(fd);
}
-bool QuicPollEventLoop::RearmSocket(QuicUdpSocketFd fd,
- QuicSocketEventMask events) {
+bool QuicPollEventLoop::RearmSocket(SocketFd fd, QuicSocketEventMask events) {
auto it = registrations_.find(fd);
if (it == registrations_.end()) {
return false;
@@ -66,7 +62,7 @@
return true;
}
-bool QuicPollEventLoop::ArtificiallyNotifyEvent(QuicUdpSocketFd fd,
+bool QuicPollEventLoop::ArtificiallyNotifyEvent(SocketFd fd,
QuicSocketEventMask events) {
auto it = registrations_.find(fd);
if (it == registrations_.end()) {
@@ -168,7 +164,7 @@
}
void QuicPollEventLoop::DispatchIoEvent(std::vector<ReadyListEntry>& ready_list,
- QuicUdpSocketFd fd, PollMask mask) {
+ SocketFd fd, PollMask mask) {
auto it = registrations_.find(fd);
if (it == registrations_.end()) {
QUIC_BUG(poll returned an unregistered fd) << fd;
@@ -260,4 +256,12 @@
return std::make_unique<AlarmFactory>(this);
}
+int QuicPollEventLoop::PollSyscall(pollfd* fds, size_t nfds, int timeout) {
+#if defined(_WIN32)
+ return WSAPoll(fds, nfds, timeout);
+#else
+ return ::poll(fds, nfds, timeout);
+#endif // defined(_WIN32)
+}
+
} // namespace quic
diff --git a/quiche/quic/core/io/quic_poll_event_loop.h b/quiche/quic/core/io/quic_poll_event_loop.h
index 6b2ec49..7c7f4bf 100644
--- a/quiche/quic/core/io/quic_poll_event_loop.h
+++ b/quiche/quic/core/io/quic_poll_event_loop.h
@@ -5,17 +5,21 @@
#ifndef QUICHE_QUIC_CORE_IO_QUIC_POLL_EVENT_LOOP_H_
#define QUICHE_QUIC_CORE_IO_QUIC_POLL_EVENT_LOOP_H_
+#if defined(_WIN32)
+#include <winsock2.h>
+#else
#include <poll.h>
+#endif
#include <memory>
#include "absl/container/btree_map.h"
#include "absl/types/span.h"
#include "quiche/quic/core/io/quic_event_loop.h"
+#include "quiche/quic/core/io/socket.h"
#include "quiche/quic/core/quic_alarm.h"
#include "quiche/quic/core/quic_alarm_factory.h"
#include "quiche/quic/core/quic_clock.h"
-#include "quiche/quic/core/quic_udp_socket.h"
#include "quiche/common/quiche_linked_hash_map.h"
namespace quic {
@@ -42,22 +46,20 @@
// QuicEventLoop implementation.
bool SupportsEdgeTriggered() const override { return false; }
ABSL_MUST_USE_RESULT bool RegisterSocket(
- QuicUdpSocketFd fd, QuicSocketEventMask events,
+ SocketFd fd, QuicSocketEventMask events,
QuicSocketEventListener* listener) override;
- ABSL_MUST_USE_RESULT bool UnregisterSocket(QuicUdpSocketFd fd) override;
- ABSL_MUST_USE_RESULT bool RearmSocket(QuicUdpSocketFd fd,
+ ABSL_MUST_USE_RESULT bool UnregisterSocket(SocketFd fd) override;
+ ABSL_MUST_USE_RESULT bool RearmSocket(SocketFd fd,
QuicSocketEventMask events) override;
ABSL_MUST_USE_RESULT bool ArtificiallyNotifyEvent(
- QuicUdpSocketFd fd, QuicSocketEventMask events) override;
+ SocketFd fd, QuicSocketEventMask events) override;
void RunEventLoopOnce(QuicTime::Delta default_timeout) override;
std::unique_ptr<QuicAlarmFactory> CreateAlarmFactory() override;
const QuicClock* GetClock() override { return clock_; }
protected:
// Allows poll(2) calls to be mocked out in unit tests.
- virtual int PollSyscall(pollfd* fds, nfds_t nfds, int timeout) {
- return ::poll(fds, nfds, timeout);
- }
+ virtual int PollSyscall(pollfd* fds, size_t nfds, int timeout);
private:
friend class QuicPollEventLoopPeer;
@@ -105,7 +107,7 @@
// Used for deferred execution of I/O callbacks.
struct ReadyListEntry {
- QuicUdpSocketFd fd;
+ SocketFd fd;
std::weak_ptr<Registration> registration;
QuicSocketEventMask events;
};
@@ -114,8 +116,7 @@
// registration order. This isn't strictly speaking necessary, but makes
// testing things easier.
using RegistrationMap =
- quiche::QuicheLinkedHashMap<QuicUdpSocketFd,
- std::shared_ptr<Registration>>;
+ quiche::QuicheLinkedHashMap<SocketFd, std::shared_ptr<Registration>>;
// Alarms are stored as weak pointers, since the alarm can be cancelled and
// disappear while in the queue.
using AlarmList = absl::btree_multimap<QuicTime, std::weak_ptr<Alarm*>>;
@@ -131,8 +132,8 @@
void ProcessAlarmsUpTo(QuicTime time);
// Adds the I/O callbacks for |fd| to the |ready_lits| as appopriate.
- void DispatchIoEvent(std::vector<ReadyListEntry>& ready_list,
- QuicUdpSocketFd fd, short mask); // NOLINT(runtime/int)
+ void DispatchIoEvent(std::vector<ReadyListEntry>& ready_list, SocketFd fd,
+ short mask); // NOLINT(runtime/int)
// Runs all of the callbacks on the ready list.
void RunReadyCallbacks(std::vector<ReadyListEntry>& ready_list);
diff --git a/quiche/quic/core/io/quic_poll_event_loop_test.cc b/quiche/quic/core/io/quic_poll_event_loop_test.cc
index f0e9557..d53d883 100644
--- a/quiche/quic/core/io/quic_poll_event_loop_test.cc
+++ b/quiche/quic/core/io/quic_poll_event_loop_test.cc
@@ -46,7 +46,7 @@
class MockQuicSocketEventListener : public QuicSocketEventListener {
public:
MOCK_METHOD(void, OnSocketEvent,
- (QuicEventLoop* /*event_loop*/, QuicUdpSocketFd /*fd*/,
+ (QuicEventLoop* /*event_loop*/, SocketFd /*fd*/,
QuicSocketEventMask /*events*/),
(override));
};
diff --git a/quiche/quic/qbone/bonnet/icmp_reachable.cc b/quiche/quic/qbone/bonnet/icmp_reachable.cc
index 8f85190..4ac7109 100644
--- a/quiche/quic/qbone/bonnet/icmp_reachable.cc
+++ b/quiche/quic/qbone/bonnet/icmp_reachable.cc
@@ -196,7 +196,7 @@
}
void IcmpReachable::EpollCallback::OnSocketEvent(QuicEventLoop* event_loop,
- QuicUdpSocketFd fd,
+ SocketFd fd,
QuicSocketEventMask events) {
bool can_read_more = reachable_->OnEvent(fd);
if (can_read_more) {
diff --git a/quiche/quic/qbone/bonnet/icmp_reachable.h b/quiche/quic/qbone/bonnet/icmp_reachable.h
index 529ccc7..f00c99a 100644
--- a/quiche/quic/qbone/bonnet/icmp_reachable.h
+++ b/quiche/quic/qbone/bonnet/icmp_reachable.h
@@ -96,7 +96,7 @@
EpollCallback(EpollCallback&&) = delete;
EpollCallback& operator=(EpollCallback&&) = delete;
- void OnSocketEvent(QuicEventLoop* event_loop, QuicUdpSocketFd fd,
+ void OnSocketEvent(QuicEventLoop* event_loop, SocketFd fd,
QuicSocketEventMask events) override;
private: