M2Crypto: select() behaves weird on SSL socket

Irmen de Jong irmen at NOSPAMREMOVETHISxs4all.nl
Mon Jun 10 15:20:21 EDT 2002


A.M. Kuchling wrote:

> Perhaps there really is no more data on the socket because OpenSSL has
> read it all, but the decrypted data is now sitting in a buffer

Sounds like a reasonable explanation. But still, I have a problem then.
I'm using select() to realize a timeout on socket reads (and writes)
(much like timeoutsocket.py does), and I am reading the data on the
socket in chunks. select() is called again before reading the next chunk.

This works nicely with the regular sockets.
It breaks when using M2Crypto SSL sockets.

I can't seem to think of a solution, other than disabling the
timeout function if using SSL...

My software heavily relies on the chunk reading because what
I'm doing is: read a fixed size block that tells how large
the next block is. Then read that next block.


Irmen


PS my reading function:

def _recv_msg(sock,size,timeout):
	msglen=0
	msglist=[]
	while msglen<size:
		# XXX this breaks when using SSL... :-(
		r,w,e=select.select([sock],[],[],timeout)
		if not r:
			raise TimeoutError()
		chunk=sock.recv(size-msglen)
		if not chunk:
			raise ConnectionClosedError()
		msglist.append(chunk)	
		msglen+=len(chunk)
	return ''.join(msglist)




More information about the Python-list mailing list