@@ -157,13 +157,50 @@ cdef class UVStream(UVBaseTransport):
157
157
else :
158
158
self .__reading_stopped()
159
159
160
+ cdef inline _try_write(self , object data):
161
+ if self ._get_write_buffer_size():
162
+ # Don't try to write anything as we already have some
163
+ # data in the write buffers.
164
+ return
165
+
166
+ cdef:
167
+ ssize_t written
168
+ int fd
169
+ Py_buffer py_buf
170
+
171
+ # Let's try to send the data right away.
172
+
173
+ fd = self ._fileno()
174
+ PyObject_GetBuffer(data, & py_buf, PyBUF_SIMPLE)
175
+ written = system.send(fd, < char * > py_buf.buf, py_buf.len, 0 )
176
+ PyBuffer_Release(& py_buf)
177
+ if written < 0 :
178
+ if errno.errno not in (system.EINTR, system.EAGAIN,
179
+ system.EWOULDBLOCK, system.EINPROGRESS,
180
+ system.EALREADY,
181
+ # If it's a wrong type of FD - let libuv
182
+ # handle it, ignore the error:
183
+ system.ENOTSOCK, system.EBADF,
184
+ system.ENOSYS):
185
+ exc = convert_error(- errno.errno)
186
+ self ._fatal_error(exc, True )
187
+
188
+ return written
189
+
160
190
cdef inline _write(self , object data):
161
191
cdef:
162
192
int err
193
+ int sent
163
194
_StreamWriteContext ctx
164
195
165
196
self ._ensure_alive()
166
197
198
+ sent = self ._try_write(data)
199
+ if sent > 0 :
200
+ if sent == len (data):
201
+ return
202
+ data = data[sent:]
203
+
167
204
ctx = _StreamWriteContext.new(self , data)
168
205
169
206
err = uv.uv_write(& ctx.req,
0 commit comments