Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Use posix API in module net and base #3966

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ if (is_apple) {

# Determines whether libevent should be dep.
dep_libevent = !is_fuchsia && !is_win && !is_mac && !is_nacl
&& !use_cobalt_customizations
&& (!use_cobalt_customizations || sb_api_version >= 16)

# Determines whether message_pump_libevent should be used.
use_libevent = dep_libevent && !is_ios
Expand Down Expand Up @@ -980,6 +980,26 @@ component("base") {
"message_loop/message_pump_io_starboard.h",
"message_loop/message_pump_ui_starboard.cc",
"message_loop/message_pump_ui_starboard.h",

# added for posix - by zhangmax


"synchronization/condition_variable_posix.cc",
"time/time_conversion_posix.cc",

"files/file_posix.cc",
"files/file_util_posix.cc",
"files/file_descriptor_watcher_posix.cc",
"files/file_descriptor_watcher_posix.h",
"files/file_enumerator_posix.cc",

"memory/page_size_posix.cc",

"message_loop/watchable_io_message_pump_posix.cc",
"message_loop/watchable_io_message_pump_posix.h",

# end of adding - zhangmax

"process/launch.cc",
"process/launch.h",
"process/launch_starboard.cc",
Expand Down Expand Up @@ -2345,7 +2365,7 @@ component("base") {
]
}

if (!use_cobalt_customizations && is_posix && !is_apple) {
if (use_libevent) {
sources += [
"strings/sys_string_conversions_posix.cc",
"synchronization/waitable_event_posix.cc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
#include <jni.h>
#endif

#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16
#include <sys/time.h>
#include <unistd.h>
#endif
Expand Down Expand Up @@ -126,14 +126,13 @@ class PlatformThreadHandle;
class PA_COMPONENT_EXPORT(PARTITION_ALLOC) TimeDelta {
public:
constexpr TimeDelta() = default;

#if BUILDFLAG(IS_WIN)
static TimeDelta FromQPCValue(LONGLONG qpc_value);
// TODO(crbug.com/989694): Avoid base::TimeDelta factory functions
// based on absolute time
static TimeDelta FromFileTime(FILETIME ft);
static TimeDelta FromWinrtDateTime(ABI::Windows::Foundation::DateTime dt);
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16
static TimeDelta FromTimeSpec(const timespec& ts);
#endif
#if BUILDFLAG(IS_FUCHSIA)
Expand Down Expand Up @@ -198,7 +197,7 @@ class PA_COMPONENT_EXPORT(PARTITION_ALLOC) TimeDelta {
constexpr bool is_min() const { return *this == Min(); }
constexpr bool is_inf() const { return is_min() || is_max(); }

#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16
struct timespec ToTimeSpec() const;
#endif
#if BUILDFLAG(IS_FUCHSIA)
Expand Down Expand Up @@ -586,7 +585,7 @@ class PA_COMPONENT_EXPORT(PARTITION_ALLOC) Time
static Time FromDoubleT(double dt);
double ToDoubleT() const;

#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16
// Converts the timespec structure to time. MacOS X 10.8.3 (and tentatively,
// earlier versions) will have the |ts|'s tv_nsec component zeroed out,
// having a 1 second resolution, which agrees with
Expand All @@ -612,7 +611,7 @@ class PA_COMPONENT_EXPORT(PARTITION_ALLOC) Time
static Time FromJavaTime(int64_t ms_since_epoch);
int64_t ToJavaTime() const;

#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16
static Time FromTimeVal(struct timeval t);
struct timeval ToTimeVal() const;
#endif
Expand Down
12 changes: 6 additions & 6 deletions base/check.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class DCheckLogMessage : public LogMessage {
const base::Location location_;
};

#if defined(STARBOARD)
#if defined(STARBOARD) && SB_API_VERSION <= 15
class DCheckStarboardErrorLogMessage : public StarboardErrorLogMessage {
public:
DCheckStarboardErrorLogMessage(const base::Location& location,
Expand Down Expand Up @@ -123,7 +123,7 @@ class DCheckWin32ErrorLogMessage : public Win32ErrorLogMessage {
private:
const base::Location location_;
};
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16
class DCheckErrnoLogMessage : public ErrnoLogMessage {
public:
DCheckErrnoLogMessage(const base::Location& location,
Expand Down Expand Up @@ -166,13 +166,13 @@ CheckError CheckError::PCheck(const char* file,
int line,
const char* condition) {
SystemErrorCode err_code = logging::GetLastSystemErrorCode();
#if defined(STARBOARD)
#if defined(STARBOARD) && SB_API_VERSION <= 15
auto* const log_message =
new StarboardErrorLogMessage(file, line, LOGGING_FATAL, err_code);
#elif BUILDFLAG(IS_WIN)
auto* const log_message =
new Win32ErrorLogMessage(file, line, LOGGING_FATAL, err_code);
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16
auto* const log_message =
new ErrnoLogMessage(file, line, LOGGING_FATAL, err_code);
#endif
Expand All @@ -187,13 +187,13 @@ CheckError CheckError::PCheck(const char* file, int line) {
CheckError CheckError::DPCheck(const char* condition,
const base::Location& location) {
SystemErrorCode err_code = logging::GetLastSystemErrorCode();
#if defined(STARBOARD)
#if defined(STARBOARD) && SB_API_VERSION <= 15
auto* const log_message =
new DCheckStarboardErrorLogMessage(location, LOGGING_DCHECK, err_code);
#elif BUILDFLAG(IS_WIN)
auto* const log_message =
new DCheckWin32ErrorLogMessage(location, LOGGING_DCHECK, err_code);
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16
auto* const log_message =
new DCheckErrnoLogMessage(location, LOGGING_DCHECK, err_code);
#endif
Expand Down
11 changes: 7 additions & 4 deletions base/files/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ struct stat;

namespace base {

#if defined(STARBOARD)
#if defined(STARBOARD) && SB_API_VERSION <= 15
using stat_wrapper_t = struct ::stat;
#else
using stat_wrapper_t = struct stat;
#ifndef ftruncate64
#define ftruncate64 ftruncate
#endif
#endif

// Thin wrapper around an OS-level file.
Expand Down Expand Up @@ -357,11 +360,11 @@ class BASE_EXPORT File {
bool DeleteOnClose(bool delete_on_close);
#endif

#if defined(STARBOARD)
#if defined(STARBOARD) && SB_API_VERSION <= 15
static Error OSErrorToFileError(SbSystemError sb_system_error);
#elif BUILDFLAG(IS_WIN)
static Error OSErrorToFileError(DWORD last_error);
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16
static Error OSErrorToFileError(int saved_errno);
#endif

Expand All @@ -378,7 +381,7 @@ class BASE_EXPORT File {
// Wrapper for stat() or stat64().
static int Stat(const char* path, stat_wrapper_t* sb);
static int Fstat(int fd, stat_wrapper_t* sb);
# if !defined(STARBOARD)
# if !defined(STARBOARD) || (defined(STARBOARD) && SB_API_VERSION >= 16)
// Starboard does not support lstat yet.
static int Lstat(const char* path, stat_wrapper_t* sb);
#endif
Expand Down
4 changes: 4 additions & 0 deletions base/files/file_descriptor_watcher_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

namespace base {

#if SB_API_VERSION >= 16

namespace {

// Per-thread FileDescriptorWatcher registration.
Expand Down Expand Up @@ -272,4 +274,6 @@ void FileDescriptorWatcher::AssertAllowed() {
}
#endif

#endif // SB_API_VERSION >= 16

} // namespace base
12 changes: 6 additions & 6 deletions base/files/file_enumerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
#include "base/time/time.h"
#include "build/build_config.h"

#if defined(STARBOARD)
#if defined(STARBOARD) && SB_API_VERSION <= 15
#include <sys/stat.h>
#include <unistd.h>
#include "starboard/file.h"
#elif BUILDFLAG(IS_WIN)
#include "base/win/windows_types.h"
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16
#include <sys/stat.h>
#include <unistd.h>
#include <unordered_set>
Expand Down Expand Up @@ -96,8 +96,8 @@ class BASE_EXPORT FileEnumerator {
// called.
NAMES_ONLY = 1 << 3,

#if defined(STARBOARD)
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#if defined(STARBOARD) && SB_API_VERSION <= 15
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16
SHOW_SYM_LINKS = 1 << 4,
#endif
};
Expand Down Expand Up @@ -193,7 +193,7 @@ class BASE_EXPORT FileEnumerator {

bool IsPatternMatched(const FilePath& src) const;

#if defined(STARBOARD)
#if defined(STARBOARD) && SB_API_VERSION <= 15
std::vector<FileInfo> ReadDirectory(const FilePath& source);

// The files in the current directory
Expand All @@ -210,7 +210,7 @@ class BASE_EXPORT FileEnumerator {
bool has_find_data_ = false;
CHROME_WIN32_FIND_DATA find_data_;
HANDLE find_handle_ = INVALID_HANDLE_VALUE;
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16
// The files in the current directory
std::vector<FileInfo> directory_entries_;

Expand Down
5 changes: 5 additions & 0 deletions base/files/file_enumerator_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#include "build/build_config.h"

namespace base {

#if SB_API_VERSION >= 16

namespace {

void GetStat(const FilePath& path, bool show_links, stat_wrapper_t* st) {
Expand Down Expand Up @@ -258,4 +261,6 @@ bool FileEnumerator::IsPatternMatched(const FilePath& path) const {
!fnmatch(pattern_.c_str(), path.value().c_str(), FNM_NOESCAPE);
}

#endif // SB_API_VERSION >= 16

} // namespace base
4 changes: 4 additions & 0 deletions base/files/file_enumerator_starboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

namespace base {

#if SB_API_VERSION <= 15

// FileEnumerator::FileInfo ----------------------------------------------------

FileEnumerator::FileInfo::FileInfo() {
Expand Down Expand Up @@ -225,4 +227,6 @@ FileEnumerator::FileInfo FileEnumerator::GetInfo() const {
return directory_entries_[current_directory_entry_];
}

#endif // SB_API_VERSION <= 15

} // namespace base
4 changes: 4 additions & 0 deletions base/files/file_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ static_assert(sizeof(base::stat_wrapper_t::st_size) >= 8);

namespace base {

#if SB_API_VERSION >= 16

// Make sure our Whence mappings match the system headers.
static_assert(File::FROM_BEGIN == SEEK_SET && File::FROM_CURRENT == SEEK_CUR &&
File::FROM_END == SEEK_END,
Expand Down Expand Up @@ -615,4 +617,6 @@ int File::Lstat(const char* path, stat_wrapper_t* sb) {
return lstat(path, sb);
}

#endif // SB_API_VERSION >= 16

} // namespace base
4 changes: 4 additions & 0 deletions base/files/file_starboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

namespace base {

#if SB_API_VERSION <= 15

namespace {
SbFileError g_sb_file_error = kSbFileOk;
} // namespace
Expand Down Expand Up @@ -503,4 +505,6 @@ File File::Duplicate() const {
return File();
}

#endif // SB_API_VERSION <= 15

} // namespace base
Loading
Loading