MCPcopy Create free account
hub / github.com/apache/brpc / Write

Method Write

src/brpc/progressive_attachment.cpp:118–150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

116}
117
118int 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
152int ProgressiveAttachment::Write(const void* data, size_t n) {
153 if (data == NULL || n == 0) {

Callers 2

MarkRPCAsDoneMethod · 0.45

Calls 4

AppendAsChunkFunction · 0.85
emptyMethod · 0.45
loadMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected