|
29 | 29 | #include "brpc/protocol.h" // ListProtocols |
30 | 30 | #include "brpc/rdma/rdma_endpoint.h" |
31 | 31 | #include "brpc/input_messenger.h" |
32 | | - |
| 32 | +#include "brpc/transport_factory.h" |
33 | 33 |
|
34 | 34 | namespace brpc { |
35 | 35 |
|
@@ -112,8 +112,7 @@ ParseResult InputMessenger::CutInputMessage( |
112 | 112 | // The length of `data' must be PROTO_DUMMY_LEN + 1 to store extra ending char '\0' |
113 | 113 | char data[PROTO_DUMMY_LEN + 1]; |
114 | 114 | m->_read_buf.copy_to_cstr(data, PROTO_DUMMY_LEN); |
115 | | - if (strncmp(data, "RDMA", PROTO_DUMMY_LEN) == 0 && |
116 | | - m->_rdma_state == Socket::RDMA_OFF) { |
| 115 | + if (strncmp(data, "RDMA", PROTO_DUMMY_LEN) == 0) { |
117 | 116 | // To avoid timeout when client uses RDMA but server uses TCP |
118 | 117 | return MakeParseError(PARSE_ERROR_TRY_OTHERS); |
119 | 118 | } |
@@ -191,46 +190,13 @@ struct RunLastMessage { |
191 | 190 | } |
192 | 191 | }; |
193 | 192 |
|
194 | | -static void QueueMessage(InputMessageBase* to_run_msg, |
195 | | - int* num_bthread_created, |
196 | | - bthread_keytable_pool_t* keytable_pool) { |
197 | | - if (!to_run_msg) { |
198 | | - return; |
199 | | - } |
200 | | - |
201 | | -#if BRPC_WITH_RDMA |
202 | | - if (rdma::FLAGS_rdma_disable_bthread) { |
203 | | - ProcessInputMessage(to_run_msg); |
204 | | - return; |
205 | | - } |
206 | | -#endif |
207 | | - // Create bthread for last_msg. The bthread is not scheduled |
208 | | - // until bthread_flush() is called (in the worse case). |
209 | | - |
210 | | - // TODO(gejun): Join threads. |
211 | | - bthread_t th; |
212 | | - bthread_attr_t tmp = (FLAGS_usercode_in_pthread ? |
213 | | - BTHREAD_ATTR_PTHREAD : |
214 | | - BTHREAD_ATTR_NORMAL) | BTHREAD_NOSIGNAL; |
215 | | - tmp.keytable_pool = keytable_pool; |
216 | | - tmp.tag = bthread_self_tag(); |
217 | | - bthread_attr_set_name(&tmp, "ProcessInputMessage"); |
218 | | - |
219 | | - if (!FLAGS_usercode_in_coroutine && bthread_start_background( |
220 | | - &th, &tmp, ProcessInputMessage, to_run_msg) == 0) { |
221 | | - ++*num_bthread_created; |
222 | | - } else { |
223 | | - ProcessInputMessage(to_run_msg); |
224 | | - } |
225 | | -} |
226 | | - |
227 | | -InputMessenger::InputMessageClosure::~InputMessageClosure() noexcept(false) { |
| 193 | +InputMessageClosure::~InputMessageClosure() noexcept(false) { |
228 | 194 | if (_msg) { |
229 | 195 | ProcessInputMessage(_msg); |
230 | 196 | } |
231 | 197 | } |
232 | 198 |
|
233 | | -void InputMessenger::InputMessageClosure::reset(InputMessageBase* m) { |
| 199 | +void InputMessageClosure::reset(InputMessageBase* m) { |
234 | 200 | if (_msg) { |
235 | 201 | ProcessInputMessage(_msg); |
236 | 202 | } |
@@ -303,7 +269,7 @@ int InputMessenger::ProcessNewMessage( |
303 | 269 | // This unique_ptr prevents msg to be lost before transfering |
304 | 270 | // ownership to last_msg |
305 | 271 | DestroyingPtr<InputMessageBase> msg(pr.message()); |
306 | | - QueueMessage(last_msg.release(), &num_bthread_created, m->_keytable_pool); |
| 272 | + m->_transport->QueueMessage(last_msg, &num_bthread_created, false); |
307 | 273 | if (_handlers[index].process == NULL) { |
308 | 274 | LOG(ERROR) << "process of index=" << index << " is NULL"; |
309 | 275 | continue; |
@@ -336,22 +302,19 @@ int InputMessenger::ProcessNewMessage( |
336 | 302 | // Transfer ownership to last_msg |
337 | 303 | last_msg.reset(msg.release()); |
338 | 304 | } else { |
339 | | - QueueMessage(msg.release(), &num_bthread_created, |
340 | | - m->_keytable_pool); |
| 305 | + last_msg.reset(msg.release()); |
| 306 | + m->_transport->QueueMessage(last_msg, &num_bthread_created, false); |
341 | 307 | bthread_flush(); |
342 | 308 | num_bthread_created = 0; |
343 | 309 | } |
344 | 310 | } |
345 | | -#if BRPC_WITH_RDMA |
346 | 311 | // In RDMA polling mode, all messages must be executed in a new bthread and |
347 | 312 | // not in the bthread where the polling bthread is located, because the |
348 | 313 | // method for processing messages may call synchronization primitives, |
349 | 314 | // causing the polling bthread to be scheduled out. |
350 | | - if (rdma::FLAGS_rdma_use_polling) { |
351 | | - QueueMessage(last_msg.release(), &num_bthread_created, |
352 | | - m->_keytable_pool); |
| 315 | + if (m->_socket_mode == SOCKET_MODE_RDMA) { |
| 316 | + m->_transport->QueueMessage(last_msg, &num_bthread_created, true); |
353 | 317 | } |
354 | | -#endif |
355 | 318 | if (num_bthread_created) { |
356 | 319 | bthread_flush(); |
357 | 320 | } |
@@ -414,8 +377,7 @@ void InputMessenger::OnNewMessages(Socket* m) { |
414 | 377 | } |
415 | 378 | } |
416 | 379 |
|
417 | | - if (m->_rdma_state == Socket::RDMA_OFF && messenger->ProcessNewMessage( |
418 | | - m, nr, read_eof, received_us, base_realtime, last_msg) < 0) { |
| 380 | + if (messenger->ProcessNewMessage(m, nr, read_eof, received_us, base_realtime, last_msg) < 0) { |
419 | 381 | return; |
420 | 382 | } |
421 | 383 | } |
@@ -533,16 +495,7 @@ int InputMessenger::Create(const butil::EndPoint& remote_side, |
533 | 495 |
|
534 | 496 | int InputMessenger::Create(SocketOptions options, SocketId* id) { |
535 | 497 | options.user = this; |
536 | | -#if BRPC_WITH_RDMA |
537 | | - if (options.use_rdma) { |
538 | | - options.on_edge_triggered_events = rdma::RdmaEndpoint::OnNewDataFromTcp; |
539 | | - options.app_connect = std::make_shared<rdma::RdmaConnect>(); |
540 | | - } else { |
541 | | -#else |
542 | | - { |
543 | | -#endif |
544 | | - options.on_edge_triggered_events = OnNewMessages; |
545 | | - } |
| 498 | + options.need_on_edge_trigger = true; |
546 | 499 | // Enable keepalive by options or Gflag. |
547 | 500 | // Priority: options > Gflag. |
548 | 501 | if (options.keepalive_options || FLAGS_socket_keepalive) { |
|
0 commit comments