OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/web_socket_proxy.h" | 5 #include "chrome/browser/chromeos/web_socket_proxy.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 #include <string.h> | 9 #include <string.h> |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "base/base64.h" | 25 #include "base/base64.h" |
26 #include "base/basictypes.h" | 26 #include "base/basictypes.h" |
27 #include "base/bind.h" | 27 #include "base/bind.h" |
28 #include "base/bind_helpers.h" | 28 #include "base/bind_helpers.h" |
29 #include "base/lazy_instance.h" | 29 #include "base/lazy_instance.h" |
30 #include "base/logging.h" | 30 #include "base/logging.h" |
31 #include "base/memory/ref_counted.h" | 31 #include "base/memory/ref_counted.h" |
32 #include "base/memory/scoped_ptr.h" | 32 #include "base/memory/scoped_ptr.h" |
33 #include "base/memory/weak_ptr.h" | 33 #include "base/memory/weak_ptr.h" |
34 #include "base/message_loop.h" | 34 #include "base/message_loop.h" |
| 35 #include "base/process_util.h" |
35 #include "base/sequenced_task_runner_helpers.h" | 36 #include "base/sequenced_task_runner_helpers.h" |
36 #include "base/sha1.h" | 37 #include "base/sha1.h" |
37 #include "base/stl_util.h" | 38 #include "base/stl_util.h" |
38 #include "base/string_number_conversions.h" | 39 #include "base/string_number_conversions.h" |
39 #include "base/string_util.h" | 40 #include "base/string_util.h" |
40 #include "base/sys_byteorder.h" | 41 #include "base/sys_byteorder.h" |
41 #include "chrome/browser/chromeos/web_socket_proxy_helper.h" | 42 #include "chrome/browser/chromeos/web_socket_proxy_helper.h" |
42 #include "chrome/browser/internal_auth.h" | 43 #include "chrome/browser/internal_auth.h" |
43 #include "chrome/common/chrome_notification_types.h" | 44 #include "chrome/common/chrome_notification_types.h" |
44 #include "content/public/browser/browser_thread.h" | 45 #include "content/public/browser/browser_thread.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 // Fixed-size (one-byte) messages communicated via control pipe. | 95 // Fixed-size (one-byte) messages communicated via control pipe. |
95 const char kControlMessageShutdown[] = { '.' }; | 96 const char kControlMessageShutdown[] = { '.' }; |
96 const char kControlMessageNetworkChange[] = { ':' }; | 97 const char kControlMessageNetworkChange[] = { ':' }; |
97 | 98 |
98 // Returns true on success. | 99 // Returns true on success. |
99 bool SetNonBlock(int fd) { | 100 bool SetNonBlock(int fd) { |
100 int flags = fcntl(fd, F_GETFL, 0); | 101 int flags = fcntl(fd, F_GETFL, 0); |
101 return flags >= 0 && fcntl(fd, F_SETFL, flags | O_NONBLOCK) == 0; | 102 return flags >= 0 && fcntl(fd, F_SETFL, flags | O_NONBLOCK) == 0; |
102 } | 103 } |
103 | 104 |
104 // Returns true on success. | |
105 bool IgnoreSigPipe() { | |
106 struct sigaction sa; | |
107 sa.sa_handler = SIG_IGN; | |
108 sa.sa_flags = 0; | |
109 if (sigemptyset(&sa.sa_mask) || sigaction(SIGPIPE, &sa, 0)) { | |
110 LOG(ERROR) << "WebSocketProxy: Failed to disable sigpipe"; | |
111 return false; | |
112 } | |
113 return true; | |
114 } | |
115 | |
116 uint64 ReadNetworkInteger(uint8* buf, int num_bytes) { | 105 uint64 ReadNetworkInteger(uint8* buf, int num_bytes) { |
117 uint64 rv = 0; | 106 uint64 rv = 0; |
118 DCHECK_GE(num_bytes, 0); | 107 DCHECK_GE(num_bytes, 0); |
119 DCHECK_LE(num_bytes, 8); | 108 DCHECK_LE(num_bytes, 8); |
120 while (num_bytes--) { | 109 while (num_bytes--) { |
121 rv <<= 8; | 110 rv <<= 8; |
122 rv += *buf++; | 111 rv += *buf++; |
123 } | 112 } |
124 return rv; | 113 return rv; |
125 } | 114 } |
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
914 event_set(control_event_.get(), control_descriptor_[0], EV_READ | EV_PERSIST, | 903 event_set(control_event_.get(), control_descriptor_[0], EV_READ | EV_PERSIST, |
915 &OnControlRequest, this); | 904 &OnControlRequest, this); |
916 event_base_set(evbase_, control_event_.get()); | 905 event_base_set(evbase_, control_event_.get()); |
917 if (event_add(control_event_.get(), NULL)) { | 906 if (event_add(control_event_.get(), NULL)) { |
918 LOG(ERROR) << "WebSocketProxy: Failed to add control event"; | 907 LOG(ERROR) << "WebSocketProxy: Failed to add control event"; |
919 return; | 908 return; |
920 } | 909 } |
921 | 910 |
922 if (evdns_init()) | 911 if (evdns_init()) |
923 LOG(WARNING) << "WebSocketProxy: Failed to initialize evDNS"; | 912 LOG(WARNING) << "WebSocketProxy: Failed to initialize evDNS"; |
924 if (!IgnoreSigPipe()) { | 913 if (!base::IgnoreSigPipe()) { |
925 LOG(ERROR) << "WebSocketProxy: Failed to ignore SIGPIPE"; | 914 LOG(ERROR) << "WebSocketProxy: Failed to ignore SIGPIPE"; |
926 return; | 915 return; |
927 } | 916 } |
928 | 917 |
929 memset(&addr, 0, sizeof(addr)); | 918 memset(&addr, 0, sizeof(addr)); |
930 socklen_t addr_len = sizeof(addr); | 919 socklen_t addr_len = sizeof(addr); |
931 if (getsockname( | 920 if (getsockname( |
932 listening_sock_, reinterpret_cast<struct sockaddr*>(&addr), &addr_len)) { | 921 listening_sock_, reinterpret_cast<struct sockaddr*>(&addr), &addr_len)) { |
933 LOG(ERROR) << "Failed to determine listening port"; | 922 LOG(ERROR) << "Failed to determine listening port"; |
934 return; | 923 return; |
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1901 | 1890 |
1902 void WebSocketProxy::Shutdown() { | 1891 void WebSocketProxy::Shutdown() { |
1903 static_cast<Serv*>(impl_)->Shutdown(); | 1892 static_cast<Serv*>(impl_)->Shutdown(); |
1904 } | 1893 } |
1905 | 1894 |
1906 void WebSocketProxy::OnNetworkChange() { | 1895 void WebSocketProxy::OnNetworkChange() { |
1907 static_cast<Serv*>(impl_)->OnNetworkChange(); | 1896 static_cast<Serv*>(impl_)->OnNetworkChange(); |
1908 } | 1897 } |
1909 | 1898 |
1910 } // namespace chromeos | 1899 } // namespace chromeos |
OLD | NEW |