You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@geode.apache.org by GitBox <gi...@apache.org> on 2022/05/12 14:07:44 UTC

[GitHub] [geode-native] pivotal-jbarrett commented on a diff in pull request #970: GEODE-10300: C++ native client: Allow locator responses greater than …

pivotal-jbarrett commented on code in PR #970:
URL: https://github.com/apache/geode-native/pull/970#discussion_r871422678


##########
cppcache/src/StreamDataInput.cpp:
##########
@@ -0,0 +1,98 @@
+/*
+ * 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 "StreamDataInput.hpp"
+
+#include <geode/DataInput.hpp>
+
+#include "Utils.hpp"
+#include "util/Log.hpp"
+
+namespace apache {
+namespace geode {
+namespace client {
+
+const size_t BUFF_SIZE = 3000;
+
+StreamDataInput::StreamDataInput(std::chrono::milliseconds timeout,
+                                 std::unique_ptr<Connector> connector,
+                                 const CacheImpl* cache, Pool* pool)
+    : DataInput(nullptr, 0, cache, pool) {
+  m_remainingTimeBeforeTimeout = timeout;
+  m_connector = std::move(connector);
+  m_buf = nullptr;
+  m_bufHead = m_buf;
+  m_bufLength = 0;
+}
+
+StreamDataInput::~StreamDataInput() {
+  if (m_bufHead != nullptr) {
+    free(const_cast<uint8_t*>(m_bufHead));
+  }
+}
+
+void StreamDataInput::readDataIfNotAvailable(size_t size) {
+  char buff[BUFF_SIZE];
+  while ((m_bufLength - (m_buf - m_bufHead)) < size) {
+    const auto start = std::chrono::system_clock::now();
+
+    const auto receivedLength = m_connector->receive_nothrowiftimeout(
+        buff, BUFF_SIZE,
+        std::chrono::duration_cast<std::chrono::milliseconds>(
+            m_remainingTimeBeforeTimeout));
+
+    const auto timeSpent = std::chrono::system_clock::now() - start;
+
+    m_remainingTimeBeforeTimeout -=
+        std::chrono::duration_cast<decltype(m_remainingTimeBeforeTimeout)>(
+            timeSpent);
+
+    LOGDEBUG(
+        "received %d bytes from %s: %s, time spent: "
+        "%ld microsecs, time remaining before timeout: %ld microsecs",
+        receivedLength, m_connector->getRemoteEndpoint().c_str(),
+        Utils::convertBytesToString(reinterpret_cast<uint8_t*>(buff),
+                                    receivedLength)
+            .c_str(),
+        std::chrono::duration_cast<std::chrono::microseconds>(timeSpent)
+            .count(),
+        std::chrono::duration_cast<std::chrono::microseconds>(
+            m_remainingTimeBeforeTimeout)
+            .count());
+
+    if (m_remainingTimeBeforeTimeout <= std::chrono::microseconds ::zero()) {
+      throw(TimeoutException(std::string("Timeout when receiving from ")
+                                 .append(m_connector->getRemoteEndpoint())));
+    }
+
+    size_t newLength = m_bufLength + receivedLength;

Review Comment:
   `auto`



##########
cppcache/src/StreamDataInput.hpp:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#ifndef GEODE_STREAMDATAINPUT_H_
+#define GEODE_STREAMDATAINPUT_H_
+
+#include <chrono>
+
+#include "Connector.hpp"
+#include "geode/DataInput.hpp"
+
+/**

Review Comment:
   Delete these this comment since it provides no useful in formation.



##########
cppcache/src/StreamDataInput.cpp:
##########
@@ -0,0 +1,98 @@
+/*
+ * 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 "StreamDataInput.hpp"
+
+#include <geode/DataInput.hpp>
+
+#include "Utils.hpp"
+#include "util/Log.hpp"
+
+namespace apache {
+namespace geode {
+namespace client {
+
+const size_t BUFF_SIZE = 3000;
+
+StreamDataInput::StreamDataInput(std::chrono::milliseconds timeout,
+                                 std::unique_ptr<Connector> connector,
+                                 const CacheImpl* cache, Pool* pool)
+    : DataInput(nullptr, 0, cache, pool) {
+  m_remainingTimeBeforeTimeout = timeout;
+  m_connector = std::move(connector);
+  m_buf = nullptr;
+  m_bufHead = m_buf;
+  m_bufLength = 0;
+}
+
+StreamDataInput::~StreamDataInput() {
+  if (m_bufHead != nullptr) {
+    free(const_cast<uint8_t*>(m_bufHead));

Review Comment:
   Let's use `std::unique_ptr` for automatic ownership and lifecycle management.



##########
cppcache/src/StreamDataInput.cpp:
##########
@@ -0,0 +1,98 @@
+/*
+ * 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 "StreamDataInput.hpp"
+
+#include <geode/DataInput.hpp>
+
+#include "Utils.hpp"
+#include "util/Log.hpp"
+
+namespace apache {
+namespace geode {
+namespace client {
+
+const size_t BUFF_SIZE = 3000;

Review Comment:
   Google convention is `kBufferSize`.



##########
cppcache/src/StreamDataInput.hpp:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#ifndef GEODE_STREAMDATAINPUT_H_
+#define GEODE_STREAMDATAINPUT_H_
+
+#include <chrono>
+
+#include "Connector.hpp"
+#include "geode/DataInput.hpp"
+
+/**
+ * @file
+ */
+
+namespace apache {
+namespace geode {
+namespace client {
+
+#include "geode/DataInput.hpp"

Review Comment:
   duplicate include.



##########
cppcache/include/geode/DataInput.hpp:
##########
@@ -502,7 +502,7 @@ class APACHE_GEODE_EXPORT DataInput {
 
   inline char readPdxChar() { return static_cast<char>(readInt16()); }
 
-  inline void _checkBufferSize(size_t size, int32_t line) {
+  virtual inline void _checkBufferSize(size_t size, int32_t line) {

Review Comment:
   Having a mix of inline and virtual attributes produces some really interesting unknown behavior. 



-- 
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: notifications-unsubscribe@geode.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org