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

Side by Side Diff: mojo/services/network/net_adapters.cc

Issue 1873463003: Remove mojo network service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
OLDNEW
(Empty)
1 // Copyright 2014 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 "mojo/services/network/net_adapters.h"
6
7 #include <stdint.h>
8
9 #include <utility>
10
11 #include "net/base/net_errors.h"
12
13 namespace mojo {
14
15 namespace {
16
17 const uint32_t kMaxBufSize = 64 * 1024;
18
19 } // namespace
20
21 NetToMojoPendingBuffer::NetToMojoPendingBuffer(
22 ScopedDataPipeProducerHandle handle,
23 void* buffer)
24 : handle_(std::move(handle)), buffer_(buffer) {}
25
26 NetToMojoPendingBuffer::~NetToMojoPendingBuffer() {
27 if (handle_.is_valid())
28 EndWriteDataRaw(handle_.get(), 0);
29 }
30
31 // static
32 MojoResult NetToMojoPendingBuffer::BeginWrite(
33 ScopedDataPipeProducerHandle* handle,
34 scoped_refptr<NetToMojoPendingBuffer>* pending,
35 uint32_t* num_bytes) {
36 void* buf;
37 *num_bytes = 0;
38
39 MojoResult result = BeginWriteDataRaw(handle->get(), &buf, num_bytes,
40 MOJO_WRITE_DATA_FLAG_NONE);
41 if (result == MOJO_RESULT_OK) {
42 if (*num_bytes > kMaxBufSize)
43 *num_bytes = kMaxBufSize;
44 *pending = new NetToMojoPendingBuffer(std::move(*handle), buf);
45 }
46 return result;
47 }
48
49 ScopedDataPipeProducerHandle NetToMojoPendingBuffer::Complete(
50 uint32_t num_bytes) {
51 EndWriteDataRaw(handle_.get(), num_bytes);
52 buffer_ = NULL;
53 return std::move(handle_);
54 }
55
56 // -----------------------------------------------------------------------------
57
58 NetToMojoIOBuffer::NetToMojoIOBuffer(
59 NetToMojoPendingBuffer* pending_buffer)
60 : net::WrappedIOBuffer(pending_buffer->buffer()),
61 pending_buffer_(pending_buffer) {
62 }
63
64 NetToMojoIOBuffer::~NetToMojoIOBuffer() {
65 }
66
67 // -----------------------------------------------------------------------------
68
69 MojoToNetPendingBuffer::MojoToNetPendingBuffer(
70 ScopedDataPipeConsumerHandle handle,
71 const void* buffer)
72 : handle_(std::move(handle)), buffer_(buffer) {}
73
74 MojoToNetPendingBuffer::~MojoToNetPendingBuffer() {
75 }
76
77 // static
78 MojoResult MojoToNetPendingBuffer::BeginRead(
79 ScopedDataPipeConsumerHandle* handle,
80 scoped_refptr<MojoToNetPendingBuffer>* pending,
81 uint32_t* num_bytes) {
82 const void* buffer = NULL;
83 *num_bytes = 0;
84 MojoResult result = BeginReadDataRaw(handle->get(), &buffer, num_bytes,
85 MOJO_READ_DATA_FLAG_NONE);
86 if (result == MOJO_RESULT_OK)
87 *pending = new MojoToNetPendingBuffer(std::move(*handle), buffer);
88 return result;
89 }
90
91 ScopedDataPipeConsumerHandle MojoToNetPendingBuffer::Complete(
92 uint32_t num_bytes) {
93 EndReadDataRaw(handle_.get(), num_bytes);
94 buffer_ = NULL;
95 return std::move(handle_);
96 }
97
98 // -----------------------------------------------------------------------------
99
100 MojoToNetIOBuffer::MojoToNetIOBuffer(MojoToNetPendingBuffer* pending_buffer)
101 : net::WrappedIOBuffer(pending_buffer->buffer()),
102 pending_buffer_(pending_buffer) {
103 }
104
105 MojoToNetIOBuffer::~MojoToNetIOBuffer() {
106 }
107
108 // -----------------------------------------------------------------------------
109
110 NetworkErrorPtr MakeNetworkError(int error_code) {
111 NetworkErrorPtr error = NetworkError::New();
112 error->code = error_code;
113 if (error_code <= 0)
114 error->description = net::ErrorToString(error_code);
115 return error;
116 }
117
118 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/network/net_adapters.h ('k') | mojo/services/network/net_address_type_converters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698