Skip to content

Commit

Permalink
Support Socket
Browse files Browse the repository at this point in the history
  • Loading branch information
chenBright committed Mar 31, 2024
1 parent 4cc32f2 commit 113f268
Show file tree
Hide file tree
Showing 14 changed files with 598 additions and 682 deletions.
2 changes: 1 addition & 1 deletion src/brpc/acceptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ void Acceptor::OnNewConnectionsUntilEAGAIN(Socket* acception) {
// Always add this socket into `_socket_map' whether it
// has been `SetFailed' or not, whether `Acceptor' is
// running or not. Otherwise, `Acceptor::BeforeRecycle'
// may be called (inside Socket::OnRecycle) after `Acceptor'
// may be called (inside Socket::BeforeRecycled) after `Acceptor'
// has been destroyed
am->_socket_map.insert(socket_id, ConnectStatistics());
}
Expand Down
3 changes: 2 additions & 1 deletion src/brpc/details/health_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ bool HealthCheckTask::OnTriggeringTask(timespec* next_abstime) {
ptr->_ninflight_app_health_check.fetch_add(
1, butil::memory_order_relaxed);
}
ptr->Revive();
// See comments above.
ptr->Revive(2/*note*/);
ptr->_hc_count = 0;
if (!FLAGS_health_check_path.empty()) {
HealthCheckManager::StartCheck(_id, ptr->_health_check_interval_s);
Expand Down
18 changes: 7 additions & 11 deletions src/brpc/event_dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,34 +71,30 @@ EventDispatcher& GetGlobalEventDispatcher(int fd, bthread_tag_t tag) {
return g_edisp[tag * FLAGS_event_dispatcher_num + index];
}

int EventData::OnCreate(const EventDataOptions* options) {
if (!options) {
LOG(ERROR) << "options is NULL";
return -1;
}
if (options->user_id == INVALID_VREF_ID) {
int EventData::OnCreated(const EventDataOptions& options) {
if (options.user_id == INVALID_VREF_ID) {
LOG(ERROR) << "Invalid user_id=-1";
return -1;
}
if (!options->input_cb) {
if (!options.input_cb) {
LOG(ERROR) << "Invalid input_cb=NULL";
return -1;
}
if (!options->output_cb) {
if (!options.output_cb) {
LOG(ERROR) << "Invalid output_cb=NULL";
return -1;
}

_options = *options;
_options = options;
return 0;
}

void EventData::OnRecycle() {
void EventData::BeforeRecycled() {
_options = {INVALID_EVENT_DATA_ID, NULL, NULL};
}

void MakeEventDataIdInvalid(EventDataId& id) {
EventData::SetFailed(id);
EventData::SetFailedById(id);
id = INVALID_EVENT_DATA_ID;
}

Expand Down
13 changes: 7 additions & 6 deletions src/brpc/event_dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,11 @@ struct EventDataOptions {
// stored in epoll/kqueue data, and calls its callback, so
// EventDispatcher supports various IO types, such as socket,
// pipe, eventfd, timerfd, etc.
class EventData : public VersionedRefWithId<EventData, EventDataOptions> {
class EventData : public VersionedRefWithId<EventData> {
public:
explicit EventData(Forbidden f)
: VersionedRefWithId<EventData, EventDataOptions>(f)
, _options{INVALID_EVENT_DATA_ID, NULL, NULL}
{}
: VersionedRefWithId<EventData>(f)
, _options{INVALID_EVENT_DATA_ID, NULL, NULL} {}

DISALLOW_COPY_AND_ASSIGN(EventData);

Expand All @@ -76,8 +75,10 @@ class EventData : public VersionedRefWithId<EventData, EventDataOptions> {
}

private:
int OnCreate(const EventDataOptions* options) override;
void OnRecycle() override;
friend class VersionedRefWithId<EventData>;

int OnCreated(const EventDataOptions& options);
void BeforeRecycled();

EventDataOptions _options;
};
Expand Down
Loading

0 comments on commit 113f268

Please sign in to comment.