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

Unified Diff: net/tools/quic/quic_simple_client.h

Issue 995423003: Add a chromium based simple QUIC client. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix iOS Created 5 years, 9 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
« no previous file with comments | « net/tools/quic/quic_client.cc ('k') | net/tools/quic/quic_simple_client.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/tools/quic/quic_simple_client.h
diff --git a/net/tools/quic/quic_simple_client.h b/net/tools/quic/quic_simple_client.h
index 38becd8fce404724661231367c45ceb9c28bab7b..0bab4e452c1940accd8b7c23e5bdaed7ec5bc886 100644
--- a/net/tools/quic/quic_simple_client.h
+++ b/net/tools/quic/quic_simple_client.h
@@ -5,8 +5,8 @@
// A toy client, which connects to a specified port and sends QUIC
// request to that endpoint.
-#ifndef NET_TOOLS_QUIC_QUIC_CLIENT_H_
-#define NET_TOOLS_QUIC_QUIC_CLIENT_H_
+#ifndef NET_TOOLS_QUIC_QUIC_SIMPLE_CLIENT_H_
+#define NET_TOOLS_QUIC_QUIC_SIMPLE_CLIENT_H_
#include <string>
@@ -14,54 +14,53 @@
#include "base/command_line.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/string_piece.h"
+#include "net/base/io_buffer.h"
#include "net/base/ip_endpoint.h"
+#include "net/base/net_log.h"
+#include "net/http/http_response_headers.h"
#include "net/quic/crypto/crypto_handshake.h"
#include "net/quic/quic_config.h"
#include "net/quic/quic_framer.h"
#include "net/quic/quic_packet_creator.h"
-#include "net/tools/balsa/balsa_headers.h"
-#include "net/tools/epoll_server/epoll_server.h"
-#include "net/tools/quic/quic_client_session.h"
-#include "net/tools/quic/quic_spdy_client_stream.h"
+#include "net/tools/quic/quic_simple_client_session.h"
+#include "net/tools/quic/quic_simple_client_stream.h"
namespace net {
+struct HttpRequestInfo;
class ProofVerifier;
class QuicServerId;
+class QuicConnectionHelper;
+class UDPClientSocket;
namespace tools {
-class QuicEpollConnectionHelper;
-
namespace test {
class QuicClientPeer;
} // namespace test
-class QuicClient : public EpollCallbackInterface,
- public QuicDataStream::Visitor {
+class QuicSimpleClient : public QuicDataStream::Visitor {
public:
class ResponseListener {
public:
ResponseListener() {}
virtual ~ResponseListener() {}
virtual void OnCompleteResponse(QuicStreamId id,
- const BalsaHeaders& response_headers,
+ const HttpResponseHeaders& response_headers,
const std::string& response_body) = 0;
};
// Create a quic client, which will have events managed by an externally owned
// EpollServer.
- QuicClient(IPEndPoint server_address,
- const QuicServerId& server_id,
- const QuicVersionVector& supported_versions,
- EpollServer* epoll_server);
- QuicClient(IPEndPoint server_address,
- const QuicServerId& server_id,
- const QuicVersionVector& supported_versions,
- const QuicConfig& config,
- EpollServer* epoll_server);
-
- ~QuicClient() override;
+ QuicSimpleClient(IPEndPoint server_address,
+ const QuicServerId& server_id,
+ const QuicVersionVector& supported_versions);
+ QuicSimpleClient(IPEndPoint server_address,
+ const QuicServerId& server_id,
+ const QuicVersionVector& supported_versions,
+ const QuicConfig& config);
+
+ ~QuicSimpleClient() override;
// Initializes the client to create a connection. Should be called exactly
// once before calling StartConnect or Connect. Returns true if the
@@ -86,23 +85,23 @@ class QuicClient : public EpollCallbackInterface,
void Disconnect();
// Sends an HTTP request and does not wait for response before returning.
- void SendRequest(const BalsaHeaders& headers,
+ void SendRequest(const HttpRequestInfo& headers,
base::StringPiece body,
bool fin);
// Sends an HTTP request and waits for response before returning.
- void SendRequestAndWaitForResponse(const BalsaHeaders& headers,
+ void SendRequestAndWaitForResponse(const HttpRequestInfo& headers,
base::StringPiece body,
bool fin);
// Sends a request simple GET for each URL in |args|, and then waits for
// each to complete.
- void SendRequestsAndWaitForResponse(const
- base::CommandLine::StringVector& args);
+ void SendRequestsAndWaitForResponse(
+ const base::CommandLine::StringVector& url_list);
- // Returns a newly created QuicSpdyClientStream, owned by the
- // QuicClient.
- QuicSpdyClientStream* CreateReliableClientStream();
+ // Returns a newly created QuicSimpleClientStream, owned by the
+ // QuicSimpleClient.
+ QuicSimpleClientStream* CreateReliableClientStream();
// Wait for events until the stream with the given ID is closed.
void WaitForStreamToClose(QuicStreamId id);
@@ -114,20 +113,17 @@ class QuicClient : public EpollCallbackInterface,
// Returns true if there are any outstanding requests.
bool WaitForEvents();
- // From EpollCallbackInterface
- void OnRegistration(EpollServer* eps, int fd, int event_mask) override {}
- void OnModification(int fd, int event_mask) override {}
- void OnEvent(int fd, EpollEvent* event) override;
- // |fd_| can be unregistered without the client being disconnected. This
- // happens in b3m QuicProber where we unregister |fd_| to feed in events to
- // the client from the SelectServer.
- void OnUnregistration(int fd, bool replaced) override {}
- void OnShutdown(EpollServer* eps, int fd) override {}
+ // Start the read loop on the socket.
+ void StartReading();
+
+ // Called on reads that complete asynchronously. Dispatches the packet and
+ // calls StartReading() again.
+ void OnReadComplete(int result);
// QuicDataStream::Visitor
void OnClose(QuicDataStream* stream) override;
- QuicClientSession* session() { return session_.get(); }
+ QuicSimpleClientSession* session() { return session_.get(); }
bool connected() const;
bool goaway_received() const;
@@ -144,8 +140,6 @@ class QuicClient : public EpollCallbackInterface,
const IPEndPoint& client_address() const { return client_address_; }
- int fd() { return fd_; }
-
const QuicServerId& server_id() const { return server_id_; }
// This should only be set before the initial Connect()
@@ -191,16 +185,9 @@ class QuicClient : public EpollCallbackInterface,
protected:
virtual QuicConnectionId GenerateConnectionId();
- virtual QuicEpollConnectionHelper* CreateQuicConnectionHelper();
+ virtual QuicConnectionHelper* CreateQuicConnectionHelper();
virtual QuicPacketWriter* CreateQuicPacketWriter();
- virtual int ReadPacket(char* buffer,
- int buffer_len,
- IPEndPoint* server_address,
- IPAddressNumber* client_ip);
-
- EpollServer* epoll_server() { return epoll_server_; }
-
private:
friend class net::tools::test::QuicClientPeer;
@@ -220,12 +207,12 @@ class QuicClient : public EpollCallbackInterface,
// and binds the socket to our address.
bool CreateUDPSocket();
- // If the socket has been created, then unregister and close() the FD.
- void CleanUpUDPSocket();
-
// Read a UDP packet and hand it to the framer.
bool ReadAndProcessPacket();
+ // Used by |helper_| to time alarms.
+ QuicClock clock_;
+
// Address of the server.
const IPEndPoint server_address_;
@@ -250,14 +237,16 @@ class QuicClient : public EpollCallbackInterface,
scoped_ptr<QuicPacketWriter> writer_;
// Session which manages streams.
- scoped_ptr<QuicClientSession> session_;
- // Listens for events on the client socket.
- EpollServer* epoll_server_;
- // UDP socket.
- int fd_;
+ scoped_ptr<QuicSimpleClientSession> session_;
+
+ // UDP socket connected to the server.
+ scoped_ptr<UDPClientSocket> socket_;
+
+ // Connection on the socket. Owned by |session_|.
+ QuicConnection* connection_;
// Helper to be used by created connections.
- scoped_ptr<QuicEpollConnectionHelper> helper_;
+ scoped_ptr<QuicConnectionHelper> helper_;
// Listens for full responses.
scoped_ptr<ResponseListener> response_listener_;
@@ -289,10 +278,24 @@ class QuicClient : public EpollCallbackInterface,
// Body of most recent response.
std::string latest_response_body_;
- DISALLOW_COPY_AND_ASSIGN(QuicClient);
+ 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 log used for the sockets.
+ NetLog net_log_;
+
+ base::WeakPtrFactory<QuicSimpleClient> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(QuicSimpleClient);
};
} // namespace tools
} // namespace net
-#endif // NET_TOOLS_QUIC_QUIC_CLIENT_H_
+#endif // NET_TOOLS_QUIC_QUIC_SIMPLE_CLIENT_H_
« no previous file with comments | « net/tools/quic/quic_client.cc ('k') | net/tools/quic/quic_simple_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698