Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: net/spdy/spdy_websocket_stream.cc

Issue 3020068: WebSocket over SPDY. (Closed)
Patch Set: fix unittests Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/spdy/spdy_websocket_stream.h ('k') | net/spdy/spdy_websocket_stream_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 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.
4
5 #include "net/spdy/spdy_websocket_stream.h"
6
7 #include "googleurl/src/gurl.h"
8 #include "net/base/net_errors.h"
9 #include "net/base/io_buffer.h"
10 #include "net/spdy/spdy_framer.h"
11 #include "net/spdy/spdy_protocol.h"
12 #include "net/spdy/spdy_session.h"
13 #include "net/spdy/spdy_stream.h"
14
15 namespace net {
16
17 SpdyWebSocketStream::SpdyWebSocketStream(
18 SpdySession* spdy_session,
19 SpdyWebSocketStreamDelegate* delegate)
20 : stream_(NULL),
21 spdy_session_(spdy_session),
22 delegate_(delegate),
23 ALLOW_THIS_IN_INITIALIZER_LIST(
24 io_callback_(this, &SpdyWebSocketStream::OnIOCompleted)) {
25 }
26
27 SpdyWebSocketStream::~SpdyWebSocketStream() {
28 if (stream_)
29 stream_->DetachDelegate();
30 }
31
32 int SpdyWebSocketStream::InitializeStream(
33 const GURL& url,
34 RequestPriority request_priority,
35 const BoundNetLog& net_log) {
36 if (spdy_session_->IsClosed())
37 return ERR_CONNECTION_CLOSED;
38
39 int result = spdy_session_->CreateStream(url,
40 request_priority,
41 &stream_,
42 net_log,
43 &io_callback_);
44 if (result != ERR_IO_PENDING)
45 OnSpdyStreamCreated(result);
46 return result;
47 }
48
49 void SpdyWebSocketStream::SendRequest(
50 linked_ptr<spdy::SpdyHeaderBlock> headers) {
51 if (!stream_)
52 return;
53 stream_->set_spdy_headers(headers);
54 int result = stream_->SendRequest(true);
55 if (result < OK && result != ERR_IO_PENDING)
56 Close();
57 }
58
59 void SpdyWebSocketStream::SendData(const char* data, int length) {
60 if (!stream_)
61 return;
62 IOBuffer* buf(new IOBuffer(length));
63 memcpy(buf->data(), data, length);
64 int result = stream_->WriteStreamData(buf, length, spdy::DATA_FLAG_NONE);
65 if (result < OK && result != ERR_IO_PENDING)
66 Close();
67 }
68
69 void SpdyWebSocketStream::Close() {
70 if (spdy_session_)
71 spdy_session_->CancelPendingCreateStreams(&stream_);
72 if (stream_)
73 stream_->Close();
74 }
75
76 bool SpdyWebSocketStream::OnSendHeadersComplete(int status) {
77 if (delegate_)
78 delegate_->OnSentSpdyHeaders(this);
79 return true;
80 }
81
82 int SpdyWebSocketStream::OnSendBody() {
83 NOTREACHED();
84 return ERR_UNEXPECTED;
85 }
86
87 bool SpdyWebSocketStream::OnSendBodyComplete(int status) {
88 NOTREACHED();
89 return true;
90 }
91
92 bool SpdyWebSocketStream::IsFinishedSendingBody() {
93 NOTREACHED();
94 return true;
95 }
96
97 int SpdyWebSocketStream::OnResponseReceived(
98 const spdy::SpdyHeaderBlock& response,
99 base::Time response_time, int status) {
100 if (!delegate_)
101 return ERR_ABORTED;
102 return delegate_->OnReceivedSpdyResponseHeader(this, response, status);
103 }
104
105 void SpdyWebSocketStream::OnDataReceived(const char* data, int length) {
106 if (!delegate_)
107 return;
108 delegate_->OnReceivedSpdyData(this, data, length);
109 }
110
111 void SpdyWebSocketStream::OnDataSent(int length) {
112 if (!delegate_)
113 return;
114 delegate_->OnSentSpdyData(this, length);
115 }
116
117 void SpdyWebSocketStream::OnClose(int status) {
118 if (!delegate_)
119 return;
120 SpdyWebSocketStreamDelegate* delegate = delegate_;
121 delegate_ = NULL;
122 stream_ = NULL;
123 if (delegate)
124 delegate->OnCloseSpdyStream(this);
125 }
126
127 void SpdyWebSocketStream::OnIOCompleted(int result) {
128 OnSpdyStreamCreated(result);
129 }
130
131 void SpdyWebSocketStream::OnSpdyStreamCreated(int result) {
132 DCHECK_NE(ERR_IO_PENDING, result);
133 if (stream_)
134 stream_->SetDelegate(this);
135 if (delegate_) {
136 delegate_->OnCreatedSpdyStream(this, result);
137 }
138 }
139
140
141 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_websocket_stream.h ('k') | net/spdy/spdy_websocket_stream_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698