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

Side by Side Diff: mojo/examples/http_server/http_server.cc

Issue 634713002: Implement parts of the Mojo TCP interfaces. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: missing file in gyp 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 unified diff | Download patch
« no previous file with comments | « mojo/examples/http_server/BUILD.gn ('k') | mojo/mojo_examples.gypi » ('j') | 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 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 <stdio.h>
6
7 #include "base/bind.h"
8 #include "mojo/public/c/system/main.h"
9 #include "mojo/public/cpp/application/application_delegate.h"
10 #include "mojo/public/cpp/application/application_impl.h"
11 #include "mojo/public/cpp/application/application_runner.h"
12 #include "mojo/services/public/interfaces/network/network_service.mojom.h"
13
14 namespace mojo {
15 namespace examples {
16
17 class HttpServerApp : public ApplicationDelegate {
18 public:
19 virtual void Initialize(ApplicationImpl* app) override {
20 app->ConnectToService("mojo:mojo_network_service", &network_service_);
21 Start();
22 }
23
24 private:
25 void OnListeningStarted(NetworkErrorPtr err) {
26 }
27
28 void OnSocketBound(NetworkErrorPtr err, NetAddressPtr bound_address) {
29 if (err->code != 0) {
30 printf("Bound err = %d\n", err->code);
31 return;
32 }
33
34 printf("Got address = %d.%d.%d.%d:%d\n",
35 (int)bound_address->ipv4->addr[0],
36 (int)bound_address->ipv4->addr[1],
37 (int)bound_address->ipv4->addr[2],
38 (int)bound_address->ipv4->addr[3],
39 (int)bound_address->ipv4->port);
40
41 bound_socket_->StartListening(
42 GetProxy(&server_socket_),
43 base::Bind(&HttpServerApp::OnListeningStarted,
44 base::Unretained(this)));
45 }
46
47 void Start() {
48 NetAddressPtr net_address(NetAddress::New());
49 net_address->family = NET_ADDRESS_FAMILY_IPV4;
50 net_address->ipv4 = NetAddressIPv4::New();
51 net_address->ipv4->addr.resize(4);
52 net_address->ipv4->addr[0] = 0;
53 net_address->ipv4->addr[1] = 0;
54 net_address->ipv4->addr[2] = 0;
55 net_address->ipv4->addr[3] = 0;
56
57 network_service_->CreateTCPBoundSocket(
58 net_address.Pass(),
59 GetProxy(&bound_socket_),
60 base::Bind(&HttpServerApp::OnSocketBound, base::Unretained(this)));
61 }
62
63 NetworkServicePtr network_service_;
64 TCPBoundSocketPtr bound_socket_;
65 TCPServerSocketPtr server_socket_;
66 };
67
68 } // namespace examples
69 } // namespace mojo
70
71 MojoResult MojoMain(MojoHandle shell_handle) {
72 mojo::ApplicationRunner runner(new mojo::examples::HttpServerApp);
73 return runner.Run(shell_handle);
74 }
OLDNEW
« no previous file with comments | « mojo/examples/http_server/BUILD.gn ('k') | mojo/mojo_examples.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698