summaryrefslogtreecommitdiffstats
path: root/net/websockets
diff options
context:
space:
mode:
authoryutak@chromium.org <yutak@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-09 03:43:50 +0000
committeryutak@chromium.org <yutak@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-09 03:43:50 +0000
commit55cf6a61387f2efda3692ca9bf5ee13373f27e27 (patch)
treea41ba2d964ee60b0c5b8ab73890eefee6b460b34 /net/websockets
parent594aea05aa0056dc11bf82128efcd388fd13bd84 (diff)
downloadchromium_src-55cf6a61387f2efda3692ca9bf5ee13373f27e27.zip
chromium_src-55cf6a61387f2efda3692ca9bf5ee13373f27e27.tar.gz
chromium_src-55cf6a61387f2efda3692ca9bf5ee13373f27e27.tar.bz2
Add WebSocketStream interface.
BUG=116624 TEST=none R=mmenke@chromium.org,willchan@chromium.org Review URL: https://chromiumcodereview.appspot.com/10808073 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150713 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/websockets')
-rw-r--r--net/websockets/websocket_stream.h104
1 files changed, 104 insertions, 0 deletions
diff --git a/net/websockets/websocket_stream.h b/net/websockets/websocket_stream.h
new file mode 100644
index 0000000..7e31edc
--- /dev/null
+++ b/net/websockets/websocket_stream.h
@@ -0,0 +1,104 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_WEBSOCKETS_WEBSOCKET_STREAM_H_
+#define NET_WEBSOCKETS_WEBSOCKET_STREAM_H_
+
+#include "base/basictypes.h"
+#include "base/memory/scoped_vector.h"
+#include "net/base/completion_callback.h"
+
+namespace net {
+
+class BoundNetLog;
+class HttpRequestHeaders;
+struct HttpRequestInfo;
+class HttpResponseInfo;
+struct WebSocketFrameChunk;
+
+// WebSocketStream is a transport-agnostic interface for reading and writing
+// WebSocket frames. This class provides an abstraction for WebSocket streams
+// based on various transport layer, such as normal WebSocket connections
+// (WebSocket protocol upgraded from HTTP handshake), SPDY transports, or
+// WebSocket connections with multiplexing extension. Subtypes of
+// WebSocketStream are responsible for managing the underlying transport
+// appropriately.
+//
+// All functions except Close() can be asynchronous. If an operation cannot
+// be finished synchronously, the function returns ERR_IO_PENDING, and
+// |callback| will be called when the operation is finished. Non-null |callback|
+// must be provided to these functions.
+
+class WebSocketStream {
+ public:
+ WebSocketStream() {}
+
+ // Derived classes must make sure Close() is called when the stream is not
+ // closed on destruction.
+ virtual ~WebSocketStream() {}
+
+ // Initializes stream. Must be called before calling SendHandshakeRequest().
+ // Returns a net error code, possibly ERR_IO_PENDING, as stated above.
+ //
+ // |request_info->url| must be a URL starting with "ws://" or "wss://".
+ // |request_info->method| must be "GET". |request_info->upload_data| is
+ // ignored.
+ virtual int InitializeStream(const HttpRequestInfo& request_info,
+ const BoundNetLog& net_log,
+ const CompletionCallback& callback) = 0;
+
+ // Writes WebSocket handshake request to the underlying socket. Must be
+ // called after InitializeStream() completes and before
+ // ReadHandshakeResponse() is called.
+ //
+ // |response_info| must remain valid until the stream is destroyed.
+ virtual int SendHandshakeRequest(const HttpRequestHeaders& headers,
+ HttpResponseInfo* response_info,
+ const CompletionCallback& callback) = 0;
+
+ // Reads WebSocket handshake response from the underlying socket. This
+ // function completes when the response headers have been completely
+ // received. Must be called after SendHandshakeRequest() completes.
+ virtual int ReadHandshakeResponse(const CompletionCallback& callback) = 0;
+
+ // Reads WebSocket frame data. This operation finishes when new frame data
+ // becomes available. Each frame message might be chopped off in the middle
+ // as specified in the description of WebSocketFrameChunk struct.
+ // |frame_chunks| must be valid until the operation completes or Close()
+ // is called.
+ //
+ // This function can be called after ReadHandshakeResponse(). This function
+ // should not be called while the previous call of ReadFrames() is still
+ // pending.
+ virtual int ReadFrames(ScopedVector<WebSocketFrameChunk>* frame_chunks,
+ const CompletionCallback& callback) = 0;
+
+ // Writes WebSocket frame data. |frame_chunks| must obey the rule specified
+ // in the documentation of WebSocketFrameChunk struct: the first chunk of
+ // a WebSocket frame must contain non-NULL |header|, and the last chunk must
+ // have |final_chunk| field set to true. Series of chunks representing a
+ // WebSocket frame must be consistent (the total length of |data| fields must
+ // match |header->payload_length|). |frame_chunks| must be valid until the
+ // operation completes or Close() is called.
+ //
+ // This function can be called after ReadHandshakeResponse(). This function
+ // should not be called while previous call of WriteFrames() is still pending.
+ virtual int WriteFrames(ScopedVector<WebSocketFrameChunk>* frame_chunks,
+ const CompletionCallback& callback) = 0;
+
+ // Closes the stream. All pending I/O operations (if any) are canceled
+ // at this point, so |frame_chunks| can be freed.
+ virtual void Close() = 0;
+
+ // TODO(yutak): Add following interfaces:
+ // - RenewStreamForAuth for authentication (is this necessary?)
+ // - GetSSLInfo, GetSSLCertRequsetInfo for SSL
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(WebSocketStream);
+};
+
+} // namespace net
+
+#endif // NET_WEBSOCKETS_WEBSOCKET_STREAM_H_