-
Notifications
You must be signed in to change notification settings - Fork 542
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Adds `wangle::AcceptObserver`, an observer that is notified when a connection is accepted. - Can be used by instrumentation that ties its lifetime to that of the transport; the callback can be used to initialize instrumentation and install callbacks on accept (such as `AsyncTransport::LifecycleCallback`, D21613750) without requiring further changes to existing application / acceptor logic. Since there were no existing tests around the base `wangle::Acceptor` logic, I added a few in addition to what I needed for testing `AcceptObserver`. Reviewed By: mingtaoy Differential Revision: D21652470 fbshipit-source-id: dd9cb652ff30d6d47f20f1aced221d2d1ef7a715
- Loading branch information
1 parent
720329e
commit 1eda2c3
Showing
4 changed files
with
515 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
namespace folly { | ||
class AsyncTransport; | ||
} | ||
|
||
namespace wangle { | ||
|
||
class Acceptor; | ||
|
||
/** | ||
* Observer of events related to connection acceptance. | ||
* | ||
* This observer can be combined with AsyncTransport::LifecycleObserver and | ||
* other observers to enable instrumentation to be installed when a connection | ||
* is accepted. For instance, a sampling algorithm can be executed in accept() | ||
* to sample and install instrumentation on a subset of connections. | ||
*/ | ||
class AcceptObserver { | ||
public: | ||
virtual ~AcceptObserver() = default; | ||
|
||
/** | ||
* accept() is invoked after a connection has been accepted and an | ||
* AsyncTransport has been instantiated to manage the socket fd / connection. | ||
* | ||
* @param transport Transport of accepted connection. | ||
*/ | ||
virtual void accept(folly::AsyncTransport* transport) noexcept = 0; | ||
|
||
/** | ||
* ready() is invoked after a connection has been accepted and SSL | ||
* handshakes (if any) have completed, right before onNewConnection is called. | ||
* | ||
* @param transport Transport of ready connection. | ||
*/ | ||
virtual void ready(folly::AsyncTransport* transport) noexcept = 0; | ||
|
||
/** | ||
* acceptorDestroy() is invoked when the worker (acceptor) is destroyed. | ||
* | ||
* No further events will be invoked after acceptorDestroy(). | ||
* | ||
* @param acceptor Acceptor that was destroyed. | ||
*/ | ||
virtual void acceptorDestroy(Acceptor* acceptor) noexcept = 0; | ||
|
||
/** | ||
* observerAttached() is invoked when the observer is installed. | ||
* | ||
* @param acceptor Acceptor that the observer is attached to. | ||
*/ | ||
virtual void observerAttach(Acceptor* acceptor) noexcept = 0; | ||
|
||
/** | ||
* observerDetached() is invoked if the observer is uninstalled prior to | ||
* worker (acceptor) destruction. | ||
* | ||
* No further events will be invoked after observerDetached(). | ||
* | ||
* @param acceptor Acceptor that the observer was removed from. | ||
*/ | ||
virtual void observerDetach(Acceptor* acceptor) noexcept = 0; | ||
}; | ||
|
||
} // namespace wangle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.