| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/tools/quic/quic_client.h" | 5 #include "net/tools/quic/quic_client.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <netinet/in.h> | 8 #include <netinet/in.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 #include <sys/epoll.h> | 10 #include <sys/epoll.h> |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 114 |
| 115 epoll_server_.RegisterFD(fd_, this, kEpollFlags); | 115 epoll_server_.RegisterFD(fd_, this, kEpollFlags); |
| 116 initialized_ = true; | 116 initialized_ = true; |
| 117 return true; | 117 return true; |
| 118 } | 118 } |
| 119 | 119 |
| 120 bool QuicClient::Connect() { | 120 bool QuicClient::Connect() { |
| 121 if (!StartConnect()) { | 121 if (!StartConnect()) { |
| 122 return false; | 122 return false; |
| 123 } | 123 } |
| 124 while (CryptoHandshakeInProgress()) { | 124 while (EncryptionBeingEstablished()) { |
| 125 WaitForEvents(); | 125 WaitForEvents(); |
| 126 } | 126 } |
| 127 return session_->connection()->connected(); | 127 return session_->connection()->connected(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 bool QuicClient::StartConnect() { | 130 bool QuicClient::StartConnect() { |
| 131 DCHECK(!connected() && initialized_); | 131 DCHECK(!connected() && initialized_); |
| 132 | 132 |
| 133 QuicGuid guid = QuicRandom::GetInstance()->RandUint64(); | 133 QuicGuid guid = QuicRandom::GetInstance()->RandUint64(); |
| 134 session_.reset(new QuicClientSession( | 134 session_.reset(new QuicClientSession( |
| 135 server_hostname_, | 135 server_hostname_, |
| 136 config_, | 136 config_, |
| 137 new QuicConnection(guid, server_address_, | 137 new QuicConnection(guid, server_address_, |
| 138 new QuicEpollConnectionHelper(fd_, &epoll_server_), | 138 new QuicEpollConnectionHelper(fd_, &epoll_server_), |
| 139 false), | 139 false), |
| 140 &crypto_config_)); | 140 &crypto_config_)); |
| 141 return session_->CryptoConnect(); | 141 return session_->CryptoConnect(); |
| 142 } | 142 } |
| 143 | 143 |
| 144 bool QuicClient::CryptoHandshakeInProgress() { | 144 bool QuicClient::EncryptionBeingEstablished() { |
| 145 return !session_->IsCryptoHandshakeComplete() && | 145 return !session_->IsEncryptionEstablished() && |
| 146 session_->connection()->connected(); | 146 session_->connection()->connected(); |
| 147 } | 147 } |
| 148 | 148 |
| 149 void QuicClient::Disconnect() { | 149 void QuicClient::Disconnect() { |
| 150 DCHECK(connected()); | 150 DCHECK(connected()); |
| 151 | 151 |
| 152 session()->connection()->SendConnectionClose(QUIC_PEER_GOING_AWAY); | 152 session()->connection()->SendConnectionClose(QUIC_PEER_GOING_AWAY); |
| 153 epoll_server_.UnregisterFD(fd_); | 153 epoll_server_.UnregisterFD(fd_); |
| 154 close(fd_); | 154 close(fd_); |
| 155 fd_ = -1; | 155 fd_ = -1; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 } | 244 } |
| 245 | 245 |
| 246 IPEndPoint client_address(client_ip, client_address_.port()); | 246 IPEndPoint client_address(client_ip, client_address_.port()); |
| 247 session_->connection()->ProcessUdpPacket( | 247 session_->connection()->ProcessUdpPacket( |
| 248 client_address, server_address, packet); | 248 client_address, server_address, packet); |
| 249 return true; | 249 return true; |
| 250 } | 250 } |
| 251 | 251 |
| 252 } // namespace tools | 252 } // namespace tools |
| 253 } // namespace net | 253 } // namespace net |
| OLD | NEW |