| 360 | } |
| 361 | |
| 362 | void Stream::SetRemoteConsumed(size_t new_remote_consumed) { |
| 363 | CHECK(_cur_buf_size > 0); |
| 364 | bthread_id_list_t tmplist; |
| 365 | bthread_id_list_init(&tmplist, 0, 0); |
| 366 | bthread_mutex_lock(&_congestion_control_mutex); |
| 367 | if (_remote_consumed >= new_remote_consumed) { |
| 368 | bthread_mutex_unlock(&_congestion_control_mutex); |
| 369 | return; |
| 370 | } |
| 371 | const bool was_full = _produced >= _remote_consumed + _cur_buf_size; |
| 372 | |
| 373 | if (FLAGS_socket_max_streams_unconsumed_bytes > 0) { |
| 374 | _host_socket->_total_streams_unconsumed_size -= new_remote_consumed - _remote_consumed; |
| 375 | if (_host_socket->_total_streams_unconsumed_size > FLAGS_socket_max_streams_unconsumed_bytes) { |
| 376 | if (_options.min_buf_size > 0) { |
| 377 | _cur_buf_size = _options.min_buf_size; |
| 378 | } else { |
| 379 | _cur_buf_size /= 2; |
| 380 | } |
| 381 | LOG(INFO) << "stream consumers on socket " << _host_socket->id() << " is crowded, " << "cut stream " << id() << " buffer to " << _cur_buf_size; |
| 382 | } else if (_produced >= new_remote_consumed + _cur_buf_size && (_options.max_buf_size <= 0 || _cur_buf_size < (size_t)_options.max_buf_size)) { |
| 383 | if (_options.max_buf_size > 0 && _cur_buf_size * 2 > (size_t)_options.max_buf_size) { |
| 384 | _cur_buf_size = _options.max_buf_size; |
| 385 | } else { |
| 386 | _cur_buf_size *= 2; |
| 387 | } |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | _remote_consumed = new_remote_consumed; |
| 392 | const bool is_full = _produced >= _remote_consumed + _cur_buf_size; |
| 393 | if (was_full && !is_full) { |
| 394 | bthread_id_list_swap(&tmplist, &_writable_wait_list); |
| 395 | } |
| 396 | bthread_mutex_unlock(&_congestion_control_mutex); |
| 397 | |
| 398 | // broadcast |
| 399 | bthread_id_list_reset(&tmplist, 0); |
| 400 | bthread_id_list_destroy(&tmplist); |
| 401 | } |
| 402 | |
| 403 | void* Stream::RunOnWritable(void* arg) { |
| 404 | WritableMeta *wm = (WritableMeta*)arg; |
nothing calls this directly
no test coverage detected