Merge remote-tracking branch 'td/master'
This commit is contained in:
commit
c037048ec3
@ -3,17 +3,20 @@ Language: Cpp
|
|||||||
# BasedOnStyle: Google
|
# BasedOnStyle: Google
|
||||||
AccessModifierOffset: -1
|
AccessModifierOffset: -1
|
||||||
AlignAfterOpenBracket: Align
|
AlignAfterOpenBracket: Align
|
||||||
AlignConsecutiveMacros: false
|
AlignArrayOfStructures: None
|
||||||
AlignConsecutiveAssignments: false
|
AlignConsecutiveMacros: None
|
||||||
AlignConsecutiveDeclarations: false
|
AlignConsecutiveAssignments: None
|
||||||
|
AlignConsecutiveBitFields: None
|
||||||
|
AlignConsecutiveDeclarations: None
|
||||||
AlignEscapedNewlines: Left
|
AlignEscapedNewlines: Left
|
||||||
AlignOperands: true
|
AlignOperands: Align
|
||||||
AlignTrailingComments: true
|
AlignTrailingComments: true
|
||||||
AllowAllArgumentsOnNextLine: true
|
AllowAllArgumentsOnNextLine: true
|
||||||
AllowAllConstructorInitializersOnNextLine: true
|
AllowAllConstructorInitializersOnNextLine: true
|
||||||
AllowAllParametersOfDeclarationOnNextLine: true
|
AllowAllParametersOfDeclarationOnNextLine: true
|
||||||
AllowShortBlocksOnASingleLine: Never
|
AllowShortBlocksOnASingleLine: Never
|
||||||
AllowShortCaseLabelsOnASingleLine: false
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
AllowShortEnumsOnASingleLine: true
|
||||||
AllowShortFunctionsOnASingleLine: None # All
|
AllowShortFunctionsOnASingleLine: None # All
|
||||||
AllowShortIfStatementsOnASingleLine: Never # WithoutElse
|
AllowShortIfStatementsOnASingleLine: Never # WithoutElse
|
||||||
AllowShortLambdasOnASingleLine: Inline # All
|
AllowShortLambdasOnASingleLine: Inline # All
|
||||||
@ -24,10 +27,11 @@ AlwaysBreakBeforeMultilineStrings: true
|
|||||||
AlwaysBreakTemplateDeclarations: Yes
|
AlwaysBreakTemplateDeclarations: Yes
|
||||||
BinPackArguments: true
|
BinPackArguments: true
|
||||||
BinPackParameters: true
|
BinPackParameters: true
|
||||||
|
BitFieldColonSpacing: Both
|
||||||
BraceWrapping:
|
BraceWrapping:
|
||||||
AfterCaseLabel: false
|
AfterCaseLabel: false
|
||||||
AfterClass: false
|
AfterClass: false
|
||||||
AfterControlStatement: false
|
AfterControlStatement: Never
|
||||||
AfterEnum: false
|
AfterEnum: false
|
||||||
AfterFunction: false
|
AfterFunction: false
|
||||||
AfterNamespace: false
|
AfterNamespace: false
|
||||||
@ -37,12 +41,15 @@ BraceWrapping:
|
|||||||
AfterExternBlock: false
|
AfterExternBlock: false
|
||||||
BeforeCatch: false
|
BeforeCatch: false
|
||||||
BeforeElse: false
|
BeforeElse: false
|
||||||
|
BeforeLambdaBody: false
|
||||||
|
BeforeWhile: false
|
||||||
IndentBraces: false
|
IndentBraces: false
|
||||||
SplitEmptyFunction: true
|
SplitEmptyFunction: true
|
||||||
SplitEmptyRecord: true
|
SplitEmptyRecord: true
|
||||||
SplitEmptyNamespace: true
|
SplitEmptyNamespace: true
|
||||||
BreakBeforeBinaryOperators: None
|
BreakBeforeBinaryOperators: None
|
||||||
BreakBeforeBraces: Attach
|
BreakBeforeBraces: Attach
|
||||||
|
BreakBeforeConceptDeclarations: true
|
||||||
BreakBeforeInheritanceComma: true # false
|
BreakBeforeInheritanceComma: true # false
|
||||||
BreakInheritanceList: BeforeComma # BeforeColon
|
BreakInheritanceList: BeforeComma # BeforeColon
|
||||||
BreakBeforeTernaryOperators: true
|
BreakBeforeTernaryOperators: true
|
||||||
@ -60,21 +67,30 @@ Cpp11BracedListStyle: true
|
|||||||
DeriveLineEnding: true
|
DeriveLineEnding: true
|
||||||
DerivePointerAlignment: true
|
DerivePointerAlignment: true
|
||||||
DisableFormat: false
|
DisableFormat: false
|
||||||
|
EmptyLineAfterAccessModifier: Never
|
||||||
|
EmptyLineBeforeAccessModifier: LogicalBlock
|
||||||
ExperimentalAutoDetectBinPacking: false
|
ExperimentalAutoDetectBinPacking: false
|
||||||
FixNamespaceComments: true
|
FixNamespaceComments: true
|
||||||
ForEachMacros:
|
ForEachMacros:
|
||||||
- Q_FOREACH_THIS_LIST_MUST_BE_NON_EMPTY
|
- Q_FOREACH_THIS_LIST_MUST_BE_NON_EMPTY
|
||||||
IncludeBlocks: Preserve
|
IncludeBlocks: Preserve
|
||||||
#IndentCaseBlocks: false
|
IncludeCategories:
|
||||||
|
- Regex: '.*'
|
||||||
|
Priority: 0
|
||||||
|
IndentAccessModifiers: false
|
||||||
|
IndentCaseBlocks: false
|
||||||
IndentCaseLabels: true
|
IndentCaseLabels: true
|
||||||
|
IndentExternBlock: AfterExternBlock
|
||||||
IndentGotoLabels: true
|
IndentGotoLabels: true
|
||||||
IndentPPDirectives: None
|
IndentPPDirectives: None
|
||||||
|
IndentRequires: false
|
||||||
IndentWidth: 2
|
IndentWidth: 2
|
||||||
IndentWrappedFunctionNames: false
|
IndentWrappedFunctionNames: false
|
||||||
# InsertTrailingCommas: None
|
# InsertTrailingCommas: None
|
||||||
# JavaScriptQuotes: Leave
|
# JavaScriptQuotes: Leave
|
||||||
# JavaScriptWrapImports: true
|
# JavaScriptWrapImports: true
|
||||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||||
|
LambdaBodyIndentation: Signature
|
||||||
MacroBlockBegin: ''
|
MacroBlockBegin: ''
|
||||||
MacroBlockEnd: ''
|
MacroBlockEnd: ''
|
||||||
MaxEmptyLinesToKeep: 1
|
MaxEmptyLinesToKeep: 1
|
||||||
@ -91,15 +107,22 @@ PenaltyBreakFirstLessLess: 120
|
|||||||
PenaltyBreakString: 1000
|
PenaltyBreakString: 1000
|
||||||
PenaltyBreakTemplateDeclaration: 10
|
PenaltyBreakTemplateDeclaration: 10
|
||||||
PenaltyExcessCharacter: 1000000
|
PenaltyExcessCharacter: 1000000
|
||||||
|
PenaltyIndentedWhitespace: 0
|
||||||
PenaltyReturnTypeOnItsOwnLine: 200
|
PenaltyReturnTypeOnItsOwnLine: 200
|
||||||
PointerAlignment: Right
|
PointerAlignment: Right
|
||||||
|
PPIndentWidth: -1
|
||||||
|
ReferenceAlignment: Pointer
|
||||||
ReflowComments: false # true
|
ReflowComments: false # true
|
||||||
SortIncludes: false # disabled, because we need case insensitive sort
|
ShortNamespaceLines: 0 # 1
|
||||||
|
SortIncludes: CaseInsensitive # CaseSensitive
|
||||||
|
# SortJavaStaticImport: Before
|
||||||
SortUsingDeclarations: false # true
|
SortUsingDeclarations: false # true
|
||||||
SpaceAfterCStyleCast: false
|
SpaceAfterCStyleCast: false
|
||||||
SpaceAfterLogicalNot: false
|
SpaceAfterLogicalNot: false
|
||||||
SpaceAfterTemplateKeyword: true
|
SpaceAfterTemplateKeyword: true
|
||||||
|
SpaceAroundPointerQualifiers: Default
|
||||||
SpaceBeforeAssignmentOperators: true
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
SpaceBeforeCaseColon: false
|
||||||
SpaceBeforeCpp11BracedList: false
|
SpaceBeforeCpp11BracedList: false
|
||||||
SpaceBeforeCtorInitializerColon: true
|
SpaceBeforeCtorInitializerColon: true
|
||||||
SpaceBeforeInheritanceColon: true
|
SpaceBeforeInheritanceColon: true
|
||||||
@ -109,10 +132,13 @@ SpaceBeforeSquareBrackets: false
|
|||||||
SpaceInEmptyBlock: false
|
SpaceInEmptyBlock: false
|
||||||
SpaceInEmptyParentheses: false
|
SpaceInEmptyParentheses: false
|
||||||
SpacesBeforeTrailingComments: 2
|
SpacesBeforeTrailingComments: 2
|
||||||
SpacesInAngles: false
|
SpacesInAngles: Never
|
||||||
SpacesInConditionalStatement: false
|
SpacesInConditionalStatement: false
|
||||||
SpacesInContainerLiterals: true
|
SpacesInContainerLiterals: true
|
||||||
SpacesInCStyleCastParentheses: false
|
SpacesInCStyleCastParentheses: false
|
||||||
|
SpacesInLineCommentPrefix:
|
||||||
|
Minimum: 1
|
||||||
|
Maximum: 1 # -1
|
||||||
SpacesInParentheses: false
|
SpacesInParentheses: false
|
||||||
SpacesInSquareBrackets: false
|
SpacesInSquareBrackets: false
|
||||||
Standard: Auto
|
Standard: Auto
|
||||||
|
@ -219,7 +219,7 @@ function split_file($file, $chunks, $undo) {
|
|||||||
$new_content = $common.$namespace_begin.$f.$namespace_end;
|
$new_content = $common.$namespace_begin.$f.$namespace_end;
|
||||||
|
|
||||||
$std_methods = array();
|
$std_methods = array();
|
||||||
preg_match_all('/std::[a-z_0-9]*/', $new_content, $std_methods);
|
preg_match_all('/std::[a-z_0-9]*|td::unique(?!_)/', $new_content, $std_methods);
|
||||||
$std_methods = array_unique($std_methods[0]);
|
$std_methods = array_unique($std_methods[0]);
|
||||||
|
|
||||||
$needed_std_headers = array();
|
$needed_std_headers = array();
|
||||||
@ -230,6 +230,7 @@ function split_file($file, $chunks, $undo) {
|
|||||||
'std::uint32_t' => '',
|
'std::uint32_t' => '',
|
||||||
'std::int32_t' => '',
|
'std::int32_t' => '',
|
||||||
'std::int64_t' => '',
|
'std::int64_t' => '',
|
||||||
|
'td::unique' => 'algorithm',
|
||||||
'std::fill' => 'algorithm',
|
'std::fill' => 'algorithm',
|
||||||
'std::find' => 'algorithm',
|
'std::find' => 'algorithm',
|
||||||
'std::max' => 'algorithm',
|
'std::max' => 'algorithm',
|
||||||
|
@ -1079,6 +1079,7 @@ class ToggleSlowModeQuery final : public Td::ResultHandler {
|
|||||||
class ReportChannelSpamQuery final : public Td::ResultHandler {
|
class ReportChannelSpamQuery final : public Td::ResultHandler {
|
||||||
Promise<Unit> promise_;
|
Promise<Unit> promise_;
|
||||||
ChannelId channel_id_;
|
ChannelId channel_id_;
|
||||||
|
DialogId sender_dialog_id_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ReportChannelSpamQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
explicit ReportChannelSpamQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||||
@ -1086,6 +1087,7 @@ class ReportChannelSpamQuery final : public Td::ResultHandler {
|
|||||||
|
|
||||||
void send(ChannelId channel_id, DialogId sender_dialog_id, const vector<MessageId> &message_ids) {
|
void send(ChannelId channel_id, DialogId sender_dialog_id, const vector<MessageId> &message_ids) {
|
||||||
channel_id_ = channel_id;
|
channel_id_ = channel_id;
|
||||||
|
sender_dialog_id_ = sender_dialog_id;
|
||||||
|
|
||||||
auto input_channel = td_->contacts_manager_->get_input_channel(channel_id);
|
auto input_channel = td_->contacts_manager_->get_input_channel(channel_id);
|
||||||
CHECK(input_channel != nullptr);
|
CHECK(input_channel != nullptr);
|
||||||
@ -1110,7 +1112,9 @@ class ReportChannelSpamQuery final : public Td::ResultHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void on_error(Status status) final {
|
void on_error(Status status) final {
|
||||||
// td_->contacts_manager_->on_get_channel_error(channel_id_, status, "ReportChannelSpamQuery");
|
if (sender_dialog_id_.get_type() != DialogType::Channel) {
|
||||||
|
td_->contacts_manager_->on_get_channel_error(channel_id_, status, "ReportChannelSpamQuery");
|
||||||
|
}
|
||||||
promise_.set_error(std::move(status));
|
promise_.set_error(std::move(status));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -2127,14 +2131,16 @@ class EditChannelAdminQuery final : public Td::ResultHandler {
|
|||||||
class EditChannelBannedQuery final : public Td::ResultHandler {
|
class EditChannelBannedQuery final : public Td::ResultHandler {
|
||||||
Promise<Unit> promise_;
|
Promise<Unit> promise_;
|
||||||
ChannelId channel_id_;
|
ChannelId channel_id_;
|
||||||
|
DialogId participant_dialog_id_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit EditChannelBannedQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
explicit EditChannelBannedQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void send(ChannelId channel_id, tl_object_ptr<telegram_api::InputPeer> &&input_peer,
|
void send(ChannelId channel_id, DialogId participant_dialog_id, tl_object_ptr<telegram_api::InputPeer> &&input_peer,
|
||||||
const DialogParticipantStatus &status) {
|
const DialogParticipantStatus &status) {
|
||||||
channel_id_ = channel_id;
|
channel_id_ = channel_id;
|
||||||
|
participant_dialog_id_ = participant_dialog_id;
|
||||||
auto input_channel = td_->contacts_manager_->get_input_channel(channel_id);
|
auto input_channel = td_->contacts_manager_->get_input_channel(channel_id);
|
||||||
CHECK(input_channel != nullptr);
|
CHECK(input_channel != nullptr);
|
||||||
send_query(G()->net_query_creator().create(telegram_api::channels_editBanned(
|
send_query(G()->net_query_creator().create(telegram_api::channels_editBanned(
|
||||||
@ -2154,7 +2160,9 @@ class EditChannelBannedQuery final : public Td::ResultHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void on_error(Status status) final {
|
void on_error(Status status) final {
|
||||||
|
if (participant_dialog_id_.get_type() != DialogType::Channel) {
|
||||||
td_->contacts_manager_->on_get_channel_error(channel_id_, status, "EditChannelBannedQuery");
|
td_->contacts_manager_->on_get_channel_error(channel_id_, status, "EditChannelBannedQuery");
|
||||||
|
}
|
||||||
promise_.set_error(std::move(status));
|
promise_.set_error(std::move(status));
|
||||||
td_->updates_manager_->get_difference("EditChannelBannedQuery");
|
td_->updates_manager_->get_difference("EditChannelBannedQuery");
|
||||||
}
|
}
|
||||||
@ -2737,7 +2745,9 @@ class GetChannelParticipantQuery final : public Td::ResultHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// td_->contacts_manager_->on_get_channel_error(channel_id_, status, "GetChannelParticipantQuery");
|
if (participant_dialog_id_.get_type() != DialogType::Channel) {
|
||||||
|
td_->contacts_manager_->on_get_channel_error(channel_id_, status, "GetChannelParticipantQuery");
|
||||||
|
}
|
||||||
promise_.set_error(std::move(status));
|
promise_.set_error(std::move(status));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -7573,7 +7583,8 @@ void ContactsManager::restrict_channel_participant(ChannelId channel_id, DialogI
|
|||||||
if (participant_dialog_id.get_type() == DialogType::User) {
|
if (participant_dialog_id.get_type() == DialogType::User) {
|
||||||
speculative_add_channel_user(channel_id, participant_dialog_id.get_user_id(), status, old_status);
|
speculative_add_channel_user(channel_id, participant_dialog_id.get_user_id(), status, old_status);
|
||||||
}
|
}
|
||||||
td_->create_handler<EditChannelBannedQuery>(std::move(promise))->send(channel_id, std::move(input_peer), status);
|
td_->create_handler<EditChannelBannedQuery>(std::move(promise))
|
||||||
|
->send(channel_id, participant_dialog_id, std::move(input_peer), status);
|
||||||
}
|
}
|
||||||
|
|
||||||
ChannelId ContactsManager::migrate_chat_to_megagroup(ChatId chat_id, Promise<Unit> &promise) {
|
ChannelId ContactsManager::migrate_chat_to_megagroup(ChatId chat_id, Promise<Unit> &promise) {
|
||||||
|
@ -2873,12 +2873,17 @@ class BlockFromRepliesQuery final : public Td::ResultHandler {
|
|||||||
|
|
||||||
class DeleteParticipantHistoryQuery final : public Td::ResultHandler {
|
class DeleteParticipantHistoryQuery final : public Td::ResultHandler {
|
||||||
Promise<AffectedHistory> promise_;
|
Promise<AffectedHistory> promise_;
|
||||||
|
ChannelId channel_id_;
|
||||||
|
DialogId sender_dialog_id_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DeleteParticipantHistoryQuery(Promise<AffectedHistory> &&promise) : promise_(std::move(promise)) {
|
explicit DeleteParticipantHistoryQuery(Promise<AffectedHistory> &&promise) : promise_(std::move(promise)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void send(ChannelId channel_id, DialogId sender_dialog_id) {
|
void send(ChannelId channel_id, DialogId sender_dialog_id) {
|
||||||
|
channel_id_ = channel_id;
|
||||||
|
sender_dialog_id_ = sender_dialog_id;
|
||||||
|
|
||||||
auto input_channel = td_->contacts_manager_->get_input_channel(channel_id);
|
auto input_channel = td_->contacts_manager_->get_input_channel(channel_id);
|
||||||
if (input_channel == nullptr) {
|
if (input_channel == nullptr) {
|
||||||
return promise_.set_error(Status::Error(400, "Chat is not accessible"));
|
return promise_.set_error(Status::Error(400, "Chat is not accessible"));
|
||||||
@ -2902,7 +2907,9 @@ class DeleteParticipantHistoryQuery final : public Td::ResultHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void on_error(Status status) final {
|
void on_error(Status status) final {
|
||||||
// td_->contacts_manager_->on_get_channel_error(channel_id_, status, "DeleteParticipantHistoryQuery");
|
if (sender_dialog_id_.get_type() != DialogType::Channel) {
|
||||||
|
td_->contacts_manager_->on_get_channel_error(channel_id_, status, "DeleteParticipantHistoryQuery");
|
||||||
|
}
|
||||||
promise_.set_error(std::move(status));
|
promise_.set_error(std::move(status));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -12178,6 +12185,30 @@ void MessagesManager::set_dialog_online_member_count(DialogId dialog_id, int32 o
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (online_member_count < 0) {
|
||||||
|
LOG(ERROR) << "Receive online_member_count = " << online_member_count << " in " << dialog_id;
|
||||||
|
online_member_count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (dialog_id.get_type()) {
|
||||||
|
case DialogType::Chat: {
|
||||||
|
auto participant_count = td_->contacts_manager_->get_chat_participant_count(dialog_id.get_chat_id());
|
||||||
|
if (online_member_count > participant_count) {
|
||||||
|
online_member_count = participant_count;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DialogType::Channel: {
|
||||||
|
auto participant_count = td_->contacts_manager_->get_channel_participant_count(dialog_id.get_channel_id());
|
||||||
|
if (participant_count != 0 && online_member_count > participant_count) {
|
||||||
|
online_member_count = participant_count;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
auto &info = dialog_online_member_counts_[dialog_id];
|
auto &info = dialog_online_member_counts_[dialog_id];
|
||||||
LOG(INFO) << "Change number of online members from " << info.online_member_count << " to " << online_member_count
|
LOG(INFO) << "Change number of online members from " << info.online_member_count << " to " << online_member_count
|
||||||
<< " in " << dialog_id << " from " << source;
|
<< " in " << dialog_id << " from " << source;
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
#include "td/utils/logging.h"
|
#include "td/utils/logging.h"
|
||||||
#include "td/utils/port/thread_local.h"
|
#include "td/utils/port/thread_local.h"
|
||||||
#include "td/utils/ThreadSafeCounter.h"
|
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <new>
|
#include <new>
|
||||||
@ -26,20 +25,14 @@ TD_THREAD_LOCAL BufferAllocator::BufferRawTls *BufferAllocator::buffer_raw_tls;
|
|||||||
|
|
||||||
std::atomic<size_t> BufferAllocator::buffer_mem;
|
std::atomic<size_t> BufferAllocator::buffer_mem;
|
||||||
|
|
||||||
static ThreadSafeCounter buffer_slice_size_;
|
|
||||||
|
|
||||||
int64 BufferAllocator::get_buffer_slice_size() {
|
int64 BufferAllocator::get_buffer_slice_size() {
|
||||||
return buffer_slice_size_.sum();
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BufferAllocator::track_buffer_slice(int64 size) {
|
void BufferAllocator::track_buffer_slice(int64 size) {
|
||||||
if (size == 0) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer_slice_size_.add(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t BufferAllocator::get_buffer_mem() {
|
size_t BufferAllocator::get_buffer_mem() {
|
||||||
return buffer_mem;
|
return buffer_mem;
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,8 @@
|
|||||||
|
|
||||||
#define REF_NEW ref new
|
#define REF_NEW ref new
|
||||||
#define CLRCALL
|
#define CLRCALL
|
||||||
#define DEPRECATED_ATTRIBUTE(message) ::Windows::Foundation::Metadata::Deprecated(message,\
|
#define DEPRECATED_ATTRIBUTE(message) \
|
||||||
::Windows::Foundation::Metadata::DeprecationType::Deprecate, 0x0)
|
::Windows::Foundation::Metadata::Deprecated(message, ::Windows::Foundation::Metadata::DeprecationType::Deprecate, 0x0)
|
||||||
|
|
||||||
namespace CxCli {
|
namespace CxCli {
|
||||||
|
|
||||||
@ -73,6 +73,7 @@ public:
|
|||||||
std::lock_guard<std::mutex> guard(mutex_);
|
std::lock_guard<std::mutex> guard(mutex_);
|
||||||
return impl_[key];
|
return impl_[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::mutex mutex_;
|
std::mutex mutex_;
|
||||||
std::map<Key, Value> impl_;
|
std::map<Key, Value> impl_;
|
||||||
|
@ -103,7 +103,7 @@ StringBuilder &operator<<(StringBuilder &sb, const PrintFlags &print_flags) {
|
|||||||
namespace detail {
|
namespace detail {
|
||||||
class FileFdImpl {
|
class FileFdImpl {
|
||||||
public:
|
public:
|
||||||
PollableFdInfo info;
|
PollableFdInfo info_;
|
||||||
};
|
};
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
@ -242,8 +242,8 @@ Result<FileFd> FileFd::open(CSlice filepath, int32 flags, int32 mode) {
|
|||||||
|
|
||||||
FileFd FileFd::from_native_fd(NativeFd native_fd) {
|
FileFd FileFd::from_native_fd(NativeFd native_fd) {
|
||||||
auto impl = make_unique<detail::FileFdImpl>();
|
auto impl = make_unique<detail::FileFdImpl>();
|
||||||
impl->info.set_native_fd(std::move(native_fd));
|
impl->info_.set_native_fd(std::move(native_fd));
|
||||||
impl->info.add_flags(PollFlags::Write());
|
impl->info_.add_flags(PollFlags::Write());
|
||||||
return FileFd(std::move(impl));
|
return FileFd(std::move(impl));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -648,11 +648,11 @@ Status FileFd::truncate_to_current_position(int64 current_position) {
|
|||||||
}
|
}
|
||||||
PollableFdInfo &FileFd::get_poll_info() {
|
PollableFdInfo &FileFd::get_poll_info() {
|
||||||
CHECK(!empty());
|
CHECK(!empty());
|
||||||
return impl_->info;
|
return impl_->info_;
|
||||||
}
|
}
|
||||||
const PollableFdInfo &FileFd::get_poll_info() const {
|
const PollableFdInfo &FileFd::get_poll_info() const {
|
||||||
CHECK(!empty());
|
CHECK(!empty());
|
||||||
return impl_->info;
|
return impl_->info_;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -43,7 +43,7 @@ namespace detail {
|
|||||||
#if TD_PORT_WINDOWS
|
#if TD_PORT_WINDOWS
|
||||||
class SocketFdImpl final : private Iocp::Callback {
|
class SocketFdImpl final : private Iocp::Callback {
|
||||||
public:
|
public:
|
||||||
explicit SocketFdImpl(NativeFd native_fd) : info(std::move(native_fd)) {
|
explicit SocketFdImpl(NativeFd native_fd) : info_(std::move(native_fd)) {
|
||||||
VLOG(fd) << get_native_fd() << " create from native_fd";
|
VLOG(fd) << get_native_fd() << " create from native_fd";
|
||||||
get_poll_info().add_flags(PollFlags::Write());
|
get_poll_info().add_flags(PollFlags::Write());
|
||||||
Iocp::get()->subscribe(get_native_fd(), this);
|
Iocp::get()->subscribe(get_native_fd(), this);
|
||||||
@ -51,7 +51,7 @@ class SocketFdImpl final : private Iocp::Callback {
|
|||||||
notify_iocp_connected();
|
notify_iocp_connected();
|
||||||
}
|
}
|
||||||
|
|
||||||
SocketFdImpl(NativeFd native_fd, const IPAddress &addr) : info(std::move(native_fd)) {
|
SocketFdImpl(NativeFd native_fd, const IPAddress &addr) : info_(std::move(native_fd)) {
|
||||||
VLOG(fd) << get_native_fd() << " create from native_fd and connect";
|
VLOG(fd) << get_native_fd() << " create from native_fd and connect";
|
||||||
get_poll_info().add_flags(PollFlags::Write());
|
get_poll_info().add_flags(PollFlags::Write());
|
||||||
Iocp::get()->subscribe(get_native_fd(), this);
|
Iocp::get()->subscribe(get_native_fd(), this);
|
||||||
@ -88,14 +88,14 @@ class SocketFdImpl final : private Iocp::Callback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PollableFdInfo &get_poll_info() {
|
PollableFdInfo &get_poll_info() {
|
||||||
return info;
|
return info_;
|
||||||
}
|
}
|
||||||
const PollableFdInfo &get_poll_info() const {
|
const PollableFdInfo &get_poll_info() const {
|
||||||
return info;
|
return info_;
|
||||||
}
|
}
|
||||||
|
|
||||||
const NativeFd &get_native_fd() const {
|
const NativeFd &get_native_fd() const {
|
||||||
return info.native_fd();
|
return info_.native_fd();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<size_t> write(Slice data) {
|
Result<size_t> write(Slice data) {
|
||||||
@ -161,7 +161,7 @@ class SocketFdImpl final : private Iocp::Callback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PollableFdInfo info;
|
PollableFdInfo info_;
|
||||||
SpinLock lock_;
|
SpinLock lock_;
|
||||||
|
|
||||||
std::atomic<int> refcnt_{1};
|
std::atomic<int> refcnt_{1};
|
||||||
@ -283,7 +283,12 @@ class SocketFdImpl final : private Iocp::Callback {
|
|||||||
if (overlapped == reinterpret_cast<WSAOVERLAPPED *>(&close_overlapped_)) {
|
if (overlapped == reinterpret_cast<WSAOVERLAPPED *>(&close_overlapped_)) {
|
||||||
return on_close();
|
return on_close();
|
||||||
}
|
}
|
||||||
UNREACHABLE();
|
LOG(ERROR) << this << ' ' << overlapped << ' ' << &read_overlapped_ << ' ' << &write_overlapped_ << ' '
|
||||||
|
<< reinterpret_cast<WSAOVERLAPPED *>(&close_overlapped_) << ' ' << size;
|
||||||
|
LOG(FATAL) << get_native_fd() << ' ' << info_.get_flags_local() << ' ' << refcnt_.load() << ' ' << close_flag_
|
||||||
|
<< ' ' << need_close_after_write_ << ' ' << is_connected_ << ' ' << is_read_active_ << ' '
|
||||||
|
<< is_write_active_ << ' ' << is_write_waiting_.load() << ' ' << input_reader_.size() << ' '
|
||||||
|
<< output_reader_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_error(Status status) {
|
void on_error(Status status) {
|
||||||
@ -335,7 +340,7 @@ class SocketFdImpl final : private Iocp::Callback {
|
|||||||
void on_close() {
|
void on_close() {
|
||||||
VLOG(fd) << get_native_fd() << " on close";
|
VLOG(fd) << get_native_fd() << " on close";
|
||||||
close_flag_ = true;
|
close_flag_ = true;
|
||||||
info.set_native_fd({});
|
info_.set_native_fd({});
|
||||||
}
|
}
|
||||||
bool dec_refcnt() {
|
bool dec_refcnt() {
|
||||||
VLOG(fd) << get_native_fd() << " dec_refcnt from " << refcnt_;
|
VLOG(fd) << get_native_fd() << " dec_refcnt from " << refcnt_;
|
||||||
@ -386,18 +391,18 @@ static InitWSA init_wsa;
|
|||||||
#else
|
#else
|
||||||
class SocketFdImpl {
|
class SocketFdImpl {
|
||||||
public:
|
public:
|
||||||
PollableFdInfo info;
|
PollableFdInfo info_;
|
||||||
explicit SocketFdImpl(NativeFd fd) : info(std::move(fd)) {
|
explicit SocketFdImpl(NativeFd fd) : info_(std::move(fd)) {
|
||||||
}
|
}
|
||||||
PollableFdInfo &get_poll_info() {
|
PollableFdInfo &get_poll_info() {
|
||||||
return info;
|
return info_;
|
||||||
}
|
}
|
||||||
const PollableFdInfo &get_poll_info() const {
|
const PollableFdInfo &get_poll_info() const {
|
||||||
return info;
|
return info_;
|
||||||
}
|
}
|
||||||
|
|
||||||
const NativeFd &get_native_fd() const {
|
const NativeFd &get_native_fd() const {
|
||||||
return info.native_fd();
|
return info_.native_fd();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<size_t> writev(Span<IoSlice> slices) {
|
Result<size_t> writev(Span<IoSlice> slices) {
|
||||||
|
@ -29,7 +29,7 @@ namespace td {
|
|||||||
namespace detail {
|
namespace detail {
|
||||||
class EventFdLinuxImpl {
|
class EventFdLinuxImpl {
|
||||||
public:
|
public:
|
||||||
PollableFdInfo info;
|
PollableFdInfo info_;
|
||||||
};
|
};
|
||||||
|
|
||||||
EventFdLinux::EventFdLinux() = default;
|
EventFdLinux::EventFdLinux() = default;
|
||||||
@ -42,7 +42,7 @@ void EventFdLinux::init() {
|
|||||||
auto eventfd_errno = errno;
|
auto eventfd_errno = errno;
|
||||||
LOG_IF(FATAL, !fd) << Status::PosixError(eventfd_errno, "eventfd call failed");
|
LOG_IF(FATAL, !fd) << Status::PosixError(eventfd_errno, "eventfd call failed");
|
||||||
impl_ = make_unique<EventFdLinuxImpl>();
|
impl_ = make_unique<EventFdLinuxImpl>();
|
||||||
impl_->info.set_native_fd(std::move(fd));
|
impl_->info_.set_native_fd(std::move(fd));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EventFdLinux::empty() {
|
bool EventFdLinux::empty() {
|
||||||
@ -58,14 +58,14 @@ Status EventFdLinux::get_pending_error() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PollableFdInfo &EventFdLinux::get_poll_info() {
|
PollableFdInfo &EventFdLinux::get_poll_info() {
|
||||||
return impl_->info;
|
return impl_->info_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// NB: will be called from multiple threads
|
// NB: will be called from multiple threads
|
||||||
void EventFdLinux::release() {
|
void EventFdLinux::release() {
|
||||||
const uint64 value = 1;
|
const uint64 value = 1;
|
||||||
auto slice = Slice(reinterpret_cast<const char *>(&value), sizeof(value));
|
auto slice = Slice(reinterpret_cast<const char *>(&value), sizeof(value));
|
||||||
auto native_fd = impl_->info.native_fd().fd();
|
auto native_fd = impl_->info_.native_fd().fd();
|
||||||
|
|
||||||
auto result = [&]() -> Result<size_t> {
|
auto result = [&]() -> Result<size_t> {
|
||||||
auto write_res = detail::skip_eintr([&] { return write(native_fd, slice.begin(), slice.size()); });
|
auto write_res = detail::skip_eintr([&] { return write(native_fd, slice.begin(), slice.size()); });
|
||||||
@ -86,7 +86,7 @@ void EventFdLinux::release() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EventFdLinux::acquire() {
|
void EventFdLinux::acquire() {
|
||||||
impl_->info.sync_with_poll();
|
impl_->info_.sync_with_poll();
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
// Clear flags without EAGAIN and EWOULDBLOCK
|
// Clear flags without EAGAIN and EWOULDBLOCK
|
||||||
// Looks like it is safe thing to do with eventfd
|
// Looks like it is safe thing to do with eventfd
|
||||||
@ -94,7 +94,7 @@ void EventFdLinux::acquire() {
|
|||||||
};
|
};
|
||||||
uint64 res;
|
uint64 res;
|
||||||
auto slice = MutableSlice(reinterpret_cast<char *>(&res), sizeof(res));
|
auto slice = MutableSlice(reinterpret_cast<char *>(&res), sizeof(res));
|
||||||
auto native_fd = impl_->info.native_fd().fd();
|
auto native_fd = impl_->info_.native_fd().fd();
|
||||||
auto result = [&]() -> Result<size_t> {
|
auto result = [&]() -> Result<size_t> {
|
||||||
CHECK(!slice.empty());
|
CHECK(!slice.empty());
|
||||||
auto read_res = detail::skip_eintr([&] { return ::read(native_fd, slice.begin(), slice.size()); });
|
auto read_res = detail::skip_eintr([&] { return ::read(native_fd, slice.begin(), slice.size()); });
|
||||||
|
Loading…
Reference in New Issue
Block a user