chenBright commented on code in PR #3535:
URL: https://github.com/apache/brpc/pull/3535#discussion_r4482466914


##########
src/brpc/rdma/rdma_endpoint.cpp:
##########
@@ -821,7 +275,8 @@ friend class RdmaEndpoint;
                     lkey = (uint32_t)meta;
                 }
             }
-            if (BAIDU_UNLIKELY(lkey == 0)) {  // only happens when meta is not 
specified
+            if (BAIDU_UNLIKELY(lkey ==
+                               0)) { // only happens when meta is not specified

Review Comment:
   inline



##########
src/brpc/rdma_transport.cpp:
##########
@@ -30,27 +29,26 @@ DECLARE_bool(usercode_in_pthread);
 
 extern SocketVarsCollector *g_vars;
 
+RdmaTransport* RdmaTransport::Get(const Socket* socket) {
+    const AdapterTransport* adapter = AdapterTransport::Get(socket);
+    Transport* transport = adapter->high_speed_transport();
+    CHECK(transport != nullptr);
+    return static_cast<RdmaTransport*>(transport);
+}
+
 void RdmaTransport::Init(Socket *socket, const SocketOptions &options) {
     CHECK(_rdma_ep == nullptr);
-    if (options.socket_mode == SOCKET_MODE_RDMA) {
-        _rdma_ep = new rdma::RdmaEndpoint(socket);
-        _rdma_state = RDMA_UNKNOWN;
-    } else {
-        _rdma_state = RDMA_OFF;
-        socket->_socket_mode = SOCKET_MODE_TCP;
-    }
     _socket = socket;
     _default_connect = options.app_connect;
-    _on_edge_trigger = options.on_edge_triggered_events;
-    if (options.need_on_edge_trigger && _on_edge_trigger == nullptr) {
-        if (_rdma_ep != nullptr) {
-            _on_edge_trigger = rdma::RdmaEndpoint::OnNewDataFromTcp;
-        } else {
-            _on_edge_trigger = InputMessenger::OnNewMessages;
-        }
+    _on_edge_trigger = nullptr;
+    _rdma_state = RDMA_UNKNOWN;
+    _rdma_ep = new (std::nothrow) rdma::RdmaEndpoint(socket);

Review Comment:
   No need to use `std::nothrow`.



##########
src/brpc/handshake/handshake_io.cpp:
##########
@@ -0,0 +1,145 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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.
+
+#include "brpc/handshake/handshake_io.h"
+
+#include <cstdint>
+#include <errno.h>
+#include <unistd.h>
+
+#include "bthread/butex.h"
+#include "butil/time.h"
+#include "brpc/errno.pb.h"
+#include "brpc/socket.h"
+
+namespace brpc {
+namespace handshake {
+
+static const int WAIT_TIMEOUT_MS = 50;
+
+SocketHandshakeIO::SocketHandshakeIO(Socket* socket)
+    : _socket(socket)
+    , _read_butex(bthread::butex_create_checked<butil::atomic<int> >()) {
+    _read_butex->store(0, butil::memory_order_relaxed);
+}
+
+SocketHandshakeIO::~SocketHandshakeIO() {
+    bthread::butex_destroy(_read_butex);
+}
+
+void SocketHandshakeIO::Reset(Socket* socket) {
+    _socket = socket;
+}
+
+void SocketHandshakeIO::NotifyReadable() {
+    _read_butex->fetch_add(1, butil::memory_order_release);
+    bthread::butex_wake(_read_butex);
+}
+
+int SocketHandshakeIO::ReadExact(void* data, size_t len) {
+    CHECK(data != nullptr);
+    CHECK(_socket != nullptr);
+    const int fd = _socket->fd();
+    const SocketId socket_id = _socket->id();
+    size_t received = 0;
+    while (received < len) {
+        SocketUniquePtr alive;
+        if (Socket::Address(socket_id, &alive) != 0) {
+            errno = EFAILEDSOCKET;
+            return -1;
+        }

Review Comment:
   Why is it necessary to re-address this?



##########
src/brpc/handshake/handshake_io.cpp:
##########
@@ -0,0 +1,145 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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.
+
+#include "brpc/handshake/handshake_io.h"
+
+#include <cstdint>
+#include <errno.h>
+#include <unistd.h>
+
+#include "bthread/butex.h"
+#include "butil/time.h"
+#include "brpc/errno.pb.h"
+#include "brpc/socket.h"
+
+namespace brpc {
+namespace handshake {
+
+static const int WAIT_TIMEOUT_MS = 50;
+
+SocketHandshakeIO::SocketHandshakeIO(Socket* socket)
+    : _socket(socket)
+    , _read_butex(bthread::butex_create_checked<butil::atomic<int> >()) {
+    _read_butex->store(0, butil::memory_order_relaxed);
+}
+
+SocketHandshakeIO::~SocketHandshakeIO() {
+    bthread::butex_destroy(_read_butex);
+}
+
+void SocketHandshakeIO::Reset(Socket* socket) {
+    _socket = socket;
+}
+
+void SocketHandshakeIO::NotifyReadable() {
+    _read_butex->fetch_add(1, butil::memory_order_release);
+    bthread::butex_wake(_read_butex);
+}
+
+int SocketHandshakeIO::ReadExact(void* data, size_t len) {
+    CHECK(data != nullptr);
+    CHECK(_socket != nullptr);
+    const int fd = _socket->fd();
+    const SocketId socket_id = _socket->id();
+    size_t received = 0;
+    while (received < len) {
+        SocketUniquePtr alive;
+        if (Socket::Address(socket_id, &alive) != 0) {
+            errno = EFAILEDSOCKET;
+            return -1;
+        }
+        const int expected = _read_butex->load(butil::memory_order_acquire);
+        const timespec duetime = butil::milliseconds_from_now(WAIT_TIMEOUT_MS);
+        const ssize_t nr = read(
+            fd, static_cast<uint8_t*>(data) + received, len - received);
+        if (nr < 0) {
+            if (errno == EINTR) {
+                continue;
+            }
+            if (errno != EAGAIN) {
+                return -1;
+            }
+            if (bthread::butex_wait(_read_butex, expected, &duetime) < 0 &&
+                errno != EWOULDBLOCK && errno != ETIMEDOUT) {
+                return -1;
+            }
+        } else if (nr == 0) {
+            errno = EEOF;
+            return -1;
+        } else {
+            received += nr;
+        }
+    }
+    return 0;
+}
+
+int SocketHandshakeIO::WriteAll(const void* data, size_t len) {
+    CHECK(data != nullptr);
+    CHECK(_socket != nullptr);
+    const int fd = _socket->fd();
+    const SocketId socket_id = _socket->id();
+    size_t written = 0;
+    while (written < len) {
+        SocketUniquePtr alive;
+        if (Socket::Address(socket_id, &alive) != 0) {
+            errno = EFAILEDSOCKET;
+            return -1;

Review Comment:
   Same as above.



##########
src/brpc/rdma/rdma_endpoint.cpp:
##########
@@ -1918,8 +1345,8 @@ int RdmaEndpoint::GlobalInitialize() {
 
     g_rdma_resource_mutex = new butil::Mutex;
     for (int i = 0; i < FLAGS_rdma_prepared_qp_cnt; ++i) {
-        RdmaResource* res = AllocateQpCq(FLAGS_rdma_prepared_qp_size,
-                                         FLAGS_rdma_prepared_qp_size);
+        RdmaResource *res =

Review Comment:
   `RdmaResource *` -> `RdmaResource*`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to