0

Use a uint16_t for QUIC port values.

This reduces narrowing conversions.

Bug: 1216696
Change-Id: I601c4520540461075c3e756a4ea807f49bd718cf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2958228
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Victor Vasiliev <vasilvv@chromium.org>
Reviewed-by: Victor Vasiliev <vasilvv@chromium.org>
Cr-Commit-Position: refs/heads/master@{#892240}
This commit is contained in:
Peter Kasting
2021-06-14 20:17:04 +00:00
committed by Chromium LUCI CQ
parent 9e8d2f0f5d
commit 61adef1ab1
5 changed files with 24 additions and 4 deletions

@ -7,6 +7,7 @@
#include <algorithm>
#include <initializer_list>
#include <iostream>
#include <limits>
#include <set>
#include <string>
@ -191,6 +192,18 @@ bool TypedQuicFlagHelper<bool>::SetFlag(const std::string& s) const {
return false;
}
template <>
bool TypedQuicFlagHelper<uint16_t>::SetFlag(const std::string& s) const {
int value;
if (!base::StringToInt(s, &value) ||
value < std::numeric_limits<uint16_t>::min() ||
value > std::numeric_limits<uint16_t>::max()) {
return false;
}
*flag_ = static_cast<uint16_t>(value);
return true;
}
template <>
bool TypedQuicFlagHelper<int32_t>::SetFlag(const std::string& s) const {
int32_t value;
@ -209,6 +222,8 @@ bool TypedQuicFlagHelper<std::string>::SetFlag(const std::string& s) const {
template class EXPORT_TEMPLATE_DEFINE(QUIC_EXPORT_PRIVATE)
TypedQuicFlagHelper<bool>;
template class EXPORT_TEMPLATE_DEFINE(QUIC_EXPORT_PRIVATE)
TypedQuicFlagHelper<uint16_t>;
template class EXPORT_TEMPLATE_DEFINE(QUIC_EXPORT_PRIVATE)
TypedQuicFlagHelper<int32_t>;
template class EXPORT_TEMPLATE_DEFINE(QUIC_EXPORT_PRIVATE)

@ -72,6 +72,9 @@ template <>
QUIC_EXPORT_PRIVATE bool TypedQuicFlagHelper<bool>::SetFlag(
const std::string&) const;
template <>
QUIC_EXPORT_PRIVATE bool TypedQuicFlagHelper<uint16_t>::SetFlag(
const std::string&) const;
template <>
QUIC_EXPORT_PRIVATE bool TypedQuicFlagHelper<int32_t>::SetFlag(
const std::string&) const;
template <>
@ -81,6 +84,8 @@ QUIC_EXPORT_PRIVATE bool TypedQuicFlagHelper<std::string>::SetFlag(
// TypedQuicFlagHelper instantiations are in .cc file.
extern template class EXPORT_TEMPLATE_DECLARE(QUIC_EXPORT_PRIVATE)
TypedQuicFlagHelper<bool>;
extern template class EXPORT_TEMPLATE_DECLARE(QUIC_EXPORT_PRIVATE)
TypedQuicFlagHelper<uint16_t>;
extern template class EXPORT_TEMPLATE_DECLARE(QUIC_EXPORT_PRIVATE)
TypedQuicFlagHelper<int32_t>;
extern template class EXPORT_TEMPLATE_DECLARE(QUIC_EXPORT_PRIVATE)

@ -59,7 +59,7 @@ class QuicTransportSimpleServerSessionHelper
};
QuicTransportSimpleServer::QuicTransportSimpleServer(
int port,
uint16_t port,
std::vector<url::Origin> accepted_origins,
std::unique_ptr<quic::ProofSource> proof_source)
: port_(port),

@ -26,7 +26,7 @@ class QuicTransportSimpleServer {
public:
using ReadErrorCallback = base::OnceCallback<void(int)>;
QuicTransportSimpleServer(int port,
QuicTransportSimpleServer(uint16_t port,
std::vector<url::Origin> accepted_origins,
std::unique_ptr<quic::ProofSource> proof_source);
~QuicTransportSimpleServer();
@ -49,7 +49,7 @@ class QuicTransportSimpleServer {
// Passes the most recently read packet into the dispatcher.
void ProcessReadPacket(int result);
const int port_;
const uint16_t port_;
ReadErrorCallback read_error_callback_;

@ -9,7 +9,7 @@
#include "net/tools/quic/quic_transport_simple_server.h"
#include "url/gurl.h"
DEFINE_QUIC_COMMAND_LINE_FLAG(int, port, 20557, "The port to listen on.");
DEFINE_QUIC_COMMAND_LINE_FLAG(uint16_t, port, 20557, "The port to listen on.");
DEFINE_QUIC_COMMAND_LINE_FLAG(std::string,
accepted_origins,