Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(394)

Unified Diff: net/quic/quic_server.h

Issue 340433002: Port QuicServer to Chrome network stack (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix GN build Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/quic/quic_server.h
diff --git a/net/tools/quic/quic_server.h b/net/quic/quic_server.h
similarity index 39%
copy from net/tools/quic/quic_server.h
copy to net/quic/quic_server.h
index 6285fd769d953417076055dcdf0d1e35247cf71b..e07f24c29d02e5f8b946501d4fa137639964e0f5 100644
--- a/net/tools/quic/quic_server.h
+++ b/net/quic/quic_server.h
@@ -5,64 +5,50 @@
// A toy server, which listens on a specified address for QUIC traffic and
// handles incoming responses.
-#ifndef NET_TOOLS_QUIC_QUIC_SERVER_H_
-#define NET_TOOLS_QUIC_QUIC_SERVER_H_
+#ifndef NET_QUIC_QUIC_SERVER_H_
+#define NET_QUIC_QUIC_SERVER_H_
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
+#include "net/base/io_buffer.h"
#include "net/base/ip_endpoint.h"
+#include "net/base/net_log.h"
#include "net/quic/crypto/quic_crypto_server_config.h"
+#include "net/quic/quic_clock.h"
#include "net/quic/quic_config.h"
-#include "net/quic/quic_framer.h"
-#include "net/tools/epoll_server/epoll_server.h"
-#include "net/tools/quic/quic_dispatcher.h"
+#include "net/quic/quic_connection_helper.h"
namespace net {
-namespace tools {
namespace test {
class QuicServerPeer;
} // namespace test
+class QuicConnectionHelperInterface;
class QuicDispatcher;
+class UDPServerSocket;
-class QuicServer : public EpollCallbackInterface {
+class QuicServer {
public:
- QuicServer();
QuicServer(const QuicConfig& config,
const QuicVersionVector& supported_versions);
virtual ~QuicServer();
- // Start listening on the specified address.
- bool Listen(const IPEndPoint& address);
+ // Start listening on the specified address. Returns an error code.
+ int Listen(const IPEndPoint& address);
- // Wait up to 50ms, and handle any events which occur.
- void WaitForEvents();
-
- // Server deletion is imminent. Start cleaning up the epoll server.
+ // Server deletion is imminent. Start cleaning up.
void Shutdown();
- // From EpollCallbackInterface
- virtual void OnRegistration(EpollServer* eps,
- int fd,
- int event_mask) OVERRIDE {}
- virtual void OnModification(int fd, int event_mask) OVERRIDE {}
- virtual void OnEvent(int fd, EpollEvent* event) OVERRIDE;
- virtual void OnUnregistration(int fd, bool replaced) OVERRIDE {}
-
- // Reads a packet from the given fd, and then passes it off to
- // the QuicDispatcher. Returns true if a packet is read, false
- // otherwise.
- // If packets_dropped is non-null, the socket is configured to track
- // dropped packets, and some packets are read, it will be set to the number of
- // dropped packets.
- static bool ReadAndDispatchSinglePacket(int fd, int port,
- QuicDispatcher* dispatcher,
- uint32* packets_dropped);
-
- virtual void OnShutdown(EpollServer* eps, int fd) OVERRIDE {}
+ // Start reading on the socket. On asynchronous reads, this registers
+ // OnReadComplete as the callback, which will then call StartReading again.
+ void StartReading();
+
+ // Called on reads that complete asynchronously. Dispatches the packet and
+ // continues the read loop.
+ void OnReadComplete(int result);
void SetStrikeRegisterNoStartupPeriod() {
crypto_config_.set_strike_register_no_startup_period();
@@ -74,52 +60,23 @@ class QuicServer : public EpollCallbackInterface {
crypto_config_.SetProofSource(source);
}
- bool overflow_supported() { return overflow_supported_; }
-
- uint32 packets_dropped() { return packets_dropped_; }
-
- int port() { return port_; }
-
- protected:
- virtual QuicDispatcher* CreateQuicDispatcher();
-
- const QuicConfig& config() const { return config_; }
- const QuicCryptoServerConfig& crypto_config() const {
- return crypto_config_;
- }
- const QuicVersionVector& supported_versions() const {
- return supported_versions_;
- }
- EpollServer* epoll_server() { return &epoll_server_; }
-
private:
- friend class net::tools::test::QuicServerPeer;
+ friend class net::test::QuicServerPeer;
// Initialize the internal state of the server.
void Initialize();
// Accepts data from the framer and demuxes clients to sessions.
scoped_ptr<QuicDispatcher> dispatcher_;
- // Frames incoming packets and hands them to the dispatcher.
- EpollServer epoll_server_;
- // The port the server is listening on.
- int port_;
+ // Used by the helper_ to time alarms.
+ QuicClock clock_;
- // Listening connection. Also used for outbound client communication.
- int fd_;
+ // Used to manage the message loop.
+ QuicConnectionHelper helper_;
- // If overflow_supported_ is true this will be the number of packets dropped
- // during the lifetime of the server. This may overflow if enough packets
- // are dropped.
- uint32 packets_dropped_;
-
- // True if the kernel supports SO_RXQ_OVFL, the number of packets dropped
- // because the socket would otherwise overflow.
- bool overflow_supported_;
-
- // If true, use recvmmsg for reading.
- bool use_recvmmsg_;
+ // Listening socket. Also used for outbound client communication.
+ scoped_ptr<UDPServerSocket> socket_;
// config_ contains non-crypto parameters that are negotiated in the crypto
// handshake.
@@ -133,14 +90,31 @@ class QuicServer : public EpollCallbackInterface {
// skipped as necessary).
QuicVersionVector supported_versions_;
- // Size of flow control receive window to advertise to clients on new
- // connections.
- uint32 server_initial_flow_control_receive_window_;
+ // The address that the server listens on.
+ IPEndPoint server_address_;
+
+ // Keeps track of whether a read is currently in flight, after which
+ // OnReadComplete will be called.
+ bool read_pending_;
+
+ // The number of iterations of the read loop that have completed synchronously
+ // and without posting a new task to the message loop.
+ int synchronous_read_count_;
+
+ // The target buffer of the current read.
+ scoped_refptr<IOBufferWithSize> read_buffer_;
+
+ // The source address of the current read.
+ IPEndPoint client_address_;
+
+ // The log to use for the socket.
+ NetLog net_log_;
+
+ base::WeakPtrFactory<QuicServer> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(QuicServer);
};
-} // namespace tools
} // namespace net
-#endif // NET_TOOLS_QUIC_QUIC_SERVER_H_
+#endif // NET_QUIC_QUIC_SERVER_H_

Powered by Google App Engine
This is Rietveld 408576698