Bug 1782337 - Remove unused LineWatcher. r=ipc-reviewers,jld

Differential Revision: https://phabricator.services.mozilla.com/D153304
This commit is contained in:
Chris Peterson 2022-08-02 04:58:07 +00:00
Родитель c82e77a6da
Коммит c477304353
3 изменённых файлов: 0 добавлений и 76 удалений

Просмотреть файл

@ -531,7 +531,6 @@ class MessageLoopForIO : public MessageLoop {
typedef base::MessagePumpLibevent::Watcher Watcher;
typedef base::MessagePumpLibevent::FileDescriptorWatcher
FileDescriptorWatcher;
typedef base::LineWatcher LineWatcher;
enum Mode {
WATCH_READ = base::MessagePumpLibevent::WATCH_READ,

Просмотреть файл

@ -16,7 +16,6 @@
#include "base/logging.h"
#include "base/scoped_nsautorelease_pool.h"
#include "base/time.h"
#include "nsDependentSubstring.h"
#include "event.h"
#include "mozilla/ProfilerLabels.h"
#include "mozilla/ProfilerThreadSleep.h"
@ -408,46 +407,4 @@ void MessagePumpLibevent::ScheduleDelayedWork(
delayed_work_time_ = delayed_work_time;
}
void LineWatcher::OnFileCanReadWithoutBlocking(int aFd) {
ssize_t length = 0;
while (true) {
length = read(aFd, mReceiveBuffer.get(), mBufferSize - mReceivedIndex);
DCHECK(length <= ssize_t(mBufferSize - mReceivedIndex));
if (length <= 0) {
if (length < 0) {
if (errno == EINTR) {
continue; // retry system call when interrupted
}
if (errno == EAGAIN || errno == EWOULDBLOCK) {
return; // no data available: return and re-poll
}
DLOG(ERROR) << "Can't read from fd, error " << errno;
} else {
DLOG(ERROR) << "End of file";
}
// At this point, assume that we can't actually access
// the socket anymore, and indicate an error.
OnError();
mReceivedIndex = 0;
return;
}
while (length-- > 0) {
DCHECK(mReceivedIndex < mBufferSize);
if (mReceiveBuffer[mReceivedIndex] == mTerminator) {
nsDependentCSubstring message(mReceiveBuffer.get(), mReceivedIndex);
OnLineRead(aFd, message);
if (length > 0) {
DCHECK(mReceivedIndex < (mBufferSize - 1));
memmove(&mReceiveBuffer[0], &mReceiveBuffer[mReceivedIndex + 1],
length);
}
mReceivedIndex = 0;
} else {
mReceivedIndex++;
}
}
}
}
} // namespace base

Просмотреть файл

@ -9,8 +9,6 @@
#include "base/message_pump.h"
#include "base/time.h"
#include "mozilla/UniquePtr.h"
#include "nsStringFwd.h"
// Declare structs we need from libevent.h rather than including it
struct event_base;
@ -178,36 +176,6 @@ class MessagePumpLibevent : public MessagePump {
DISALLOW_COPY_AND_ASSIGN(MessagePumpLibevent);
};
/**
* LineWatcher overrides OnFileCanReadWithoutBlocking. It separates the read
* data by mTerminator and passes each line to OnLineRead.
*/
class LineWatcher : public MessagePumpLibevent::Watcher {
public:
LineWatcher(char aTerminator, int aBufferSize)
: mReceivedIndex(0), mBufferSize(aBufferSize), mTerminator(aTerminator) {
mReceiveBuffer = mozilla::MakeUnique<char[]>(mBufferSize);
}
~LineWatcher() {}
protected:
/**
* OnError will be called when |read| returns error. Derived class should
* implement this function to handle error cases when needed.
*/
virtual void OnError() {}
virtual void OnLineRead(int aFd, nsDependentCSubstring& aMessage) = 0;
virtual void OnFileCanWriteWithoutBlocking(int /* aFd */) override {}
private:
void OnFileCanReadWithoutBlocking(int aFd) final;
mozilla::UniquePtr<char[]> mReceiveBuffer;
int mReceivedIndex;
int mBufferSize;
char mTerminator;
};
} // namespace base
#endif // BASE_MESSAGE_PUMP_LIBEVENT_H_