子类化套接字

扫码查看
socket objects have a little quirk. If you try to receive 0 bytes on ablocking socket, they block. That is, if I call recv(0), it blocks(until some data arrives).I think that''s wrong, but I don''t want to argue that. I would like tocreate a subclass of socket that fixes the problem. Ideally, somethinglike:class new_socket(socket):def recv( self, bufsize, flags=0 ):if bufsize == 0:return ""else:return socket.recv( bufsize, flags )They only problem is, sockets return socket objects via the acceptcall. And the socket returned is of type socket, of course, notnew_socket, as I would like. I could override accept() to return anew_socket, but I don''t know how to convert the old socket to a newsocket. That is, I''d like to add a method to the class above somethinglike:def accept( self ):conn, addr = socket.accept()<convert conn, which is type socket to type new_socket>return ( conn, addr )Does anyone have any suggestions on how to do the above? 解决方案--Best regards,Maksim Kasimovmailto: ma************@gmail.com 这篇关于子类化套接字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-20 09:21
查看更多