This repository was archived by the owner on Sep 27, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +24
-4
lines changed Expand file tree Collapse file tree 3 files changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -204,6 +204,26 @@ Transition ConnectionHandle::FillReadBuffer() {
204
204
Transition result = Transition::NEED_DATA;
205
205
ssize_t bytes_read = 0 ;
206
206
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
+ }
207
227
208
228
// return explicitly
209
229
while (done == false ) {
Original file line number Diff line number Diff line change @@ -54,15 +54,15 @@ void *SelectAllTest(int port) {
54
54
txn1.commit ();
55
55
56
56
pqxx::work txn2 (C);
57
- for (int i = 0 ; i < 20 ; i++) {
57
+ for (int i = 0 ; i < 2000 ; i++) {
58
58
std::string s = " INSERT INTO template VALUES (" + std::to_string (i) + " )" ;
59
59
LOG_INFO (" Start sending query" );
60
60
txn2.exec (s);
61
61
}
62
62
63
63
pqxx::result R = txn2.exec (" SELECT * from template;" );
64
64
txn2.commit ();
65
- EXPECT_EQ (R.size (), 20 );
65
+ EXPECT_EQ (R.size (), 2000 );
66
66
} catch (const std::exception &e) {
67
67
LOG_INFO (" [SelectAllTest] Exception occurred: %s" , e.what ());
68
68
EXPECT_TRUE (false );
Original file line number Diff line number Diff line change @@ -73,15 +73,15 @@ void *BasicTest(int port) {
73
73
txn3.commit ();
74
74
75
75
pqxx::work txn4 (C);
76
- for (int i = 0 ; i < 10 ; i++) {
76
+ for (int i = 0 ; i < 1000 ; i++) {
77
77
std::string s = " INSERT INTO template VALUES (" + std::to_string (i) + " )" ;
78
78
txn4.exec (s);
79
79
}
80
80
81
81
R = txn4.exec (" SELECT * from template;" );
82
82
txn4.commit ();
83
83
84
- EXPECT_EQ (R.size (), 10 );
84
+ EXPECT_EQ (R.size (), 1000 );
85
85
86
86
} catch (const std::exception &e) {
87
87
LOG_INFO (" [SSLTest] Exception occurred: %s" , e.what ());
You can’t perform that action at this time.
0 commit comments