| Index: tools/android/forwarder2/forwarder.h
|
| diff --git a/tools/android/forwarder2/forwarder.h b/tools/android/forwarder2/forwarder.h
|
| index 5ad1b1a38ec846cdb1e8604f13f72ab11c7a504f..0be86fccf3c68ecd67db12b59c1a0abd2e22ebde 100644
|
| --- a/tools/android/forwarder2/forwarder.h
|
| +++ b/tools/android/forwarder2/forwarder.h
|
| @@ -5,48 +5,41 @@
|
| #ifndef TOOLS_ANDROID_FORWARDER2_FORWARDER_H_
|
| #define TOOLS_ANDROID_FORWARDER2_FORWARDER_H_
|
|
|
| -#include "base/callback.h"
|
| +#include <sys/select.h>
|
| +
|
| #include "base/memory/scoped_ptr.h"
|
| -#include "base/threading/thread.h"
|
| -#include "tools/android/forwarder2/self_deleter_helper.h"
|
| +#include "base/threading/thread_checker.h"
|
|
|
| namespace forwarder2 {
|
|
|
| -class PipeNotifier;
|
| class Socket;
|
|
|
| -// Internal class that wraps a helper thread to forward traffic between
|
| -// |socket1| and |socket2|. After creating a new instance, call its Start()
|
| -// method to launch operations. Thread stops automatically if one of the socket
|
| -// disconnects, but ensures that all buffered writes to the other, still alive,
|
| -// socket, are written first. When this happens, the instance will delete itself
|
| -// automatically.
|
| -// Note that the instance will always be destroyed on the same thread that
|
| -// created it.
|
| +// Internal class that forwards traffic between |socket1| and |socket2|. Note
|
| +// that this class is not thread-safe.
|
| class Forwarder {
|
| public:
|
| - // Callback used on error invoked by the Forwarder to self-delete.
|
| - typedef base::Callback<void (scoped_ptr<Forwarder>)> ErrorCallback;
|
| -
|
| - Forwarder(scoped_ptr<Socket> socket1,
|
| - scoped_ptr<Socket> socket2,
|
| - PipeNotifier* deletion_notifier,
|
| - const ErrorCallback& error_callback);
|
| + Forwarder(scoped_ptr<Socket> socket1, scoped_ptr<Socket> socket2);
|
|
|
| ~Forwarder();
|
|
|
| - void Start();
|
| + void RegisterFDs(fd_set* read_fds, fd_set* write_fds, int* max_fd);
|
|
|
| - private:
|
| - void ThreadHandler();
|
| + void ProcessEvents(const fd_set& read_fds, const fd_set& write_fds);
|
|
|
| - void OnThreadHandlerCompletion(const ErrorCallback& error_callback);
|
| + bool IsClosed() const;
|
|
|
| - SelfDeleterHelper<Forwarder> self_deleter_helper_;
|
| - PipeNotifier* const deletion_notifier_;
|
| - scoped_ptr<Socket> socket1_;
|
| - scoped_ptr<Socket> socket2_;
|
| - base::Thread thread_;
|
| + void Shutdown();
|
| +
|
| + private:
|
| + class BufferedCopier;
|
| +
|
| + base::ThreadChecker thread_checker_;
|
| + const scoped_ptr<Socket> socket1_;
|
| + const scoped_ptr<Socket> socket2_;
|
| + // Copies data from socket1 to socket2.
|
| + const scoped_ptr<BufferedCopier> buffer1_;
|
| + // Copies data from socket2 to socket1.
|
| + const scoped_ptr<BufferedCopier> buffer2_;
|
| };
|
|
|
| } // namespace forwarder2
|
|
|