diff --git a/rtc_base/network.cc b/rtc_base/network.cc index 67888ede83..2dce20a243 100644 --- a/rtc_base/network.cc +++ b/rtc_base/network.cc @@ -38,7 +38,6 @@ #include "rtc_base/logging.h" #include "rtc_base/networkmonitor.h" #include "rtc_base/socket.h" // includes something that makes windows happy -#include "rtc_base/stream.h" #include "rtc_base/stringencode.h" #include "rtc_base/strings/string_builder.h" #include "rtc_base/stringutils.h" @@ -775,26 +774,28 @@ bool BasicNetworkManager::CreateNetworks(bool include_ignored, #if defined(WEBRTC_LINUX) bool IsDefaultRoute(const std::string& network_name) { - FileStream fs; - if (!fs.Open("/proc/net/route", "r", nullptr)) { + FILE* f = fopen("/proc/net/route", "r"); + if (!f) { RTC_LOG(LS_WARNING) << "Couldn't read /proc/net/route, skipping default " << "route check (assuming everything is a default route)."; return true; - } else { - std::string line; - while (fs.ReadLine(&line) == SR_SUCCESS) { - char iface_name[256]; - unsigned int iface_ip, iface_gw, iface_mask, iface_flags; - if (sscanf(line.c_str(), "%255s %8X %8X %4X %*d %*u %*d %8X", iface_name, - &iface_ip, &iface_gw, &iface_flags, &iface_mask) == 5 && - network_name == iface_name && iface_mask == 0 && - (iface_flags & (RTF_UP | RTF_HOST)) == RTF_UP) { - return true; - } + } + bool is_default_route = false; + char line[500]; + while (fgets(line, sizeof(line), f)) { + char iface_name[256]; + unsigned int iface_ip, iface_gw, iface_mask, iface_flags; + if (sscanf(line, "%255s %8X %8X %4X %*d %*u %*d %8X", iface_name, &iface_ip, + &iface_gw, &iface_flags, &iface_mask) == 5 && + network_name == iface_name && iface_mask == 0 && + (iface_flags & (RTF_UP | RTF_HOST)) == RTF_UP) { + is_default_route = true; + break; } } - return false; + fclose(f); + return is_default_route; } #endif diff --git a/rtc_base/stream.cc b/rtc_base/stream.cc index 73300a1c66..e66fcb2ca7 100644 --- a/rtc_base/stream.cc +++ b/rtc_base/stream.cc @@ -69,26 +69,6 @@ StreamResult StreamInterface::ReadAll(void* buffer, 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) { t->Post(RTC_FROM_HERE, this, MSG_POST_EVENT, new StreamEventData(events, err)); diff --git a/rtc_base/stream.h b/rtc_base/stream.h index 6195918cef..da6873222d 100644 --- a/rtc_base/stream.h +++ b/rtc_base/stream.h @@ -213,12 +213,6 @@ class StreamInterface : public MessageHandler { size_t* read, 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: StreamInterface();