Skip to content

Commit 231e8eb

Browse files
authored
Announce ntci::StreamSocketSession connection initiate and complete events
1 parent 3e6be0d commit 231e8eb

11 files changed

+494
-31
lines changed

groups/ntc/ntca/ntca_connectevent.h

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class ConnectEvent
5959
/// Create a new connect event having the same value as the specified
6060
/// 'original' object. Optionally specify a 'basicAllocator'
6161
/// used to supply memory. If 'basicAllocator' is 0, the currently
62-
/// installed default allocator is used.s
62+
/// installed default allocator is used.
6363
ConnectEvent(const ConnectEvent& original,
6464
bslma::Allocator* basicAllocator = 0);
6565

@@ -87,16 +87,20 @@ class ConnectEvent
8787
/// Return the state of the connect attempt at the time of the event.
8888
const ntca::ConnectContext& context() const;
8989

90-
/// Return true if 'type() == ntca::ConnectEventType::e_COMPLETE', i.e.,
91-
/// the connect operation successfully completed without an error.
92-
/// Otherwise, return false.
93-
bool isComplete() const;
90+
/// Return true if 'type() == ntca::ConnectEventType::e_INITIATED', i.e.,
91+
/// the connect operation has been initiated. Otherwise, return false.
92+
bool isInitiated() const;
9493

9594
/// Return true if 'type() == ntca::ConnectEventType::e_ERROR', i.e.,
9695
/// the connect operation failed because of an error. Otherwise, return
9796
/// false. Note that the exact error is stored at 'context().error()'.
9897
bool isError() const;
9998

99+
/// Return true if 'type() == ntca::ConnectEventType::e_COMPLETE', i.e.,
100+
/// the connect operation successfully completed without an error.
101+
/// Otherwise, return false.
102+
bool isComplete() const;
103+
100104
/// Return true if this object has the same value as the specified
101105
/// 'other' object, otherwise return false.
102106
bool equals(const ConnectEvent& other) const;
@@ -216,9 +220,9 @@ const ntca::ConnectContext& ConnectEvent::context() const
216220
}
217221

218222
NTCCFG_INLINE
219-
bool ConnectEvent::isComplete() const
223+
bool ConnectEvent::isInitiated() const
220224
{
221-
return d_type == ntca::ConnectEventType::e_COMPLETE;
225+
return d_type == ntca::ConnectEventType::e_INITIATED;
222226
}
223227

224228
NTCCFG_INLINE
@@ -227,6 +231,12 @@ bool ConnectEvent::isError() const
227231
return d_type == ntca::ConnectEventType::e_ERROR;
228232
}
229233

