Commit 715d972e authored by pliard@chromium.org's avatar pliard@chromium.org

Revert 235213 "android: forwader2: Simplify Forwarder implementa..."

> android: forwader2: Simplify Forwarder implementation.
> 
> This patch does several things to the Forwarder class used in the 'forwarder2'
> tool:
> 
> - Add a Stop() method to gently ask the forwarder to shut-down. This stops
>   the forwarder from listening from incoming data, but keeps it running
>   until it could flush its buffer properly, to avoid packet loss.
> 
> - Simplify / refactor the buffer management code inside a Forwarder
>   instance, to make the state of its buffer, and their transitions,
>   more explict.
> 
> BUG=313809
> R=pliard@chromium.org
> 
> Review URL: https://codereview.chromium.org/61793013

TBR=digit@chromium.org

Review URL: https://codereview.chromium.org/70193013

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@235729 0039d316-1c4b-4281-b951-d872f2087c98
parent 3e00d6a3
This diff is collapsed.
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define TOOLS_ANDROID_FORWARDER2_FORWARDER_H_ #define TOOLS_ANDROID_FORWARDER2_FORWARDER_H_
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/threading/thread.h"
namespace forwarder2 { namespace forwarder2 {
......
...@@ -287,6 +287,19 @@ int Socket::GetPort() { ...@@ -287,6 +287,19 @@ int Socket::GetPort() {
return port_; return port_;
} }
bool Socket::IsFdInSet(const fd_set& fds) const {
if (IsClosed())
return false;
return FD_ISSET(socket_, &fds);
}
bool Socket::AddFdToSet(fd_set* fds) const {
if (IsClosed())
return false;
FD_SET(socket_, fds);
return true;
}
int Socket::ReadNumBytes(void* buffer, size_t num_bytes) { int Socket::ReadNumBytes(void* buffer, size_t num_bytes) {
int bytes_read = 0; int bytes_read = 0;
int ret = 1; int ret = 1;
...@@ -428,6 +441,11 @@ bool Socket::WaitForEvent(EventType type, int timeout_secs) { ...@@ -428,6 +441,11 @@ bool Socket::WaitForEvent(EventType type, int timeout_secs) {
return !event_was_fired; return !event_was_fired;
} }
// static
int Socket::GetHighestFileDescriptor(const Socket& s1, const Socket& s2) {
return std::max(s1.socket_, s2.socket_);
}
// static // static
pid_t Socket::GetUnixDomainSocketProcessOwner(const std::string& path) { pid_t Socket::GetUnixDomainSocketProcessOwner(const std::string& path) {
Socket socket; Socket socket;
......
...@@ -37,13 +37,14 @@ class Socket { ...@@ -37,13 +37,14 @@ class Socket {
void Close(); void Close();
bool IsClosed() const { return socket_ < 0; } bool IsClosed() const { return socket_ < 0; }
int fd() const { return socket_; }
bool Accept(Socket* new_socket); bool Accept(Socket* new_socket);
// Returns the port allocated to this socket or zero on error. // Returns the port allocated to this socket or zero on error.
int GetPort(); int GetPort();
bool IsFdInSet(const fd_set& fds) const;
bool AddFdToSet(fd_set* fds) const;
// Just a wrapper around unix read() function. // Just a wrapper around unix read() function.
// Reads up to buffer_size, but may read less then buffer_size. // Reads up to buffer_size, but may read less then buffer_size.
// Returns the number of bytes read. // Returns the number of bytes read.
...@@ -88,6 +89,8 @@ class Socket { ...@@ -88,6 +89,8 @@ class Socket {
bool DidReceiveEvent() const; bool DidReceiveEvent() const;
static int GetHighestFileDescriptor(const Socket& s1, const Socket& s2);
static pid_t GetUnixDomainSocketProcessOwner(const std::string& path); static pid_t GetUnixDomainSocketProcessOwner(const std::string& path);
private: private:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment