| 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_server.h" | 5 #include "net/tools/quic/quic_server.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <features.h> | 8 #include <features.h> |
| 9 #include <netinet/in.h> | 9 #include <netinet/in.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| 11 #include <sys/epoll.h> | 11 #include <sys/epoll.h> |
| 12 #include <sys/socket.h> | 12 #include <sys/socket.h> |
| 13 | 13 |
| 14 #include <memory> | 14 #include <memory> |
| 15 | 15 |
| 16 #include "net/base/ip_endpoint.h" | 16 #include "net/base/ip_endpoint.h" |
| 17 #include "net/base/sockaddr_storage.h" | 17 #include "net/base/sockaddr_storage.h" |
| 18 #include "net/quic/core/crypto/crypto_handshake.h" | 18 #include "net/quic/core/crypto/crypto_handshake.h" |
| 19 #include "net/quic/core/crypto/quic_random.h" | 19 #include "net/quic/core/crypto/quic_random.h" |
| 20 #include "net/quic/core/quic_crypto_stream.h" | 20 #include "net/quic/core/quic_crypto_stream.h" |
| 21 #include "net/quic/core/quic_data_reader.h" | 21 #include "net/quic/core/quic_data_reader.h" |
| 22 #include "net/quic/core/quic_packets.h" | 22 #include "net/quic/core/quic_packets.h" |
| 23 #include "net/quic/platform/api/quic_logging.h" |
| 23 #include "net/tools/quic/platform/impl/quic_epoll_clock.h" | 24 #include "net/tools/quic/platform/impl/quic_epoll_clock.h" |
| 24 #include "net/tools/quic/platform/impl/quic_socket_utils.h" | 25 #include "net/tools/quic/platform/impl/quic_socket_utils.h" |
| 25 #include "net/tools/quic/quic_dispatcher.h" | 26 #include "net/tools/quic/quic_dispatcher.h" |
| 26 #include "net/tools/quic/quic_epoll_alarm_factory.h" | 27 #include "net/tools/quic/quic_epoll_alarm_factory.h" |
| 27 #include "net/tools/quic/quic_epoll_connection_helper.h" | 28 #include "net/tools/quic/quic_epoll_connection_helper.h" |
| 28 #include "net/tools/quic/quic_http_response_cache.h" | 29 #include "net/tools/quic/quic_http_response_cache.h" |
| 29 #include "net/tools/quic/quic_packet_reader.h" | 30 #include "net/tools/quic/quic_packet_reader.h" |
| 30 #include "net/tools/quic/quic_simple_crypto_server_stream_helper.h" | 31 #include "net/tools/quic/quic_simple_crypto_server_stream_helper.h" |
| 31 #include "net/tools/quic/quic_simple_dispatcher.h" | 32 #include "net/tools/quic/quic_simple_dispatcher.h" |
| 32 | 33 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 bool QuicServer::CreateUDPSocketAndListen(const QuicSocketAddress& address) { | 111 bool QuicServer::CreateUDPSocketAndListen(const QuicSocketAddress& address) { |
| 111 fd_ = QuicSocketUtils::CreateUDPSocket(address, &overflow_supported_); | 112 fd_ = QuicSocketUtils::CreateUDPSocket(address, &overflow_supported_); |
| 112 if (fd_ < 0) { | 113 if (fd_ < 0) { |
| 113 LOG(ERROR) << "CreateSocket() failed: " << strerror(errno); | 114 LOG(ERROR) << "CreateSocket() failed: " << strerror(errno); |
| 114 return false; | 115 return false; |
| 115 } | 116 } |
| 116 | 117 |
| 117 sockaddr_storage addr = address.generic_address(); | 118 sockaddr_storage addr = address.generic_address(); |
| 118 int rc = bind(fd_, reinterpret_cast<sockaddr*>(&addr), sizeof(addr)); | 119 int rc = bind(fd_, reinterpret_cast<sockaddr*>(&addr), sizeof(addr)); |
| 119 if (rc < 0) { | 120 if (rc < 0) { |
| 120 LOG(ERROR) << "Bind failed: " << strerror(errno); | 121 QUIC_LOG(ERROR) << "Bind failed: " << strerror(errno); |
| 121 return false; | 122 return false; |
| 122 } | 123 } |
| 123 LOG(INFO) << "Listening on " << address.ToString(); | 124 QUIC_LOG(INFO) << "Listening on " << address.ToString(); |
| 124 port_ = address.port(); | 125 port_ = address.port(); |
| 125 if (port_ == 0) { | 126 if (port_ == 0) { |
| 126 QuicSocketAddress address; | 127 QuicSocketAddress address; |
| 127 if (address.FromSocket(fd_) != 0) { | 128 if (address.FromSocket(fd_) != 0) { |
| 128 LOG(ERROR) << "Unable to get self address. Error: " << strerror(errno); | 129 QUIC_LOG(ERROR) << "Unable to get self address. Error: " |
| 130 << strerror(errno); |
| 129 } | 131 } |
| 130 port_ = address.port(); | 132 port_ = address.port(); |
| 131 } | 133 } |
| 132 | 134 |
| 133 epoll_server_.RegisterFD(fd_, this, kEpollFlags); | 135 epoll_server_.RegisterFD(fd_, this, kEpollFlags); |
| 134 dispatcher_.reset(CreateQuicDispatcher()); | 136 dispatcher_.reset(CreateQuicDispatcher()); |
| 135 dispatcher_->InitializeWithWriter(CreateWriter(fd_)); | 137 dispatcher_->InitializeWithWriter(CreateWriter(fd_)); |
| 136 | 138 |
| 137 return true; | 139 return true; |
| 138 } | 140 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 dispatcher_->OnCanWrite(); | 197 dispatcher_->OnCanWrite(); |
| 196 if (dispatcher_->HasPendingWrites()) { | 198 if (dispatcher_->HasPendingWrites()) { |
| 197 event->out_ready_mask |= EPOLLOUT; | 199 event->out_ready_mask |= EPOLLOUT; |
| 198 } | 200 } |
| 199 } | 201 } |
| 200 if (event->in_events & EPOLLERR) { | 202 if (event->in_events & EPOLLERR) { |
| 201 } | 203 } |
| 202 } | 204 } |
| 203 | 205 |
| 204 } // namespace net | 206 } // namespace net |
| OLD | NEW |