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

Side by Side Diff: net/websockets/websocket_stream.h

Issue 23685005: Clarify the specification of WriteFrames() (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 3 months 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef NET_WEBSOCKETS_WEBSOCKET_STREAM_H_ 5 #ifndef NET_WEBSOCKETS_WEBSOCKET_STREAM_H_
6 #define NET_WEBSOCKETS_WEBSOCKET_STREAM_H_ 6 #define NET_WEBSOCKETS_WEBSOCKET_STREAM_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 URLRequestContext* url_request_context, 85 URLRequestContext* url_request_context,
86 const BoundNetLog& net_log, 86 const BoundNetLog& net_log,
87 scoped_ptr<ConnectDelegate> connect_delegate); 87 scoped_ptr<ConnectDelegate> connect_delegate);
88 88
89 // Derived classes must make sure Close() is called when the stream is not 89 // Derived classes must make sure Close() is called when the stream is not
90 // closed on destruction. 90 // closed on destruction.
91 virtual ~WebSocketStream(); 91 virtual ~WebSocketStream();
92 92
93 // Reads WebSocket frame data. This operation finishes when new frame data 93 // Reads WebSocket frame data. This operation finishes when new frame data
94 // becomes available. Each frame message might be chopped off in the middle 94 // becomes available. Each frame message might be chopped off in the middle
95 // as specified in the description of WebSocketFrameChunk struct. 95 // as specified in the description of the WebSocketFrameChunk struct.
96 // |frame_chunks| remains owned by the caller and must be valid until the 96 // |frame_chunks| remains owned by the caller and must be valid until the
97 // operation completes or Close() is called. |frame_chunks| must be empty on 97 // operation completes or Close() is called. |frame_chunks| must be empty on
98 // calling. 98 // calling.
99 // 99 //
100 // This function should not be called while the previous call of ReadFrames() 100 // This function should not be called while the previous call of ReadFrames()
101 // is still pending. 101 // is still pending.
102 // 102 //
103 // Returns net::OK or one of the net::ERR_* codes. 103 // Returns net::OK or one of the net::ERR_* codes.
104 // 104 //
105 // frame_chunks->size() >= 1 if the result is OK. 105 // frame_chunks->size() >= 1 if the result is OK.
(...skipping 14 matching lines...) Expand all
120 // When the socket is closed on the remote side, this method will return 120 // When the socket is closed on the remote side, this method will return
121 // ERR_CONNECTION_CLOSED. It will not return OK with an empty vector. 121 // ERR_CONNECTION_CLOSED. It will not return OK with an empty vector.
122 // 122 //
123 // If the connection is closed in the middle of receiving an incomplete frame, 123 // If the connection is closed in the middle of receiving an incomplete frame,
124 // ReadFrames may discard the incomplete frame. Since the renderer will 124 // ReadFrames may discard the incomplete frame. Since the renderer will
125 // discard any incomplete messages when the connection is closed, this makes 125 // discard any incomplete messages when the connection is closed, this makes
126 // no difference to the overall semantics. 126 // no difference to the overall semantics.
127 virtual int ReadFrames(ScopedVector<WebSocketFrameChunk>* frame_chunks, 127 virtual int ReadFrames(ScopedVector<WebSocketFrameChunk>* frame_chunks,
128 const CompletionCallback& callback) = 0; 128 const CompletionCallback& callback) = 0;
129 129
130 // Writes WebSocket frame data. |frame_chunks| must obey the rule specified 130 // Writes WebSocket frame data. |frame_chunks| must only contain complete
131 // in the documentation of WebSocketFrameChunk struct: the first chunk of 131 // frames. Every chunk must have a non-NULL |header| and the |final_chunk|
132 // a WebSocket frame must contain non-NULL |header|, and the last chunk must 132 // boolean set to true.
133 // have |final_chunk| field set to true. Series of chunks representing a
134 // WebSocket frame must be consistent (the total length of |data| fields must
135 // match |header->payload_length|). |frame_chunks| must be valid until the
136 // operation completes or Close() is called.
137 // 133 //
138 // This function should not be called while previous call of WriteFrames() is 134 // The |frame_chunks| pointer must remain valid until the operation completes
139 // still pending. 135 // or Close() is called. WriteFrames() will modify the contents of
136 // |frame_chunks| in the process of sending the message. After WriteFrames()
137 // has completed it is safe to clear and then re-use the vector, but other
138 // than that the caller should make no assumptions about its contents.
140 // 139 //
141 // Support for incomplete frames is not guaranteed and may be removed from 140 // This function should not be called while a previous call to WriteFrames()
142 // future iterations of the API. 141 // on the same stream is pending.
142 //
143 // Frame boundaries may not be preserved. Frames may be split or
144 // coalesced. Message boundaries are preserved (as required by WebSocket API
145 // semantics).
143 // 146 //
144 // This method will only return OK if all frames were written completely. 147 // This method will only return OK if all frames were written completely.
145 // Otherwise it will return an appropriate net error code. 148 // Otherwise it will return an appropriate net error code.
146 virtual int WriteFrames(ScopedVector<WebSocketFrameChunk>* frame_chunks, 149 virtual int WriteFrames(ScopedVector<WebSocketFrameChunk>* frame_chunks,
147 const CompletionCallback& callback) = 0; 150 const CompletionCallback& callback) = 0;
148 151
149 // Closes the stream. All pending I/O operations (if any) are cancelled 152 // Closes the stream. All pending I/O operations (if any) are cancelled
150 // at this point, so |frame_chunks| can be freed. 153 // at this point, so |frame_chunks| can be freed.
151 virtual void Close() = 0; 154 virtual void Close() = 0;
152 155
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 protected: 205 protected:
203 WebSocketStream(); 206 WebSocketStream();
204 207
205 private: 208 private:
206 DISALLOW_COPY_AND_ASSIGN(WebSocketStream); 209 DISALLOW_COPY_AND_ASSIGN(WebSocketStream);
207 }; 210 };
208 211
209 } // namespace net 212 } // namespace net
210 213
211 #endif // NET_WEBSOCKETS_WEBSOCKET_STREAM_H_ 214 #endif // NET_WEBSOCKETS_WEBSOCKET_STREAM_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698