def _wait_for_send_window(self, size):
<EOL>if self.closed or self.eof_sent:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>if self.out_window_size == <NUM_LIT:0>:<EOL><INDENT>if self.timeout == <NUM_LIT:0.0>:<EOL><INDENT>raise socket.timeout()<EOL><DEDENT>timeout = self.timeout<EOL>while self.out_window_size == <NUM_LIT:0>:<EOL><INDENT>if self.closed or self.eof_sent:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>then = time.time()<EOL>self.out_buffer_cv.wait(timeout)<EOL>if timeout is not None:<EOL><INDENT>timeout -= time.time() - then<EOL>if timeout <= <NUM_LIT:0.0>:<EOL><INDENT>raise socket.timeout()<EOL><DEDENT><DEDENT><DEDENT><DEDENT>if self.closed or self.eof_sent:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>if self.out_window_size < size:<EOL><INDENT>size = self.out_window_size<EOL><DEDENT>if self.out_max_packet_size - <NUM_LIT:64> < size:<EOL><INDENT>size = self.out_max_packet_size - <NUM_LIT:64><EOL><DEDENT>self.out_window_size -= size<EOL>if self.ultra_debug:<EOL><INDENT>self._log(DEBUG, "<STR_LIT>".format(self.out_window_size))<EOL><DEDENT>return size<EOL>
(You are already holding the lock.)
Wait for the send window to open up, and allocate up to ``size`` bytes
for transmission.  If no space opens up before the timeout, a timeout
exception is raised.  Returns the number of bytes available to send
(may be less than requested).