Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit 60660f2

Browse files
Tianyi Chenapavlo
authored andcommitted
recover the lines of clearing read buffer that I accidentally removed.
1 parent 7f2419c commit 60660f2

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

src/network/connection_handle.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,26 @@ Transition ConnectionHandle::FillReadBuffer() {
204204
Transition result = Transition::NEED_DATA;
205205
ssize_t bytes_read = 0;
206206
bool done = false;
207+
208+
// reset buffer if all the contents have been read
209+
if (rbuf_->buf_ptr == rbuf_->buf_size) rbuf_->Reset();
210+
211+
// buf_ptr shouldn't overflow
212+
PL_ASSERT(rbuf_->buf_ptr <= rbuf_->buf_size);
213+
214+
/* Do we have leftover data and are we at the end of the buffer?
215+
* Move the data to the head of the buffer and clear out all the old data
216+
* Note: The assumption here is that all the packets/headers till
217+
* rbuf_.buf_ptr have been fully processed
218+
*/
219+
if (rbuf_->buf_ptr < rbuf_->buf_size && rbuf_->buf_size == rbuf_->GetMaxSize()) {
220+
auto unprocessed_len = rbuf_->buf_size - rbuf_->buf_ptr;
221+
// Move this data to the head of rbuf_1
222+
std::memmove(rbuf_->GetPtr(0), rbuf_->GetPtr(rbuf_->buf_ptr), unprocessed_len);
223+
// update pointers
224+
rbuf_->buf_ptr = 0;
225+
rbuf_->buf_size = unprocessed_len;
226+
}
207227

208228
// return explicitly
209229
while (done == false) {

test/network/select_all_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ void *SelectAllTest(int port) {
5454
txn1.commit();
5555

5656
pqxx::work txn2(C);
57-
for (int i = 0; i < 20; i++) {
57+
for (int i = 0; i < 2000; i++) {
5858
std::string s = "INSERT INTO template VALUES (" + std::to_string(i) + ")";
5959
LOG_INFO("Start sending query");
6060
txn2.exec(s);
6161
}
6262

6363
pqxx::result R = txn2.exec("SELECT * from template;");
6464
txn2.commit();
65-
EXPECT_EQ(R.size(), 20);
65+
EXPECT_EQ(R.size(), 2000);
6666
} catch (const std::exception &e) {
6767
LOG_INFO("[SelectAllTest] Exception occurred: %s", e.what());
6868
EXPECT_TRUE(false);

test/network/ssl_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ void *BasicTest(int port) {
7373
txn3.commit();
7474

7575
pqxx::work txn4(C);
76-
for (int i = 0; i < 10; i++) {
76+
for (int i = 0; i < 1000; i++) {
7777
std::string s = "INSERT INTO template VALUES (" + std::to_string(i) + ")";
7878
txn4.exec(s);
7979
}
8080

8181
R = txn4.exec("SELECT * from template;");
8282
txn4.commit();
8383

84-
EXPECT_EQ(R.size(), 10);
84+
EXPECT_EQ(R.size(), 1000);
8585

8686
} catch (const std::exception &e) {
8787
LOG_INFO("[SSLTest] Exception occurred: %s", e.what());

0 commit comments

Comments
 (0)