| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 // Protobuf ZeroCopy[Input/Output]Stream implementations capable of using a | 5 // Protobuf ZeroCopy[Input/Output]Stream implementations capable of using a |
| 6 // net::StreamSocket. Built to work with Protobuf CodedStreams. | 6 // net::StreamSocket. Built to work with Protobuf CodedStreams. |
| 7 | 7 |
| 8 #ifndef GOOGLE_APIS_GCM_BASE_SOCKET_STREAM_H_ | 8 #ifndef GOOGLE_APIS_GCM_BASE_SOCKET_STREAM_H_ |
| 9 #define GOOGLE_APIS_GCM_BASE_SOCKET_STREAM_H_ | 9 #define GOOGLE_APIS_GCM_BASE_SOCKET_STREAM_H_ |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include <stdint.h> |
| 12 |
| 12 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
| 13 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 16 #include "google/protobuf/io/zero_copy_stream.h" | 18 #include "google/protobuf/io/zero_copy_stream.h" |
| 17 #include "google_apis/gcm/base/gcm_export.h" | 19 #include "google_apis/gcm/base/gcm_export.h" |
| 18 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
| 19 | 21 |
| 20 namespace net { | 22 namespace net { |
| 21 class DrainableIOBuffer; | 23 class DrainableIOBuffer; |
| 22 class IOBuffer; | 24 class IOBuffer; |
| 23 class StreamSocket; | 25 class StreamSocket; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 }; | 64 }; |
| 63 | 65 |
| 64 // |socket| should already be connected. | 66 // |socket| should already be connected. |
| 65 explicit SocketInputStream(net::StreamSocket* socket); | 67 explicit SocketInputStream(net::StreamSocket* socket); |
| 66 ~SocketInputStream() override; | 68 ~SocketInputStream() override; |
| 67 | 69 |
| 68 // ZeroCopyInputStream implementation. | 70 // ZeroCopyInputStream implementation. |
| 69 bool Next(const void** data, int* size) override; | 71 bool Next(const void** data, int* size) override; |
| 70 void BackUp(int count) override; | 72 void BackUp(int count) override; |
| 71 bool Skip(int count) override; // Not implemented. | 73 bool Skip(int count) override; // Not implemented. |
| 72 int64 ByteCount() const override; | 74 int64_t ByteCount() const override; |
| 73 | 75 |
| 74 // The remaining amount of valid data available to be read. | 76 // The remaining amount of valid data available to be read. |
| 75 int UnreadByteCount() const; | 77 int UnreadByteCount() const; |
| 76 | 78 |
| 77 // Reads from the socket, appending a max of |byte_limit| bytes onto the read | 79 // Reads from the socket, appending a max of |byte_limit| bytes onto the read |
| 78 // buffer. net::ERR_IO_PENDING is returned if the refresh can't complete | 80 // buffer. net::ERR_IO_PENDING is returned if the refresh can't complete |
| 79 // synchronously, in which case the callback is invoked upon completion. If | 81 // synchronously, in which case the callback is invoked upon completion. If |
| 80 // the refresh can complete synchronously, even in case of an error, returns | 82 // the refresh can complete synchronously, even in case of an error, returns |
| 81 // net::OK without invoking callback. | 83 // net::OK without invoking callback. |
| 82 // Note: GetState() (and possibly last_error()) should be checked upon | 84 // Note: GetState() (and possibly last_error()) should be checked upon |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 CLOSED, | 159 CLOSED, |
| 158 }; | 160 }; |
| 159 | 161 |
| 160 // |socket| should already be connected. | 162 // |socket| should already be connected. |
| 161 explicit SocketOutputStream(net::StreamSocket* socket); | 163 explicit SocketOutputStream(net::StreamSocket* socket); |
| 162 ~SocketOutputStream() override; | 164 ~SocketOutputStream() override; |
| 163 | 165 |
| 164 // ZeroCopyOutputStream implementation. | 166 // ZeroCopyOutputStream implementation. |
| 165 bool Next(void** data, int* size) override; | 167 bool Next(void** data, int* size) override; |
| 166 void BackUp(int count) override; | 168 void BackUp(int count) override; |
| 167 int64 ByteCount() const override; | 169 int64_t ByteCount() const override; |
| 168 | 170 |
| 169 // Writes the buffer into the Socket. | 171 // Writes the buffer into the Socket. |
| 170 net::Error Flush(const base::Closure& callback); | 172 net::Error Flush(const base::Closure& callback); |
| 171 | 173 |
| 172 // Returns the last fatal error encountered. Only valid if GetState() == | 174 // Returns the last fatal error encountered. Only valid if GetState() == |
| 173 // CLOSED. | 175 // CLOSED. |
| 174 net::Error last_error() const; | 176 net::Error last_error() const; |
| 175 | 177 |
| 176 // Returns the current state. | 178 // Returns the current state. |
| 177 State GetState() const; | 179 State GetState() const; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 196 net::Error last_error_; | 198 net::Error last_error_; |
| 197 | 199 |
| 198 base::WeakPtrFactory<SocketOutputStream> weak_ptr_factory_; | 200 base::WeakPtrFactory<SocketOutputStream> weak_ptr_factory_; |
| 199 | 201 |
| 200 DISALLOW_COPY_AND_ASSIGN(SocketOutputStream); | 202 DISALLOW_COPY_AND_ASSIGN(SocketOutputStream); |
| 201 }; | 203 }; |
| 202 | 204 |
| 203 } // namespace gcm | 205 } // namespace gcm |
| 204 | 206 |
| 205 #endif // GOOGLE_APIS_GCM_BASE_SOCKET_STREAM_H_ | 207 #endif // GOOGLE_APIS_GCM_BASE_SOCKET_STREAM_H_ |
| OLD | NEW |