| 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 "tools/android/forwarder2/forwarder.h" | 5 #include "tools/android/forwarder2/forwarder.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 DISALLOW_COPY_AND_ASSIGN(BufferedCopier); | 87 DISALLOW_COPY_AND_ASSIGN(BufferedCopier); |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 } // namespace | 90 } // namespace |
| 91 | 91 |
| 92 Forwarder::Forwarder(scoped_ptr<Socket> socket1, scoped_ptr<Socket> socket2) | 92 Forwarder::Forwarder(scoped_ptr<Socket> socket1, scoped_ptr<Socket> socket2) |
| 93 : socket1_(socket1.Pass()), | 93 : socket1_(socket1.Pass()), |
| 94 socket2_(socket2.Pass()) { | 94 socket2_(socket2.Pass()) { |
| 95 DCHECK(socket1_.get()); | 95 DCHECK(socket1_.get()); |
| 96 DCHECK(socket2_.get()); | 96 DCHECK(socket2_.get()); |
| 97 // The forwarder thread doesn't need to listen to notifications. It can be | |
| 98 // keept alive until either the conenction is broken or the program exit. | |
| 99 socket1_->reset_exit_notifier_fd(); | |
| 100 socket2_->reset_exit_notifier_fd(); | |
| 101 } | 97 } |
| 102 | 98 |
| 103 Forwarder::~Forwarder() { | 99 Forwarder::~Forwarder() {} |
| 104 socket1_->Close(); | |
| 105 socket2_->Close(); | |
| 106 } | |
| 107 | 100 |
| 108 void Forwarder::Run() { | 101 void Forwarder::Run() { |
| 109 const int nfds = Socket::GetHighestFileDescriptor(*socket1_, *socket2_) + 1; | 102 const int nfds = Socket::GetHighestFileDescriptor(*socket1_, *socket2_) + 1; |
| 110 fd_set read_fds; | 103 fd_set read_fds; |
| 111 fd_set write_fds; | 104 fd_set write_fds; |
| 112 | 105 |
| 113 // Copy from socket1 to socket2 | 106 // Copy from socket1 to socket2 |
| 114 BufferedCopier buffer1(socket1_.get(), socket2_.get()); | 107 BufferedCopier buffer1(socket1_.get(), socket2_.get()); |
| 115 | 108 |
| 116 // Copy from socket2 to socket1 | 109 // Copy from socket2 to socket1 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 144 } | 137 } |
| 145 | 138 |
| 146 delete this; | 139 delete this; |
| 147 } | 140 } |
| 148 | 141 |
| 149 void Forwarder::Join() { | 142 void Forwarder::Join() { |
| 150 NOTREACHED() << "Can't Join a Forwarder thread."; | 143 NOTREACHED() << "Can't Join a Forwarder thread."; |
| 151 } | 144 } |
| 152 | 145 |
| 153 } // namespace forwarder | 146 } // namespace forwarder |
| OLD | NEW |