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

Commit fbce639

Browse files
Tianyi Chenapavlo
authored andcommitted
get rid of the hacky flags (again)
1 parent e9bc994 commit fbce639

File tree

2 files changed

+2
-72
lines changed

2 files changed

+2
-72
lines changed

src/include/network/connection_handle.h

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -156,37 +156,6 @@ class ConnectionHandle {
156156
*/
157157
static bool ReadStartupPacketHeader(Buffer &rbuf, InputPacket &rpkt);
158158

159-
/**
160-
* Routine to deal with the first packet from the client
161-
*/
162-
void ProcessInitialPacket(InputPacket *pkt);
163-
164-
/**
165-
* Routine to deal with general Startup message
166-
*/
167-
void ProcessStartupPacket(InputPacket *pkt, int32_t proto_version);
168-
169-
/**
170-
* Routine to deal with SSL request message
171-
*/
172-
void ProcessSSLRequestPacket(InputPacket *pkt);
173-
174-
void SetReadBlockedOnWrite(bool flag) { read_blocked_on_write_ = flag; }
175-
176-
void SetWriteBlockedOnRead(bool flag) { write_blocked_on_read_ = flag; }
177-
178-
bool GetReadBlockedOnWrite() { return read_blocked_on_write_; }
179-
180-
bool GetWriteBlockedOnRead() { return write_blocked_on_read_; }
181-
182-
void SetReadBlocked(bool flag) { read_blocked_ = flag; }
183-
184-
void SetWriteBlocked(bool flag) { write_blocked_ = flag; }
185-
186-
bool GetReadBlocked() { return read_blocked_; }
187-
188-
bool GetWriteBlocked() { return write_blocked_; }
189-
190159
/**
191160
* Writes a packet's header (type, size) into the write buffer
192161
*/
@@ -243,11 +212,7 @@ class ConnectionHandle {
243212
bool ssl_handshake_ = false;
244213
bool finish_startup_packet_ = false;
245214
bool ssl_able_;
246-
247-
bool read_blocked_on_write_ = false;
248-
bool write_blocked_on_read_ = false;
249-
bool read_blocked_ = false;
250-
bool write_blocked_ = false;
215+
251216
// TODO(Tianyi) hide this in protocol handler
252217
InputPacket initial_packet_;
253218

src/network/connection_handle.cpp

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,6 @@ void ConnectionHandle::UpdateEventFlags(short flags) {
171171

172172
WriteState ConnectionHandle::WritePackets() {
173173
// iterate through all the packets
174-
if (GetWriteBlocked())
175-
FlushWriteBuffer();
176174
for (; next_response_ < protocol_handler_->responses.size();
177175
next_response_++) {
178176
auto pkt = protocol_handler_->responses[next_response_].get();
@@ -207,33 +205,6 @@ Transition ConnectionHandle::FillReadBuffer() {
207205
ssize_t bytes_read = 0;
208206
bool done = false;
209207

210-
// If partial SSL record exists in the SSL buffer, call SSL_read()
211-
// to read more data from the network buffer first.
212-
if (!GetReadBlocked()) {
213-
// reset buffer if all the contents have been read
214-
if (rbuf_->buf_ptr == rbuf_->buf_size) rbuf_->Reset();
215-
216-
// buf_ptr shouldn't overflow
217-
PL_ASSERT(rbuf_->buf_ptr <= rbuf_->buf_size);
218-
219-
/* Do we have leftover data and are we at the end of the buffer?
220-
* Move the data to the head of the buffer and clear out all the old data
221-
* Note: The assumption here is that all the packets/headers till
222-
* rbuf_.buf_ptr have been fully processed
223-
*/
224-
if (rbuf_->buf_ptr < rbuf_->buf_size
225-
&& rbuf_->buf_size == rbuf_->GetMaxSize()) {
226-
auto unprocessed_len = rbuf_->buf_size - rbuf_->buf_ptr;
227-
// Move this data to the head of rbuf_1
228-
std::memmove(rbuf_->GetPtr(0),
229-
rbuf_->GetPtr(rbuf_->buf_ptr),
230-
unprocessed_len);
231-
// update pointers
232-
rbuf_->buf_ptr = 0;
233-
rbuf_->buf_size = unprocessed_len;
234-
}
235-
}
236-
237208
// return explicitly
238209
while (done == false) {
239210
if (rbuf_->buf_size == rbuf_->GetMaxSize()) {
@@ -253,8 +224,6 @@ Transition ConnectionHandle::FillReadBuffer() {
253224
// The network buffer becomes empty and data is in SSL buffer. We can't rely on
254225
// libevent read event since the system does not know about the SSL buffer. We need to
255226
// call SSL_pending() to check manually. (See StateMachine)
256-
SetReadBlockedOnWrite(false);
257-
SetReadBlocked(false);
258227
bytes_read = SSL_read(conn_SSL_context, rbuf_->GetPtr(rbuf_->buf_size),
259228
rbuf_->GetMaxSize() - rbuf_->buf_size);
260229
LOG_TRACE("SSL read successfully");
@@ -284,7 +253,6 @@ Transition ConnectionHandle::FillReadBuffer() {
284253
// It happens when we're trying to rehandshake and we block on a write
285254
// during the handshake. We need to wait on the socket to be writable
286255
case SSL_ERROR_WANT_WRITE: {
287-
288256
LOG_TRACE("Rehandshake during write, block until writable");
289257
UpdateEventFlags(EV_WRITE | EV_PERSIST);
290258
return Transition::NEED_DATA;
@@ -345,8 +313,6 @@ WriteState ConnectionHandle::FlushWriteBuffer() {
345313
while (wbuf_->buf_size > 0) {
346314
LOG_TRACE("SSL_write flush");
347315
ERR_clear_error();
348-
SetWriteBlocked(false);
349-
SetWriteBlockedOnRead(false);
350316
written_bytes = SSL_write(conn_SSL_context, &wbuf_->buf[wbuf_->buf_flush_ptr], wbuf_->buf_size);
351317
int err = SSL_get_error(conn_SSL_context, written_bytes);
352318
unsigned long ecode = (err != SSL_ERROR_NONE || written_bytes < 0) ? ERR_get_error() : 0;
@@ -363,13 +329,12 @@ WriteState ConnectionHandle::FlushWriteBuffer() {
363329
// just return WRITE_NOT_READY and keeps the buffer ptr unchanged.
364330
// TODO(Yuchen): Change this. Can't write more packets and update buffer ptr when SSL_write() is not succeeded yet.
365331
case SSL_ERROR_WANT_WRITE: {
366-
SetWriteBlocked(true);
332+
UpdateEventFlags(EV_WRITE | EV_PERSIST);
367333
LOG_TRACE("Flush write buffer, want write, not ready");
368334
return WriteState::NOT_READY;
369335
}
370336
// It happens when doing rehandshake with client.
371337
case SSL_ERROR_WANT_READ: {
372-
SetWriteBlockedOnRead(true);
373338
LOG_TRACE("Flush write buffer, want read, not ready");
374339
return WriteState::NOT_READY;
375340
}

0 commit comments

Comments
 (0)