Internal method to drive progress based on the current state.
108 {
109 auto result = std::optional<Target::ReadResult>{std::nullopt};
110
112 overloaded{
115 {
116 try
117 {
119
120
121 if (event && event->isConnReq())
122 {
124 MXL_INFO(
"Accept connection from: {}", remoteAddr.toString());
125
130 endpoint.bind(cq, FI_RECV);
131
133 endpoint.bind(eq);
134
135
136 endpoint.accept();
137 MXL_DEBUG(
"Accepted the connection waiting for connected event notification.");
138
139
140 return RCTarget::WaitForConnection{std::move(endpoint)};
141 }
142
143 return state;
144 }
145 catch (FabricException const& ex)
146 {
147 if (ex.isInterrupted())
148 {
149 result = std::make_optional<Target::Interrupted>();
150 return state;
151 }
152
153 throw;
154 }
155 },
157 {
158 try
159 {
161
162 if (event && event->isConnected())
163 {
164 MXL_INFO(
"Received connected event notification, now connected.");
165
166
167 auto connected =
Connected{.ep = std::move(state.ep)};
168
169
170 _proto->start(connected.ep);
171
172 return connected;
173 }
174
176 }
177 catch (FabricException const& ex)
178 {
179 if (ex.isInterrupted())
180 {
181 result = std::make_optional<Target::Interrupted>();
183 }
184
185 throw;
186 }
187 },
188 [&](RCTarget::Connected state) ->
State
189 {
190 try
191 {
193
194
195 if (completion)
196 {
197 result =
_proto->read(state.ep, *completion);
198 }
199
200 if (event && event.value().isShutdown())
201 {
202 MXL_INFO(
"Remote endpoint has shutdown the connection.");
204 "Failed to shut down the endpoint after the remote endpoint closed it");
205 return Draining{.ep = std::move(state.ep)};
206 }
207
208 return Connected{.ep = std::move(state.ep)};
209 }
210 catch (FabricException const& ex)
211 {
212 if (ex.isInterrupted())
213 {
214 result = std::make_optional<Target::Interrupted>();
215 return Connected{.ep = std::move(state.ep)};
216 }
217
218 throw;
219 }
220 },
221 [&](RCTarget::Draining state) ->
State {
return drain(std::move(state), result); },
223 },
225
226 return result;
227 }
static std::shared_ptr< CompletionQueue > open(std::shared_ptr< Domain > domain, Attributes const &attr=Attributes::defaults())
Create a new completion queue in the specified domain.
static Endpoint create(std::shared_ptr< Domain > domain, FabricInfoView info)
Allocates (active) new endpoint.
static Exception invalidState(fmt::format_string< T... > fmt, T &&... args)
Make an MXL_ERR_INVALID_STATE exception.
static FabricAddress fromDestination(FabricInfoView info) noexcept
Build a FabricAddress from the destination address of info.
State drain(Draining state, std::optional< Target::ReadResult > &result)
Read the completions that are left after the Initiator closed the connection.
std::variant< WaitForConnectionRequest, WaitForConnection, Connected, Draining, Closed > State
The internal state of the RCTarget.
std::optional< Event > readEventQueue(EventQueue &eq, std::chrono::steady_clock::duration timeout)
Helper to read an event queue with blocking or non-blocking behaviour.
std::pair< std::optional< Completion >, std::optional< Event > > readEndpointQueues(Endpoint &ep, std::chrono::steady_clock::duration timeout)
Helper to read both completion and event queues of an endpoint with blocking or non-blocking behaviou...
void catchAndLogFabricError(F &&fun, std::string_view msg)
static constexpr std::size_t DEFAULT_SIZE
The completion-queue depth used when no explicit depth is requested.
static Attributes defaults()
Returns the a CompletionQueueAttr with all of its attributes set to reasonable defaults.
The wait for connection state.