234+
NTCCFG_INLINE
235+
bool ConnectEvent::isComplete() const
236+
{
237+
return d_type == ntca::ConnectEventType::e_COMPLETE;
238+
}
239+
230240
NTCCFG_INLINE
231241
bsl::ostream& operator<<(bsl::ostream& stream, const ConnectEvent& object)
232242
{

groups/ntc/ntca/ntca_connecteventtype.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ namespace ntca {
2828
int ConnectEventType::fromInt(ConnectEventType::Value* result, int number)
2929
{
3030
switch (number) {
31-
case ConnectEventType::e_COMPLETE:
31+
case ConnectEventType::e_INITIATED:
3232
case ConnectEventType::e_ERROR:
33+
case ConnectEventType::e_COMPLETE:
3334
*result = static_cast<ConnectEventType::Value>(number);
3435
return 0;
3536
default:
@@ -40,27 +41,36 @@ int ConnectEventType::fromInt(ConnectEventType::Value* result, int number)
4041
int ConnectEventType::fromString(ConnectEventType::Value* result,
4142
const bslstl::StringRef& string)
4243
{
43-
if (bdlb::String::areEqualCaseless(string, "COMPLETE")) {
44-
*result = e_COMPLETE;
44+
if (bdlb::String::areEqualCaseless(string, "INITIATED")) {
45+
*result = e_INITIATED;
4546
return 0;
4647
}
48+
4749
if (bdlb::String::areEqualCaseless(string, "ERROR")) {
4850
*result = e_ERROR;
4951
return 0;
5052
}
5153

54+
if (bdlb::String::areEqualCaseless(string, "COMPLETE")) {
55+
*result = e_COMPLETE;
56+
return 0;
57+
}
58+
5259
return -1;
5360
}
5461

5562
const char* ConnectEventType::toString(ConnectEventType::Value value)
5663
{
5764
switch (value) {
58-
case e_COMPLETE: {
59-
return "COMPLETE";
65+
case e_INITIATED: {
66+
return "INITIATED";
6067
} break;
6168
case e_ERROR: {
6269
return "ERROR";
6370
} break;
71+
case e_COMPLETE: {
72+
return "COMPLETE";
73+
} break;
6474
}
6575

6676
BSLS_ASSERT(!"invalid enumerator");

groups/ntc/ntca/ntca_connecteventtype.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@ struct ConnectEventType {
3535
public:
3636
/// Enumerate the connect event types.
3737
enum Value {
38-
// The connection sequence is complete.
39-
e_COMPLETE = 0,
38+
/// The connection sequence has been initiated.
39+
e_INITIATED = 0,
4040

4141
// An error has been detected during the connection sequence.
42-
e_ERROR = 1
42+
e_ERROR = 1,
43+
44+
// The connection sequence is complete.
45+
e_COMPLETE = 2
4346
};
4447

4548
/// Return the string representation exactly matching the enumerator

groups/ntc/ntca/ntca_upgradeeventtype.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ namespace ntca {
2828
int UpgradeEventType::fromInt(UpgradeEventType::Value* result, int number)
2929
{
3030
switch (number) {
31-
case UpgradeEventType::e_COMPLETE:
31+
case UpgradeEventType::e_INITIATED:
3232
case UpgradeEventType::e_ERROR:
33+
case UpgradeEventType::e_COMPLETE:
3334
*result = static_cast<UpgradeEventType::Value>(number);
3435
return 0;
3536
default:
@@ -40,27 +41,36 @@ int UpgradeEventType::fromInt(UpgradeEventType::Value* result, int number)
4041
int UpgradeEventType::fromString(UpgradeEventType::Value* result,
4142
const bslstl::StringRef& string)
4243
{
43-
if (bdlb::String::areEqualCaseless(string, "COMPLETE")) {
44-
*result = e_COMPLETE;
44+
if (bdlb::String::areEqualCaseless(string, "INITIATED")) {
45+
*result = e_INITIATED;
4546
return 0;
4647
}
48+
4749
if (bdlb::String::areEqualCaseless(string, "ERROR")) {
4850
*result = e_ERROR;
4951
return 0;
5052
}
5153

54+
if (bdlb::String::areEqualCaseless(string, "COMPLETE")) {
55+
*result = e_COMPLETE;
56+
return 0;
57+
}
58+
5259
return -1;
5360
}
5461

5562
const char* UpgradeEventType::toString(UpgradeEventType::Value value)
5663
{
5764
switch (value) {
58-
case e_COMPLETE: {
59-
return "COMPLETE";
65+
case e_INITIATED: {
66+
return "INITIATED";
6067
} break;
6168
case e_ERROR: {
6269
return "ERROR";
6370
} break;
71+
case e_COMPLETE: {
72+
return "COMPLETE";
73+
} break;
6474
}
6575

6676
BSLS_ASSERT(!"invalid enumerator");

groups/ntc/ntca/ntca_upgradeeventtype.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@ struct UpgradeEventType {
3535
public:
3636
/// Enumerate the upgrade event types.
3737
enum Value {
38-
/// The upgrade sequence is complete.
39-
e_COMPLETE = 0,
38+
/// The upgrade sequence has been initiated.
39+
e_INITIATED = 0,
4040

4141
/// An error has been detected during the upgrade sequence.
42-
e_ERROR = 1
42+
e_ERROR = 1,
43+
44+
/// The upgrade sequence is complete.
45+
e_COMPLETE = 2
4346
};
4447

4548
/// Return the string representation exactly matching the enumerator

groups/ntc/ntci/ntci_streamsocketsession.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ StreamSocketSession::~StreamSocketSession()
2727
{
2828
}
2929

30+
void StreamSocketSession::processConnectInitiated(
31+
const bsl::shared_ptr<ntci::StreamSocket>& streamSocket,
32+
const ntca::ConnectEvent& event)
33+
{
34+
NTCCFG_WARNING_UNUSED(streamSocket);
35+
NTCCFG_WARNING_UNUSED(event);
36+
}
37+
38+
void StreamSocketSession::processConnectComplete(
39+
const bsl::shared_ptr<ntci::StreamSocket>& streamSocket,
40+
const ntca::ConnectEvent& event)
41+
{
42+
NTCCFG_WARNING_UNUSED(streamSocket);
43+
NTCCFG_WARNING_UNUSED(event);
44+
}
45+
3046
void StreamSocketSession::processReadQueueFlowControlRelaxed(
3147
const bsl::shared_ptr<ntci::StreamSocket>& streamSocket,
3248
const ntca::ReadQueueEvent& event)
@@ -147,6 +163,23 @@ void StreamSocketSession::processDowngradeInitiated(
147163
NTCCFG_WARNING_UNUSED(event);
148164
}
149165

166+
167+
void StreamSocketSession::processDowngradeReceive(
168+
const bsl::shared_ptr<ntci::StreamSocket>& streamSocket,
169+
const ntca::DowngradeEvent& event)
170+
{
171+
NTCCFG_WARNING_UNUSED(streamSocket);
172+
NTCCFG_WARNING_UNUSED(event);
173+
}
174+
175+
void StreamSocketSession::processDowngradeSend(
176+
const bsl::shared_ptr<ntci::StreamSocket>& streamSocket,
177+
const ntca::DowngradeEvent& event)
178+
{
179+
NTCCFG_WARNING_UNUSED(streamSocket);
180+
NTCCFG_WARNING_UNUSED(event);
181+
}
182+
150183
void StreamSocketSession::processDowngradeComplete(
151184
const bsl::shared_ptr<ntci::StreamSocket>& streamSocket,
152185
const ntca::DowngradeEvent& event)

groups/ntc/ntci/ntci_streamsocketsession.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ class StreamSocketSession
5757
/// Destroy this object.
5858
virtual ~StreamSocketSession();
5959

60+
/// Process the condition that a connection is initiated.
61+
virtual void processConnectInitiated(
62+
const bsl::shared_ptr<ntci::StreamSocket>& streamSocket,
63+
const ntca::ConnectEvent& event);
64+
65+
/// Process the condition that a connection is complete.
66+
virtual void processConnectComplete(
67+
const bsl::shared_ptr<ntci::StreamSocket>& streamSocket,
68+
const ntca::ConnectEvent& event);
69+
6070
/// Process the condition that read queue flow control has been relaxed:
6171
/// the socket receive buffer is being automatically copied to the read
6272
/// queue.
@@ -158,6 +168,17 @@ class StreamSocketSession
158168
const bsl::shared_ptr<ntci::StreamSocket>& streamSocket,
159169
const ntca::DowngradeEvent& event);
160170

171+
/// Process the socket being shut down for reading encryption
172+
/// communication.
173+
virtual void processDowngradeReceive(
174+
const bsl::shared_ptr<ntci::StreamSocket>& streamSocket,
175+
const ntca::DowngradeEvent& event);
176+
177+
/// Process the socket being shut down for writing encrypted communication.
178+
virtual void processDowngradeSend(
179+
const bsl::shared_ptr<ntci::StreamSocket>& streamSocket,
180+
const ntca::DowngradeEvent& event);
181+
161182
/// Process the completion of a downgrade from encrypted to unencrypted
162183
/// communication.
163184
virtual void processDowngradeComplete(

groups/ntc/ntcp/ntcp_streamsocket.cpp

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -839,17 +839,33 @@ void StreamSocket::privateCompleteConnect(
839839

840840
NTCI_LOG_TRACE("Connection attempt succeeded");
841841

842+
if (d_session_sp) {
843+
ntcs::Dispatch::announceConnectComplete(
844+
d_session_sp,
845+
self,
846+
connectEvent,
847+
d_sessionStrand_sp,
848+
ntci::Strand::unknown(),
849+
self,
850+
false,
851+
&d_mutex);
852+
853+
if (d_openState.value() != ntcs::OpenState::e_CONNECTED) {
854+
return;
855+
}
856+
}
857+
842858
if (connectCallback) {
843859
connectCallback.dispatch(self,
844860
connectEvent,
845861
d_proactorStrand_sp,
846862
self,
847863
false,
848864
&d_mutex);
849-
}
850865

851-
if (d_openState.value() != ntcs::OpenState::e_CONNECTED) {
852-
return;
866+
if (d_openState.value() != ntcs::OpenState::e_CONNECTED) {
867+
return;
868+
}
853869
}
854870

855871
ntcs::Dispatch::announceEstablished(d_manager_sp,
@@ -1031,6 +1047,18 @@ void StreamSocket::privateFailConnectComplete(
10311047
}
10321048
}
10331049

1050+
if (d_session_sp) {
1051+
ntcs::Dispatch::announceConnectComplete(
1052+
d_session_sp,
1053+
self,
1054+
connectEvent,
1055+
d_sessionStrand_sp,
1056+
ntci::Strand::unknown(),
1057+
self,
1058+
defer,
1059+
&d_mutex);
1060+
}
1061+
10341062
if (connectCallback) {
10351063
connectCallback.dispatch(self,
10361064
connectEvent,
@@ -3348,6 +3376,25 @@ void StreamSocket::processRemoteEndpointResolution(
33483376
d_publicSourceEndpoint = d_systemSourceEndpoint;
33493377
}
33503378

3379+
if (!error) {
3380+
d_systemRemoteEndpoint = endpoint;
3381+
d_publicRemoteEndpoint = endpoint;
3382+
3383+
ntca::ConnectEvent event;
3384+
event.setType(ntca::ConnectEventType::e_INITIATED);
3385+
event.setContext(d_connectContext);
3386+
3387+
ntcs::Dispatch::announceConnectInitiated(
3388+
d_session_sp,
3389+
self,
3390+
event,
3391+
d_sessionStrand_sp,
3392+
ntci::Strand::unknown(),
3393+
self,
3394+
false,
3395+
&d_mutex);
3396+
}
3397+
33513398
if (error) {
33523399
this->privateFailConnect(self, error, false, false);
33533400
}
@@ -3607,6 +3654,25 @@ ntsa::Error StreamSocket::privateRetryConnectToEndpoint(
36073654

36083655
d_publicSourceEndpoint = d_systemSourceEndpoint;
36093656

3657+
d_systemRemoteEndpoint = d_connectEndpoint;
3658+
d_publicRemoteEndpoint = d_connectEndpoint;
3659+
3660+
if (d_session_sp) {
3661+
ntca::ConnectEvent event;
3662+
event.setType(ntca::ConnectEventType::e_INITIATED);
3663+
event.setContext(d_connectContext);
3664+
3665+
ntcs::Dispatch::announceConnectInitiated(
3666+
d_session_sp,
3667+
self,
3668+
event,
3669+
d_sessionStrand_sp,
3670+
ntci::Strand::unknown(),
3671+
self,
3672+
false,
3673+
&d_mutex);
3674+
}
3675+
36103676
return ntsa::Error();
36113677
}
36123678

0 commit comments

Comments
 (0)