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

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

Issue 10808073: Add WebSocketStream interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « net/net.gyp ('k') | 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
(Empty)
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.
4
5 #ifndef NET_WEBSOCKETS_WEBSOCKET_STREAM_H_
6 #define NET_WEBSOCKETS_WEBSOCKET_STREAM_H_
7
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_vector.h"
10 #include "net/base/completion_callback.h"
11
12 namespace net {
13
14 class BoundNetLog;
15 class HttpRequestHeaders;
16 struct HttpRequestInfo;
17 class HttpResponseInfo;
18 struct WebSocketFrameChunk;
19
20 // WebSocketStream is a transport-agnostic interface for reading and writing
21 // WebSocket frames. This class provides an abstraction for WebSocket streams
22 // based on various transport layer, such as normal WebSocket connections
23 // (WebSocket protocol upgraded from HTTP handshake), SPDY transports, or
24 // WebSocket connections with multiplexing extension. Subtypes of
25 // WebSocketStream are responsible for managing the underlying transport
26 // appropriately.
27
28 class WebSocketStream {
29 public:
30 WebSocketStream() {}
31 virtual ~WebSocketStream() {}
willchan no longer on Chromium 2012/07/23 21:28:52 Document that ~WebSocketStream will Close() the st
Yuta Kitamura 2012/08/06 11:34:29 Done.
32
33 // Initialize stream. Must be called before calling SendHandshakeRequest().
34 // Returns a net error code, possibly ERR_IO_PENDING. If return value is
35 // ERR_IO_PENDING, |callback| is called when the operation is finished. This
willchan no longer on Chromium 2012/07/23 21:28:52 In all these APIs, document that !callback.is_null
Yuta Kitamura 2012/08/06 11:34:29 Done. Requirement for asynchronous operations is m
36 // convention applies to other functions defined in this class.
37 //
38 // |request_info->url| must be a URL starting with "ws://" or "wss://".
39 // |request_info->method| must be "GET". |request_info->upload_data| is
40 // ignored.
41 virtual int InitializeStream(const HttpRequestInfo* request_info,
willchan no longer on Chromium 2012/07/23 21:28:52 const HttpRequestInfo&? I don't think it should be
Yuta Kitamura 2012/08/06 11:34:29 Correct. Fixed. (I just copied this from HttpStrea
42 const BoundNetLog& net_log,
43 const CompletionCallback& callback) = 0;
44
45 // Writes WebSocket handshake request to the underlying socket. Must be
46 // called after InitializeStream() completes and before
47 // ReadHandshakeResponse() is called.
48 virtual int SendHandshakeRequest(const HttpRequestHeaders& headers,
49 HttpResponseInfo* response_info,
50 const CompletionCallback& callback) = 0;
51
52 // Reads WebSocket handshake response from the underlying socket. This
53 // function completes when the response headers have been completely
54 // received. Must be called after SendHandshakeRequest() completes.
55 virtual int ReadHandshakeResponse(const CompletionCallback& callback) = 0;
willchan no longer on Chromium 2012/07/23 21:28:52 Why is this split out from SendHandshakeRequest()?
Yuta Kitamura 2012/08/06 11:34:29 Good point, there is not much reason except that H
56
57 // Reads WebSocket frame data. This operation finishes when new frame data
58 // becomes available. Each frame message might be chopped off in the middle
59 // as specified in the description of WebSocketFrameChunk struct.
60 // |frame_chunks| must be valid until the operation completes.
willchan no longer on Chromium 2012/07/23 21:28:52 or canceled via Close()
Yuta Kitamura 2012/08/06 11:34:29 Done.
61 //
62 // This function can be called after ReadHandshakeResponse(). This function
63 // should not be called while previous call of ReadFrames() is still pending.
64 virtual int ReadFrames(ScopedVector<WebSocketFrameChunk>* frame_chunks,
65 const CompletionCallback& callback) = 0;
66
67 // Writes WebSocket frame data. |frame_chunks| must obey the rule specified
68 // in the documentation of WebSocketFrameChunk struct. It is allowed to
69 // send part of WebSocket frame data.
70 //
71 // This function can be called after ReadHandshakeResponse(). This function
72 // should not be called while previous call of WriteFrames() is still pending.
73 virtual int WriteFrames(ScopedVector<WebSocketFrameChunk>* frame_chunks,
74 const CompletionCallback& callback) = 0;
mmenke 2012/07/23 17:46:05 How is this supposed to work when it sends only pa
Yuta Kitamura 2012/08/06 11:34:29 Users are expected to send one or more WebSocketFr
mmenke 2012/08/06 16:15:37 Thanks. You're right - the old comment had confus
75
76 // Disconnects the underlying connection. We don't support reuse of
77 // connections for now, because it is not clear whether existing WebSocket
78 // servers really support it.
79 virtual int Disconnect() = 0;
mmenke 2012/07/23 17:46:05 Should this be Close()? Also, what about the mult
mmenke 2012/07/23 17:46:05 Why do we need a return value?
willchan no longer on Chromium 2012/07/23 21:28:52 Yeah, this should be called closing the WebSocketS
Yuta Kitamura 2012/08/06 11:34:29 OK, fixed.
80
81 // TODO(yutak): Add following interfaces:
82 // - RenewStreamForAuth for authentication (is this necessary?)
83 // - GetSSLInfo, GetSSLCertRequsetInfo for SSL
84
85 private:
86 DISALLOW_COPY_AND_ASSIGN(WebSocketStream);
87 };
88
89 } // namespace net
90
91 #endif // NET_WEBSOCKETS_WEBSOCKET_STREAM_H_
OLDNEW
« no previous file with comments | « net/net.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698