MCPcopy Index your code
hub / github.com/python/cpython / initiate_send

Method initiate_send

Lib/test/support/asynchat.py:231–269  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

229 self.producer_fifo.append(None)
230
231 def initiate_send(self):
232 while self.producer_fifo and self.connected:
233 first = self.producer_fifo[0]
234 # handle empty string/buffer or None entry
235 if not first:
236 del self.producer_fifo[0]
237 if first is None:
238 self.handle_close()
239 return
240
241 # handle classic producer behavior
242 obs = self.ac_out_buffer_size
243 try:
244 data = first[:obs]
245 except TypeError:
246 data = first.more()
247 if data:
248 self.producer_fifo.appendleft(data)
249 else:
250 del self.producer_fifo[0]
251 continue
252
253 if isinstance(data, str) and self.use_encoding:
254 data = bytes(data, self.encoding)
255
256 # send the data
257 try:
258 num_sent = self.send(data)
259 except OSError:
260 self.handle_error()
261 return
262
263 if num_sent:
264 if num_sent < len(data) or obs < len(first):
265 self.producer_fifo[0] = first[num_sent:]
266 else:
267 del self.producer_fifo[0]
268 # we tried to send some actual data
269 return
270
271 def discard_buffers(self):
272 # Emergencies only!

Callers 3

handle_writeMethod · 0.95
pushMethod · 0.95
push_with_producerMethod · 0.95

Calls 4

handle_closeMethod · 0.95
moreMethod · 0.80
sendMethod · 0.45
handle_errorMethod · 0.45

Tested by

no test coverage detected