@@ -171,8 +171,6 @@ void ConnectionHandle::UpdateEventFlags(short flags) {
171
171
172
172
WriteState ConnectionHandle::WritePackets () {
173
173
// iterate through all the packets
174
- if (GetWriteBlocked ())
175
- FlushWriteBuffer ();
176
174
for (; next_response_ < protocol_handler_->responses .size ();
177
175
next_response_++) {
178
176
auto pkt = protocol_handler_->responses [next_response_].get ();
@@ -207,33 +205,6 @@ Transition ConnectionHandle::FillReadBuffer() {
207
205
ssize_t bytes_read = 0 ;
208
206
bool done = false ;
209
207
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
-
237
208
// return explicitly
238
209
while (done == false ) {
239
210
if (rbuf_->buf_size == rbuf_->GetMaxSize ()) {
@@ -253,8 +224,6 @@ Transition ConnectionHandle::FillReadBuffer() {
253
224
// The network buffer becomes empty and data is in SSL buffer. We can't rely on
254
225
// libevent read event since the system does not know about the SSL buffer. We need to
255
226
// call SSL_pending() to check manually. (See StateMachine)
256
- SetReadBlockedOnWrite (false );
257
- SetReadBlocked (false );
258
227
bytes_read = SSL_read (conn_SSL_context, rbuf_->GetPtr (rbuf_->buf_size ),
259
228
rbuf_->GetMaxSize () - rbuf_->buf_size );
260
229
LOG_TRACE (" SSL read successfully" );
@@ -284,7 +253,6 @@ Transition ConnectionHandle::FillReadBuffer() {
284
253
// It happens when we're trying to rehandshake and we block on a write
285
254
// during the handshake. We need to wait on the socket to be writable
286
255
case SSL_ERROR_WANT_WRITE: {
287
-
288
256
LOG_TRACE (" Rehandshake during write, block until writable" );
289
257
UpdateEventFlags (EV_WRITE | EV_PERSIST);
290
258
return Transition::NEED_DATA;
@@ -345,8 +313,6 @@ WriteState ConnectionHandle::FlushWriteBuffer() {
345
313
while (wbuf_->buf_size > 0 ) {
346
314
LOG_TRACE (" SSL_write flush" );
347
315
ERR_clear_error ();
348
- SetWriteBlocked (false );
349
- SetWriteBlockedOnRead (false );
350
316
written_bytes = SSL_write (conn_SSL_context, &wbuf_->buf [wbuf_->buf_flush_ptr ], wbuf_->buf_size );
351
317
int err = SSL_get_error (conn_SSL_context, written_bytes);
352
318
unsigned long ecode = (err != SSL_ERROR_NONE || written_bytes < 0 ) ? ERR_get_error () : 0 ;
@@ -363,13 +329,12 @@ WriteState ConnectionHandle::FlushWriteBuffer() {
363
329
// just return WRITE_NOT_READY and keeps the buffer ptr unchanged.
364
330
// TODO(Yuchen): Change this. Can't write more packets and update buffer ptr when SSL_write() is not succeeded yet.
365
331
case SSL_ERROR_WANT_WRITE: {
366
- SetWriteBlocked ( true );
332
+ UpdateEventFlags (EV_WRITE | EV_PERSIST );
367
333
LOG_TRACE (" Flush write buffer, want write, not ready" );
368
334
return WriteState::NOT_READY;
369
335
}
370
336
// It happens when doing rehandshake with client.
371
337
case SSL_ERROR_WANT_READ: {
372
- SetWriteBlockedOnRead (true );
373
338
LOG_TRACE (" Flush write buffer, want read, not ready" );
374
339
return WriteState::NOT_READY;
375
340
}
0 commit comments