[issue33307] socket.send() fails to send large amount of bytes

2018-04-18 Thread Kaulkwappe

Kaulkwappe  added the comment:

Thank you for your answer Christian. Indeed it seems a little more complex. As 
I worked with Non-TLS sockets before it looked like unexpected behaviour to me 
as on non-blocking sockets socket.send() would normally return 0 when no data 
was sent.

By the way this is the code I currently use:

Code:

n = 0

while 1:

time.sleep(0.001)

try:

buffer = socket.recv(8192)

if not buffer:
break

except OSError:
print('{0}. try to send:'.format(n), len(blark), 
'bytes')

try:
sent = socket.send(blark)
except ssl.SSLWantWriteError:
sent = 0
n += 1

print('Bytes sent:', sent)

else:
[...]

Result:

1. try to send: 33554469 bytes
Bytes sent: 0

[...]

137. try to send: 33554469 bytes
Bytes sent: 0

138. try to send: 33554469 bytes
Bytes sent: 0

139. try to send: 33554469 bytes
Bytes sent: 33554469

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33307] socket.send() fails to send large amount of bytes

2018-04-18 Thread Christian Heimes

Christian Heimes  added the comment:

The same way as with any other non-blocking I/O system. You have to keep track 
how much data you have already sent and repeat non-blocking send() until you 
have succeeded. With TLS/SSL it's even more complex, because a send() also 
requires reading and a recv() also involves writing.

PS: bugs.python.org is an issue tracker, not a help forum.

--
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33307] socket.send() fails to send large amount of bytes

2018-04-18 Thread Kaulkwappe

Kaulkwappe  added the comment:

But why does socket.send() throws an exception in this case only when sending a 
large amount of bytes? That would mean it is impossible to send large amount of 
bytes over SSL sockets as it would fail everytime.

--
status: closed -> open

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33307] socket.send() fails to send large amount of bytes

2018-04-18 Thread Christian Heimes

Christian Heimes  added the comment:

Inada is correct. This is the expected and documented behavior for non-blocking 
SSLSockets, see https://docs.python.org/3/library/ssl.html#ssl-nonblocking .

--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed
type: crash -> behavior

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33307] socket.send() fails to send large amount of bytes

2018-04-18 Thread Kaulkwappe

Kaulkwappe  added the comment:

Sorry for the misunderstanding, here is the complete example:

socket.setblocking(0)

try:
buffer = socket.recv()

if not buffer:
break

except OSError:
bytes_sent = socket.send(b'a' * 32 * 1024 * 1024)

In this case the socket is ready for sending data and should return the bytes 
that were actually sent. But when sending a large amount of bytes it every time 
fails with SSLWantWriteError exception.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33307] socket.send() fails to send large amount of bytes

2018-04-18 Thread INADA Naoki

INADA Naoki  added the comment:

Isn't it an expected behavior of SSL with nonblocking socket?
What's wrong?

--
nosy: +inada.naoki

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33307] socket.send() fails to send large amount of bytes

2018-04-18 Thread Kaulkwappe

New submission from Kaulkwappe :

socket.setblocking(0)
socket.send(b'a' * 32 * 1024 * 1024)

In the example above socket.send() fails with this error:

Error in connection handler
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/websockets/server.py", line 81, in 
handler
yield from self.ws_handler(self, path)
  File "/var/www/vhosts/.../app/sockets/core/Daemon.py", line 286, in 
websocketClientHandler
self.api.connection.send(data)
  File "/usr/lib/python3.5/ssl.py", line 869, in send
return self._sslobj.write(data)
  File "/usr/lib/python3.5/ssl.py", line 594, in write
return self._sslobj.write(data)
ssl.SSLWantWriteError: The operation did not complete (write) (_ssl.c:1949)

--
assignee: christian.heimes
components: SSL
messages: 315444
nosy: Kaulkwappe, christian.heimes
priority: normal
severity: normal
status: open
title: socket.send() fails to send large amount of bytes
type: crash
versions: Python 3.5

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com