[REV] close_socket is back in netsvc.py

bzr revid: chs@openerp.com-20121210132133-m1z2hb72y1r1wsei
This commit is contained in:
Christophe Simonis 2012-12-10 14:21:33 +01:00
parent b0c9f525ce
commit 507c02aaa2
2 changed files with 20 additions and 23 deletions

View File

@ -20,6 +20,9 @@
#
##############################################################################
#.apidoc title: Common Services: netsvc
#.apidoc module-mods: member-order: bysource
import errno
import logging
import logging.handlers
@ -41,9 +44,23 @@ import openerp
_logger = logging.getLogger(__name__)
def close_socket(sock):
""" Closes a socket instance cleanly
#.apidoc title: Common Services: netsvc
#.apidoc module-mods: member-order: bysource
:param sock: the network socket to close
:type sock: socket.socket
"""
try:
sock.shutdown(socket.SHUT_RDWR)
except socket.error, e:
# On OSX, socket shutdowns both sides if any side closes it
# causing an error 57 'Socket is not connected' on shutdown
# of the other side (or something), see
# http://bugs.python.org/issue4397
# note: stdlib fixed test, not behavior
if e.errno != errno.ENOTCONN or platform.system() not in ['Darwin', 'Windows']:
raise
sock.close()
def abort_response(dummy_1, description, dummy_2, details):
# TODO Replace except_{osv,orm} with these directly.

View File

@ -22,8 +22,6 @@
#.apidoc title: NET-RPC Server
""" This file contains instance of the net-rpc server
"""
import logging
import select
@ -38,24 +36,6 @@ import openerp.tools as tools
_logger = logging.getLogger(__name__)
def close_socket(sock):
""" Closes a socket instance cleanly
:param sock: the network socket to close
:type sock: socket.socket
"""
try:
sock.shutdown(socket.SHUT_RDWR)
except socket.error, e:
# On OSX, socket shutdowns both sides if any side closes it
# causing an error 57 'Socket is not connected' on shutdown
# of the other side (or something), see
# http://bugs.python.org/issue4397
# note: stdlib fixed test, not behavior
if e.errno != errno.ENOTCONN or platform.system() not in ['Darwin', 'Windows']:
raise
sock.close()
class Server:
""" Generic interface for all servers with an event loop etc.
Override this to impement http, net-rpc etc. servers.
@ -133,7 +113,7 @@ class Server:
return '\n'.join(res)
def _close_socket(self):
close_socket(self.socket)
netsvc.close_socket(self.socket)
class TinySocketClientThread(threading.Thread):
def __init__(self, sock, threads):