OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #include "mojo/spy/websocket_server.h" | 5 #include "mojo/spy/websocket_server.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | |
8 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/time/time.h" | |
9 #include "net/base/ip_endpoint.h" | 11 #include "net/base/ip_endpoint.h" |
10 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
11 #include "net/server/http_server_request_info.h" | 13 #include "net/server/http_server_request_info.h" |
12 #include "net/server/http_server_response_info.h" | 14 #include "net/server/http_server_response_info.h" |
13 #include "net/socket/tcp_listen_socket.h" | 15 #include "net/socket/tcp_listen_socket.h" |
16 #include "url/gurl.h" | |
14 | 17 |
15 namespace spy { | 18 namespace spy { |
16 | 19 |
17 const int kNotConnected = -1; | 20 const int kNotConnected = -1; |
18 | 21 |
19 WebSocketServer::WebSocketServer(int port) | 22 WebSocketServer::WebSocketServer(int port) |
20 : port_(port), connection_id_(kNotConnected) { | 23 : port_(port), connection_id_(kNotConnected) { |
21 } | 24 } |
22 | 25 |
23 WebSocketServer::~WebSocketServer() { | 26 WebSocketServer::~WebSocketServer() { |
24 } | 27 } |
25 | 28 |
26 bool WebSocketServer::Start() { | 29 bool WebSocketServer::Start() { |
27 net::TCPListenSocketFactory factory("0.0.0.0", port_); | 30 net::TCPListenSocketFactory factory("0.0.0.0", port_); |
28 server_ = new net::HttpServer(factory, this); | 31 server_ = new net::HttpServer(factory, this); |
29 net::IPEndPoint address; | 32 net::IPEndPoint address; |
30 int error = server_->GetLocalAddress(&address); | 33 int error = server_->GetLocalAddress(&address); |
31 port_ = address.port(); | 34 port_ = address.port(); |
32 return (error == net::OK); | 35 return (error == net::OK); |
33 } | 36 } |
34 | 37 |
38 void WebSocketServer::LogMessageInfo( | |
39 const mojo::MojoMessageHeader& message_header, | |
40 const GURL& url, | |
41 const base::Time& message_time) { | |
42 base::Time::Exploded exploded; | |
43 message_time.LocalExplode(&exploded); | |
44 | |
cpu_(ooo_6.6-7.5)
2014/06/27 01:44:06
assume you have:
bool WebSocketServer::connected(
ananta
2014/07/03 00:04:40
Done.
| |
45 DLOG(INFO) << "\n\nStart of message for url :" << url.spec(); | |
46 DLOG(INFO) << "Message Time Hours :" << exploded.hour; | |
47 DLOG(INFO) << "Message Time Mins :" << exploded.minute; | |
48 DLOG(INFO) << "Message Time Secs :" << exploded.second; | |
49 DLOG(INFO) << "Message Bytes : " << message_header.num_bytes; | |
50 DLOG(INFO) << "Message Fields : " << message_header.num_fields; | |
51 DLOG(INFO) << "Message name : " << message_header.name; | |
52 if (message_header.num_fields == 3) { | |
53 DLOG(INFO) << "Message has request id"; | |
54 DLOG(INFO) << "Message Request ID : " | |
55 << message_header.request_id; | |
56 } | |
57 if (message_header.flags & mojo::kMessageExpectsResponse) { | |
58 DLOG(INFO) << "Message expects response"; | |
59 } else if (message_header.flags & mojo::kMessageIsResponse) { | |
60 DLOG(INFO) << "Message is response"; | |
61 } | |
62 DLOG(INFO) << "End of message : "; | |
63 } | |
64 | |
35 void WebSocketServer::OnHttpRequest( | 65 void WebSocketServer::OnHttpRequest( |
36 int connection_id, | 66 int connection_id, |
37 const net::HttpServerRequestInfo& info) { | 67 const net::HttpServerRequestInfo& info) { |
38 server_->Send500(connection_id, "websockets protocol only"); | 68 server_->Send500(connection_id, "websockets protocol only"); |
39 } | 69 } |
40 | 70 |
41 void WebSocketServer::OnWebSocketRequest( | 71 void WebSocketServer::OnWebSocketRequest( |
42 int connection_id, | 72 int connection_id, |
43 const net::HttpServerRequestInfo& info) { | 73 const net::HttpServerRequestInfo& info) { |
44 if (connection_id_ != kNotConnected) { | 74 if (connection_id_ != kNotConnected) { |
(...skipping 16 matching lines...) Expand all Loading... | |
61 server_->SendOverWebSocket(connection_id, "\"hi there!\""); | 91 server_->SendOverWebSocket(connection_id, "\"hi there!\""); |
62 } | 92 } |
63 | 93 |
64 void WebSocketServer::OnClose( | 94 void WebSocketServer::OnClose( |
65 int connection_id) { | 95 int connection_id) { |
66 if (connection_id == connection_id_) | 96 if (connection_id == connection_id_) |
67 connection_id_ = kNotConnected; | 97 connection_id_ = kNotConnected; |
68 } | 98 } |
69 | 99 |
70 } // namespace spy | 100 } // namespace spy |
OLD | NEW |