| 116 | } |
| 117 | |
| 118 | int ProgressiveAttachment::Write(const butil::IOBuf& data) { |
| 119 | if (data.empty()) { |
| 120 | LOG_EVERY_SECOND(WARNING) |
| 121 | << "Write an empty chunk. To suppress this warning, check emptiness" |
| 122 | " of the chunk before calling ProgressiveAttachment.Write()"; |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | int rpc_state = _rpc_state.load(butil::memory_order_acquire); |
| 127 | if (rpc_state == RPC_RUNNING) { |
| 128 | std::unique_lock<butil::Mutex> mu(_mutex); |
| 129 | rpc_state = _rpc_state.load(butil::memory_order_acquire); |
| 130 | if (rpc_state == RPC_RUNNING) { |
| 131 | if (_saved_buf.size() >= (size_t)FLAGS_socket_max_unwritten_bytes || |
| 132 | _pause_from_mark_rpc_as_done) { |
| 133 | errno = EOVERCROWDED; |
| 134 | return -1; |
| 135 | } |
| 136 | AppendAsChunk(&_saved_buf, data, _before_http_1_1); |
| 137 | return 0; |
| 138 | } |
| 139 | } |
| 140 | // The RPC is already done (http headers were written into the socket) |
| 141 | // write into the socket directly. |
| 142 | if (rpc_state == RPC_SUCCEED) { |
| 143 | butil::IOBuf tmpbuf; |
| 144 | AppendAsChunk(&tmpbuf, data, _before_http_1_1); |
| 145 | return _httpsock->Write(&tmpbuf); |
| 146 | } else { |
| 147 | errno = ECANCELED; |
| 148 | return -1; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | int ProgressiveAttachment::Write(const void* data, size_t n) { |
| 153 | if (data == NULL || n == 0) { |
no test coverage detected