Delete StreamInterface::ReadLine.
Refactor only remaining user, IsDefaultRoute (helper function called from BasicNetworkManager::IsIgnoredNetwork) to use a FILE* and fgets instead. Bug: webrtc:6424 Change-Id: I57652f664b9a6965c19575c1b5d7f7de24f2ed44 Reviewed-on: https://webrtc-review.googlesource.com/c/108089 Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Commit-Queue: Niels Moller <nisse@webrtc.org> Cr-Commit-Position: refs/heads/master@{#25433}
This commit is contained in:
@ -38,7 +38,6 @@
|
|||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
#include "rtc_base/networkmonitor.h"
|
#include "rtc_base/networkmonitor.h"
|
||||||
#include "rtc_base/socket.h" // includes something that makes windows happy
|
#include "rtc_base/socket.h" // includes something that makes windows happy
|
||||||
#include "rtc_base/stream.h"
|
|
||||||
#include "rtc_base/stringencode.h"
|
#include "rtc_base/stringencode.h"
|
||||||
#include "rtc_base/strings/string_builder.h"
|
#include "rtc_base/strings/string_builder.h"
|
||||||
#include "rtc_base/stringutils.h"
|
#include "rtc_base/stringutils.h"
|
||||||
@ -775,26 +774,28 @@ bool BasicNetworkManager::CreateNetworks(bool include_ignored,
|
|||||||
|
|
||||||
#if defined(WEBRTC_LINUX)
|
#if defined(WEBRTC_LINUX)
|
||||||
bool IsDefaultRoute(const std::string& network_name) {
|
bool IsDefaultRoute(const std::string& network_name) {
|
||||||
FileStream fs;
|
FILE* f = fopen("/proc/net/route", "r");
|
||||||
if (!fs.Open("/proc/net/route", "r", nullptr)) {
|
if (!f) {
|
||||||
RTC_LOG(LS_WARNING)
|
RTC_LOG(LS_WARNING)
|
||||||
<< "Couldn't read /proc/net/route, skipping default "
|
<< "Couldn't read /proc/net/route, skipping default "
|
||||||
<< "route check (assuming everything is a default route).";
|
<< "route check (assuming everything is a default route).";
|
||||||
return true;
|
return true;
|
||||||
} else {
|
}
|
||||||
std::string line;
|
bool is_default_route = false;
|
||||||
while (fs.ReadLine(&line) == SR_SUCCESS) {
|
char line[500];
|
||||||
char iface_name[256];
|
while (fgets(line, sizeof(line), f)) {
|
||||||
unsigned int iface_ip, iface_gw, iface_mask, iface_flags;
|
char iface_name[256];
|
||||||
if (sscanf(line.c_str(), "%255s %8X %8X %4X %*d %*u %*d %8X", iface_name,
|
unsigned int iface_ip, iface_gw, iface_mask, iface_flags;
|
||||||
&iface_ip, &iface_gw, &iface_flags, &iface_mask) == 5 &&
|
if (sscanf(line, "%255s %8X %8X %4X %*d %*u %*d %8X", iface_name, &iface_ip,
|
||||||
network_name == iface_name && iface_mask == 0 &&
|
&iface_gw, &iface_flags, &iface_mask) == 5 &&
|
||||||
(iface_flags & (RTF_UP | RTF_HOST)) == RTF_UP) {
|
network_name == iface_name && iface_mask == 0 &&
|
||||||
return true;
|
(iface_flags & (RTF_UP | RTF_HOST)) == RTF_UP) {
|
||||||
}
|
is_default_route = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
fclose(f);
|
||||||
|
return is_default_route;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -69,26 +69,6 @@ StreamResult StreamInterface::ReadAll(void* buffer,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamResult StreamInterface::ReadLine(std::string* line) {
|
|
||||||
line->clear();
|
|
||||||
StreamResult result = SR_SUCCESS;
|
|
||||||
while (true) {
|
|
||||||
char ch;
|
|
||||||
result = Read(&ch, sizeof(ch), nullptr, nullptr);
|
|
||||||
if (result != SR_SUCCESS) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (ch == '\n') {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
line->push_back(ch);
|
|
||||||
}
|
|
||||||
if (!line->empty()) { // give back the line we've collected so far with
|
|
||||||
result = SR_SUCCESS; // a success code. Otherwise return the last code
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void StreamInterface::PostEvent(Thread* t, int events, int err) {
|
void StreamInterface::PostEvent(Thread* t, int events, int err) {
|
||||||
t->Post(RTC_FROM_HERE, this, MSG_POST_EVENT,
|
t->Post(RTC_FROM_HERE, this, MSG_POST_EVENT,
|
||||||
new StreamEventData(events, err));
|
new StreamEventData(events, err));
|
||||||
|
@ -213,12 +213,6 @@ class StreamInterface : public MessageHandler {
|
|||||||
size_t* read,
|
size_t* read,
|
||||||
int* error);
|
int* error);
|
||||||
|
|
||||||
// ReadLine is a helper function which repeatedly calls Read until it hits
|
|
||||||
// the end-of-line character, or something other than SR_SUCCESS.
|
|
||||||
// TODO: this is too inefficient to keep here. Break this out into a buffered
|
|
||||||
// readline object or adapter
|
|
||||||
StreamResult ReadLine(std::string* line);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
StreamInterface();
|
StreamInterface();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user