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
3 // found in the LICENSE file.
5 #include "net/tools/quic/quic_server_session.h"
7 #include "base/logging.h"
8 #include "net/quic/reliable_quic_stream.h"
9 #include "net/tools/quic/quic_spdy_server_stream.h"
14 QuicServerSession::QuicServerSession(
15 const QuicConfig
& config
,
16 QuicConnection
* connection
,
17 QuicSessionOwner
* owner
)
18 : QuicSession(connection
, config
, true),
22 QuicServerSession::~QuicServerSession() {
25 void QuicServerSession::InitializeSession(
26 const QuicCryptoServerConfig
& crypto_config
) {
27 crypto_stream_
.reset(CreateQuicCryptoServerStream(crypto_config
));
30 QuicCryptoServerStream
* QuicServerSession::CreateQuicCryptoServerStream(
31 const QuicCryptoServerConfig
& crypto_config
) {
32 return new QuicCryptoServerStream(crypto_config
, this);
35 void QuicServerSession::ConnectionClose(QuicErrorCode error
, bool from_peer
) {
36 QuicSession::ConnectionClose(error
, from_peer
);
37 owner_
->OnConnectionClose(connection()->guid(), error
);
40 bool QuicServerSession::ShouldCreateIncomingReliableStream(QuicStreamId id
) {
42 DLOG(INFO
) << "Invalid incoming even stream_id:" << id
;
43 connection()->SendConnectionClose(QUIC_INVALID_STREAM_ID
);
46 if (GetNumOpenStreams() >= get_max_open_streams()) {
47 DLOG(INFO
) << "Failed to create a new incoming stream with id:" << id
48 << " Already " << GetNumOpenStreams() << " open.";
49 connection()->SendConnectionClose(QUIC_TOO_MANY_OPEN_STREAMS
);
55 ReliableQuicStream
* QuicServerSession::CreateIncomingReliableStream(
57 if (!ShouldCreateIncomingReliableStream(id
)) {
61 return new QuicSpdyServerStream(id
, this);
64 ReliableQuicStream
* QuicServerSession::CreateOutgoingReliableStream() {
65 DLOG(ERROR
) << "Server push not yet supported";
69 QuicCryptoServerStream
* QuicServerSession::GetCryptoStream() {
70 return crypto_stream_
.get();