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

Unified Diff: mojo/services/network/tcp_server_socket_impl.cc

Issue 634713002: Implement parts of the Mojo TCP interfaces. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: mojo/services/network/tcp_server_socket_impl.cc
diff --git a/mojo/services/network/tcp_server_socket_impl.cc b/mojo/services/network/tcp_server_socket_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b8a39d12fba24f42197a1ca3b91e90746430a77f
--- /dev/null
+++ b/mojo/services/network/tcp_server_socket_impl.cc
@@ -0,0 +1,66 @@
+// Copyright 2014 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.
+
+#include "mojo/services/network/tcp_server_socket_impl.h"
+
+#include "mojo/services/network/net_adapters.h"
+#include "mojo/services/network/net_address_type_converters.h"
+#include "mojo/services/network/tcp_connected_socket_impl.h"
+#include "net/base/net_errors.h"
+
+namespace mojo {
+
+TCPServerSocketImpl::TCPServerSocketImpl(scoped_ptr<net::TCPSocket> socket)
+ : socket_(socket.Pass()) {
+}
+
+TCPServerSocketImpl::~TCPServerSocketImpl() {
+}
+
+void TCPServerSocketImpl::Accept(
+ ScopedDataPipeConsumerHandle send_stream,
+ ScopedDataPipeProducerHandle receive_stream,
+ InterfaceRequest<TCPConnectedSocket> client_socket,
+ const AcceptCallback& callback) {
+ // One possible future enhancement would be to enqueue multiple Accept calls
+ // on this object. This would allow the client to accept some number of
+ // incoming connections rapidly without doing an IPC round-trip.
+ if (!pending_callback_.is_null()) {
+ // Already have a pending accept on this socket.
+ callback.Run(MakeNetworkError(net::ERR_UNEXPECTED), NetAddressPtr());
+ return;
+ }
+
+ int result = socket_->Accept(
+ &accepted_socket_, &accepted_address_,
+ base::Bind(&TCPServerSocketImpl::OnAcceptCompleted,
+ base::Unretained(this)));
+ if (result == net::ERR_IO_PENDING) {
+ pending_callback_ = callback;
+ pending_send_stream_ = send_stream.Pass();
+ pending_receive_stream_ = receive_stream.Pass();
+ pending_client_socket_ = client_socket.Pass();
+ } else {
+ callback.Run(MakeNetworkError(result), NetAddressPtr());
yzshen1 2014/10/07 20:14:34 We need to call into OnAcceptCompleted for this ca
+ }
+}
+
+void TCPServerSocketImpl::OnAcceptCompleted(int result) {
+ if (result != net::OK) {
+ pending_callback_.Run(MakeNetworkError(result), NetAddressPtr());
yzshen1 2014/10/07 20:14:34 Please release those pending_XXX members.
+ } else {
+ BindToRequest(new TCPConnectedSocketImpl(
+ accepted_socket_.Pass(),
+ pending_send_stream_.Pass(),
+ pending_receive_stream_.Pass()), &pending_client_socket_);
+ pending_callback_.Run(
+ MakeNetworkError(net::OK),
+ mojo::TypeConverter<NetAddressPtr, net::IPEndPoint>::Convert(
yzshen1 2014/10/07 20:14:34 you could do NetAddress::From(blah).
+ accepted_address_));
+ }
+
+ pending_callback_ = AcceptCallback();
+}
+
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698