1 // Copyright 2024 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_SOCKET_TCP_STREAM_ATTEMPT_H_ 6 #define NET_SOCKET_TCP_STREAM_ATTEMPT_H_ 7 8 #include <string_view> 9 10 #include "base/time/time.h" 11 #include "base/timer/timer.h" 12 #include "base/values.h" 13 #include "net/base/ip_endpoint.h" 14 #include "net/base/net_export.h" 15 #include "net/socket/stream_attempt.h" 16 17 namespace net { 18 19 class NetLogWithSource; 20 21 // Represents a single TCP connection attempt. 22 class NET_EXPORT_PRIVATE TcpStreamAttempt final : public StreamAttempt { 23 public: 24 // This timeout is shorter than TransportConnectJob::ConnectionTimeout() 25 // because a TcpStreamAttempt only attempts a single TCP connection. 26 static constexpr base::TimeDelta kTcpHandshakeTimeout = base::Seconds(60); 27 28 TcpStreamAttempt(const StreamAttemptParams* params, 29 IPEndPoint ip_endpoint, 30 const NetLogWithSource* = nullptr); 31 32 TcpStreamAttempt(const TcpStreamAttempt&) = delete; 33 TcpStreamAttempt& operator=(const TcpStreamAttempt&) = delete; 34 35 ~TcpStreamAttempt() override; 36 37 LoadState GetLoadState() const override; 38 39 base::Value::Dict GetInfoAsValue() const override; 40 41 private: 42 enum class State { 43 kNone, 44 kConnecting, 45 }; 46 47 static std::string_view StateToString(State state); 48 49 // StreamAttempt methods: 50 int StartInternal() override; 51 base::Value::Dict GetNetLogStartParams() override; 52 53 void HandleCompletion(); 54 55 void OnIOComplete(int rv); 56 57 void OnTimeout(); 58 59 State next_state_ = State::kNone; 60 base::OneShotTimer timeout_timer_; 61 }; 62 63 } // namespace net 64 65 #endif // NET_SOCKET_TCP_STREAM_ATTEMPT_H_ 66