diff options
Diffstat (limited to 'net/tools/quic')
-rw-r--r-- | net/tools/quic/end_to_end_test.cc | 13 | ||||
-rw-r--r-- | net/tools/quic/quic_dispatcher.cc | 21 | ||||
-rw-r--r-- | net/tools/quic/quic_dispatcher.h | 10 | ||||
-rw-r--r-- | net/tools/quic/quic_epoll_connection_helper.cc | 14 | ||||
-rw-r--r-- | net/tools/quic/quic_epoll_connection_helper.h | 4 | ||||
-rw-r--r-- | net/tools/quic/quic_epoll_connection_helper_test.cc | 7 | ||||
-rw-r--r-- | net/tools/quic/quic_packet_writer.h | 12 | ||||
-rw-r--r-- | net/tools/quic/quic_socket_utils.cc | 25 | ||||
-rw-r--r-- | net/tools/quic/quic_socket_utils.h | 14 | ||||
-rw-r--r-- | net/tools/quic/quic_time_wait_list_manager.cc | 29 | ||||
-rw-r--r-- | net/tools/quic/quic_time_wait_list_manager_test.cc | 42 | ||||
-rw-r--r-- | net/tools/quic/test_tools/quic_test_utils.h | 12 |
12 files changed, 104 insertions, 99 deletions
diff --git a/net/tools/quic/end_to_end_test.cc b/net/tools/quic/end_to_end_test.cc index 43684c4..7305127 100644 --- a/net/tools/quic/end_to_end_test.cc +++ b/net/tools/quic/end_to_end_test.cc @@ -534,13 +534,14 @@ class WrongAddressWriter : public QuicPacketWriter { self_address_ = IPEndPoint(ip, 0); } - virtual WriteResult WritePacket( - const char* buffer, size_t buf_len, - const IPAddressNumber& real_self_address, - const IPEndPoint& peer_address, - QuicBlockedWriterInterface* blocked_writer) OVERRIDE { + virtual int WritePacket(const char* buffer, size_t buf_len, + const IPAddressNumber& real_self_address, + const IPEndPoint& peer_address, + QuicBlockedWriterInterface* blocked_writer, + int* error) OVERRIDE { return QuicSocketUtils::WritePacket(fd_, buffer, buf_len, - self_address_.address(), peer_address); + self_address_.address(), peer_address, + error); } IPEndPoint self_address_; diff --git a/net/tools/quic/quic_dispatcher.cc b/net/tools/quic/quic_dispatcher.cc index b22b9dc..8550ef0 100644 --- a/net/tools/quic/quic_dispatcher.cc +++ b/net/tools/quic/quic_dispatcher.cc @@ -53,22 +53,25 @@ QuicDispatcher::~QuicDispatcher() { STLDeleteElements(&closed_session_list_); } -WriteResult QuicDispatcher::WritePacket(const char* buffer, size_t buf_len, - const IPAddressNumber& self_address, - const IPEndPoint& peer_address, - QuicBlockedWriterInterface* writer) { +int QuicDispatcher::WritePacket(const char* buffer, size_t buf_len, + const IPAddressNumber& self_address, + const IPEndPoint& peer_address, + QuicBlockedWriterInterface* writer, + int* error) { if (write_blocked_) { write_blocked_list_.insert(make_pair(writer, true)); - return WriteResult(WRITE_STATUS_BLOCKED, EAGAIN); + *error = EAGAIN; + return -1; } - WriteResult result = QuicSocketUtils::WritePacket(fd_, buffer, buf_len, - self_address, peer_address); - if (result.status == WRITE_STATUS_BLOCKED) { + int rc = QuicSocketUtils::WritePacket(fd_, buffer, buf_len, + self_address, peer_address, + error); + if (rc == -1 && (*error == EWOULDBLOCK || *error == EAGAIN)) { write_blocked_list_.insert(make_pair(writer, true)); write_blocked_ = true; } - return result; + return rc; } void QuicDispatcher::ProcessPacket(const IPEndPoint& server_address, diff --git a/net/tools/quic/quic_dispatcher.h b/net/tools/quic/quic_dispatcher.h index 584965c..465601c 100644 --- a/net/tools/quic/quic_dispatcher.h +++ b/net/tools/quic/quic_dispatcher.h @@ -60,11 +60,11 @@ class QuicDispatcher : public QuicPacketWriter, public QuicSessionOwner { virtual ~QuicDispatcher(); // QuicPacketWriter - virtual WriteResult WritePacket( - const char* buffer, size_t buf_len, - const IPAddressNumber& self_address, - const IPEndPoint& peer_address, - QuicBlockedWriterInterface* writer) OVERRIDE; + virtual int WritePacket(const char* buffer, size_t buf_len, + const IPAddressNumber& self_address, + const IPEndPoint& peer_address, + QuicBlockedWriterInterface* writer, + int* error) OVERRIDE; virtual void ProcessPacket(const IPEndPoint& server_address, const IPEndPoint& client_address, diff --git a/net/tools/quic/quic_epoll_connection_helper.cc b/net/tools/quic/quic_epoll_connection_helper.cc index fc68b8f..9c33847 100644 --- a/net/tools/quic/quic_epoll_connection_helper.cc +++ b/net/tools/quic/quic_epoll_connection_helper.cc @@ -98,11 +98,13 @@ QuicRandom* QuicEpollConnectionHelper::GetRandomGenerator() { return random_generator_; } -WriteResult QuicEpollConnectionHelper::WritePacketToWire( - const QuicEncryptedPacket& packet) { +int QuicEpollConnectionHelper::WritePacketToWire( + const QuicEncryptedPacket& packet, + int* error) { if (connection_->ShouldSimulateLostPacket()) { DLOG(INFO) << "Dropping packet due to fake packet loss."; - return WriteResult(WRITE_STATUS_OK, packet.length()); + *error = 0; + return packet.length(); } // If we have a writer, delgate the write to it. @@ -110,12 +112,14 @@ WriteResult QuicEpollConnectionHelper::WritePacketToWire( return writer_->WritePacket(packet.data(), packet.length(), connection_->self_address().address(), connection_->peer_address(), - connection_); + connection_, + error); } else { return QuicSocketUtils::WritePacket( fd_, packet.data(), packet.length(), connection_->self_address().address(), - connection_->peer_address()); + connection_->peer_address(), + error); } } diff --git a/net/tools/quic/quic_epoll_connection_helper.h b/net/tools/quic/quic_epoll_connection_helper.h index a7e6f01..5bd526f 100644 --- a/net/tools/quic/quic_epoll_connection_helper.h +++ b/net/tools/quic/quic_epoll_connection_helper.h @@ -43,8 +43,8 @@ class QuicEpollConnectionHelper : public QuicConnectionHelperInterface { virtual void SetConnection(QuicConnection* connection) OVERRIDE; virtual const QuicClock* GetClock() const OVERRIDE; virtual QuicRandom* GetRandomGenerator() OVERRIDE; - virtual WriteResult WritePacketToWire( - const QuicEncryptedPacket& packet) OVERRIDE; + virtual int WritePacketToWire(const QuicEncryptedPacket& packet, + int* error) OVERRIDE; virtual bool IsWriteBlockedDataBuffered() OVERRIDE; virtual bool IsWriteBlocked(int error) OVERRIDE; virtual QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) OVERRIDE; diff --git a/net/tools/quic/quic_epoll_connection_helper_test.cc b/net/tools/quic/quic_epoll_connection_helper_test.cc index 0e5cd48..154c393 100644 --- a/net/tools/quic/quic_epoll_connection_helper_test.cc +++ b/net/tools/quic/quic_epoll_connection_helper_test.cc @@ -39,14 +39,15 @@ class TestConnectionHelper : public QuicEpollConnectionHelper { : QuicEpollConnectionHelper(fd, eps) { } - virtual WriteResult WritePacketToWire( - const QuicEncryptedPacket& packet) OVERRIDE { + virtual int WritePacketToWire(const QuicEncryptedPacket& packet, + int* error) OVERRIDE { QuicFramer framer(QuicVersionMax(), QuicTime::Zero(), true); FramerVisitorCapturingFrames visitor; framer.set_visitor(&visitor); EXPECT_TRUE(framer.ProcessPacket(packet)); header_ = *visitor.header(); - return WriteResult(WRITE_STATUS_OK, packet.length()); + *error = 0; + return packet.length(); } QuicPacketHeader* header() { return &header_; } diff --git a/net/tools/quic/quic_packet_writer.h b/net/tools/quic/quic_packet_writer.h index 2d70e09..b10e852 100644 --- a/net/tools/quic/quic_packet_writer.h +++ b/net/tools/quic/quic_packet_writer.h @@ -6,12 +6,10 @@ #define NET_TOOLS_QUIC_QUIC_PACKET_WRITER_H_ #include "net/base/ip_endpoint.h" -#include "net/quic/quic_protocol.h" namespace net { class QuicBlockedWriterInterface; -struct WriteResult; namespace tools { @@ -22,11 +20,11 @@ class QuicPacketWriter { public: virtual ~QuicPacketWriter() {} - virtual WriteResult WritePacket( - const char* buffer, size_t buf_len, - const net::IPAddressNumber& self_address, - const net::IPEndPoint& peer_address, - QuicBlockedWriterInterface* blocked_writer) = 0; + virtual int WritePacket(const char* buffer, size_t buf_len, + const net::IPAddressNumber& self_address, + const net::IPEndPoint& peer_address, + QuicBlockedWriterInterface* blocked_writer, + int* error) = 0; }; } // namespace tools diff --git a/net/tools/quic/quic_socket_utils.cc b/net/tools/quic/quic_socket_utils.cc index 87071a6..6535d57 100644 --- a/net/tools/quic/quic_socket_utils.cc +++ b/net/tools/quic/quic_socket_utils.cc @@ -12,7 +12,6 @@ #include <string> #include "base/logging.h" -#include "net/quic/quic_protocol.h" #ifndef SO_RXQ_OVFL #define SO_RXQ_OVFL 40 @@ -51,7 +50,7 @@ IPAddressNumber QuicSocketUtils::GetAddressFromMsghdr(struct msghdr *hdr) { // static bool QuicSocketUtils::GetOverflowFromMsghdr(struct msghdr *hdr, - int *dropped_packets) { + int *dropped_packets) { if (hdr->msg_controllen > 0) { struct cmsghdr *cmsg; for (cmsg = CMSG_FIRSTHDR(hdr); @@ -80,9 +79,9 @@ int QuicSocketUtils::SetGetAddressInfo(int fd, int address_family) { // static int QuicSocketUtils::ReadPacket(int fd, char* buffer, size_t buf_len, - int* dropped_packets, - IPAddressNumber* self_address, - IPEndPoint* peer_address) { + int* dropped_packets, + IPAddressNumber* self_address, + IPEndPoint* peer_address) { CHECK(peer_address != NULL); const int kSpaceForOverflowAndIp = CMSG_SPACE(sizeof(int)) + CMSG_SPACE(sizeof(in6_pktinfo)); @@ -136,11 +135,10 @@ int QuicSocketUtils::ReadPacket(int fd, char* buffer, size_t buf_len, } // static -WriteResult QuicSocketUtils::WritePacket(int fd, - const char* buffer, - size_t buf_len, - const IPAddressNumber& self_address, - const IPEndPoint& peer_address) { +int QuicSocketUtils::WritePacket(int fd, const char* buffer, size_t buf_len, + const IPAddressNumber& self_address, + const IPEndPoint& peer_address, + int* error) { sockaddr_storage raw_address; socklen_t address_len = sizeof(raw_address); CHECK(peer_address.ToSockAddr( @@ -192,11 +190,8 @@ WriteResult QuicSocketUtils::WritePacket(int fd, } int rc = sendmsg(fd, &hdr, 0); - if (rc >= 0) { - return WriteResult(WRITE_STATUS_OK, rc); - } - return WriteResult((errno == EAGAIN || errno == EWOULDBLOCK) ? - WRITE_STATUS_BLOCKED : WRITE_STATUS_ERROR, errno); + *error = (rc >= 0) ? 0 : errno; + return rc; } } // namespace tools diff --git a/net/tools/quic/quic_socket_utils.h b/net/tools/quic/quic_socket_utils.h index 8f0feff..bfacc6c 100644 --- a/net/tools/quic/quic_socket_utils.h +++ b/net/tools/quic/quic_socket_utils.h @@ -12,7 +12,6 @@ #include <string> #include "net/base/ip_endpoint.h" -#include "net/quic/quic_protocol.h" namespace net { namespace tools { @@ -46,13 +45,12 @@ class QuicSocketUtils { IPAddressNumber* self_address, IPEndPoint* peer_address); - // Writes buf_len to the socket. If writing is successful, sets the result's - // status to WRITE_STATUS_OK and sets bytes_written. Otherwise sets the - // result's status to WRITE_STATUS_BLOCKED or WRITE_STATUS_ERROR and sets - // error_code to errno. - static WriteResult WritePacket(int fd, const char* buffer, size_t buf_len, - const IPAddressNumber& self_address, - const IPEndPoint& peer_address); + // Writes buf_len to the socket. If writing is successful returns the number + // of bytes written otherwise returns -1 and sets error to errno. + static int WritePacket(int fd, const char* buffer, size_t buf_len, + const IPAddressNumber& self_address, + const IPEndPoint& peer_address, + int* error); }; } // namespace tools diff --git a/net/tools/quic/quic_time_wait_list_manager.cc b/net/tools/quic/quic_time_wait_list_manager.cc index 345ddb2..a2fc4f8 100644 --- a/net/tools/quic/quic_time_wait_list_manager.cc +++ b/net/tools/quic/quic_time_wait_list_manager.cc @@ -263,19 +263,22 @@ void QuicTimeWaitListManager::SendOrQueuePacket(QueuedPacket* packet) { void QuicTimeWaitListManager::WriteToWire(QueuedPacket* queued_packet) { DCHECK(!is_write_blocked_); - WriteResult result = writer_->WritePacket( - queued_packet->packet()->data(), - queued_packet->packet()->length(), - queued_packet->server_address().address(), - queued_packet->client_address(), - this); - - if (result.status == WRITE_STATUS_BLOCKED) { - is_write_blocked_ = true; - } else if (result.status == WRITE_STATUS_ERROR) { - LOG(WARNING) << "Received unknown error while sending reset packet to " - << queued_packet->client_address().ToString() << ": " - << strerror(result.error_code); + int error; + int rc = writer_->WritePacket(queued_packet->packet()->data(), + queued_packet->packet()->length(), + queued_packet->server_address().address(), + queued_packet->client_address(), + this, + &error); + + if (rc == -1) { + if (error == EAGAIN || error == EWOULDBLOCK) { + is_write_blocked_ = true; + } else { + LOG(WARNING) << "Received unknown error while sending reset packet to " + << queued_packet->client_address().ToString() << ": " + << strerror(error); + } } } diff --git a/net/tools/quic/quic_time_wait_list_manager_test.cc b/net/tools/quic/quic_time_wait_list_manager_test.cc index 64abb61..8f59687 100644 --- a/net/tools/quic/quic_time_wait_list_manager_test.cc +++ b/net/tools/quic/quic_time_wait_list_manager_test.cc @@ -195,10 +195,11 @@ TEST_F(QuicTimeWaitListManagerTest, SendPublicReset) { EXPECT_CALL(writer_, WritePacket(_, _, server_address_.address(), client_address_, - &time_wait_list_manager_)) + &time_wait_list_manager_, + _)) .With(Args<0, 1>(PublicResetPacketEq(guid_, kRandomSequenceNumber))) - .WillOnce(Return(WriteResult(WRITE_STATUS_OK, packet->length()))); + .WillOnce(Return(packet->length())); ProcessPacket(guid_, *packet); } @@ -209,7 +210,7 @@ TEST_F(QuicTimeWaitListManagerTest, DropInvalidPacket) { QuicEncryptedPacket packet(buffer, arraysize(buffer)); ProcessPacket(guid_, packet); // Will get called for a valid packet since received packet count = 1 (2 ^ 0). - EXPECT_CALL(writer_, WritePacket(_, _, _, _, _)).Times(0); + EXPECT_CALL(writer_, WritePacket(_, _, _, _, _, _)).Times(0); } TEST_F(QuicTimeWaitListManagerTest, DropPublicResetPacket) { @@ -224,7 +225,7 @@ TEST_F(QuicTimeWaitListManagerTest, DropPublicResetPacket) { QuicFramer::BuildPublicResetPacket(packet)); ProcessPacket(guid_, *public_reset_packet); // Will get called for a data packet since received packet count = 1 (2 ^ 0). - EXPECT_CALL(writer_, WritePacket(_, _, _, _, _)) + EXPECT_CALL(writer_, WritePacket(_, _, _, _, _, _)) .Times(0); } @@ -234,8 +235,8 @@ TEST_F(QuicTimeWaitListManagerTest, SendPublicResetWithExponentialBackOff) { scoped_ptr<QuicEncryptedPacket> packet( ConstructEncryptedPacket(guid_, sequence_number)); if ((sequence_number & (sequence_number - 1)) == 0) { - EXPECT_CALL(writer_, WritePacket(_, _, _, _, _)) - .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); + EXPECT_CALL(writer_, WritePacket(_, _, _, _, _, _)) + .WillOnce(Return(1)); } ProcessPacket(guid_, *packet); // Send public reset with exponential back off. @@ -293,10 +294,11 @@ TEST_F(QuicTimeWaitListManagerTest, SendQueuedPackets) { EXPECT_CALL(writer_, WritePacket(_, _, server_address_.address(), client_address_, - &time_wait_list_manager_)) + &time_wait_list_manager_, + _)) .With(Args<0, 1>(PublicResetPacketEq(guid, sequence_number))) - .WillOnce(Return(WriteResult(WRITE_STATUS_OK, packet->length()))); + .WillOnce(Return(packet->length())); ProcessPacket(guid, *packet); EXPECT_FALSE(time_wait_list_manager_.is_write_blocked()); @@ -304,10 +306,11 @@ TEST_F(QuicTimeWaitListManagerTest, SendQueuedPackets) { EXPECT_CALL(writer_, WritePacket(_, _, server_address_.address(), client_address_, - &time_wait_list_manager_)) + &time_wait_list_manager_, + _)) .With(Args<0, 1>(PublicResetPacketEq(guid, sequence_number))) - .WillOnce(Return(WriteResult(WRITE_STATUS_BLOCKED, EAGAIN))); + .WillOnce(DoAll(SetArgPointee<5>(EAGAIN), Return(-1))); ProcessPacket(guid, *packet); // 3rd packet. No public reset should be sent; ProcessPacket(guid, *packet); @@ -320,7 +323,7 @@ TEST_F(QuicTimeWaitListManagerTest, SendQueuedPackets) { QuicPacketSequenceNumber other_sequence_number = 23423; scoped_ptr<QuicEncryptedPacket> other_packet( ConstructEncryptedPacket(other_guid, other_sequence_number)); - EXPECT_CALL(writer_, WritePacket(_, _, _, _, _)) + EXPECT_CALL(writer_, WritePacket(_, _, _, _, _, _)) .Times(0); ProcessPacket(other_guid, *other_packet); @@ -328,18 +331,19 @@ TEST_F(QuicTimeWaitListManagerTest, SendQueuedPackets) { EXPECT_CALL(writer_, WritePacket(_, _, server_address_.address(), client_address_, - &time_wait_list_manager_)) + &time_wait_list_manager_, + _)) .With(Args<0, 1>(PublicResetPacketEq(guid, sequence_number))) - .WillOnce(Return(WriteResult(WRITE_STATUS_OK, packet->length()))); + .WillOnce(Return(packet->length())); EXPECT_CALL(writer_, WritePacket(_, _, server_address_.address(), client_address_, - &time_wait_list_manager_)) + &time_wait_list_manager_, + _)) .With(Args<0, 1>(PublicResetPacketEq(other_guid, other_sequence_number))) - .WillOnce(Return(WriteResult(WRITE_STATUS_OK, - other_packet->length()))); + .WillOnce(Return(other_packet->length())); time_wait_list_manager_.OnCanWrite(); EXPECT_FALSE(time_wait_list_manager_.is_write_blocked()); } @@ -353,8 +357,7 @@ TEST_F(QuicTimeWaitListManagerTest, MakeSureFramerUsesCorrectVersion) { packet.reset(ConstructEncryptedPacket(guid_, kRandomSequenceNumber)); // Reset packet should be written, using the minimum quic version. - EXPECT_CALL(writer_, WritePacket(_, _, _, _, _)).Times(1) - .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 0))); + EXPECT_CALL(writer_, WritePacket(_, _, _, _, _, _)).Times(1); ProcessPacket(guid_, *packet); EXPECT_EQ(time_wait_list_manager_.version(), QuicVersionMin()); @@ -366,8 +369,7 @@ TEST_F(QuicTimeWaitListManagerTest, MakeSureFramerUsesCorrectVersion) { packet.reset(ConstructEncryptedPacket(guid_, kRandomSequenceNumber)); // Reset packet should be written, using the maximum quic version. - EXPECT_CALL(writer_, WritePacket(_, _, _, _, _)).Times(1) - .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 0))); + EXPECT_CALL(writer_, WritePacket(_, _, _, _, _, _)).Times(1); ProcessPacket(guid_, *packet); EXPECT_EQ(time_wait_list_manager_.version(), QuicVersionMax()); } diff --git a/net/tools/quic/test_tools/quic_test_utils.h b/net/tools/quic/test_tools/quic_test_utils.h index 2710a56..dffa255 100644 --- a/net/tools/quic/test_tools/quic_test_utils.h +++ b/net/tools/quic/test_tools/quic_test_utils.h @@ -125,12 +125,12 @@ class MockPacketWriter : public QuicPacketWriter { MockPacketWriter(); virtual ~MockPacketWriter(); - MOCK_METHOD5(WritePacket, - WriteResult(const char* buffer, - size_t buf_len, - const IPAddressNumber& self_address, - const IPEndPoint& peer_address, - QuicBlockedWriterInterface* blocked_writer)); + MOCK_METHOD6(WritePacket, int(const char* buffer, + size_t buf_len, + const IPAddressNumber& self_address, + const IPEndPoint& peer_address, + QuicBlockedWriterInterface* blocked_writer, + int* error)); }; } // namespace test |