[REV] close_socket is back in netsvc.py
bzr revid: chs@openerp.com-20121210132133-m1z2hb72y1r1wsei
This commit is contained in:
parent
b0c9f525ce
commit
507c02aaa2
|
@ -20,6 +20,9 @@
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
|
#.apidoc title: Common Services: netsvc
|
||||||
|
#.apidoc module-mods: member-order: bysource
|
||||||
|
|
||||||
import errno
|
import errno
|
||||||
import logging
|
import logging
|
||||||
import logging.handlers
|
import logging.handlers
|
||||||
|
@ -41,9 +44,23 @@ import openerp
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def close_socket(sock):
|
||||||
|
""" Closes a socket instance cleanly
|
||||||
|
|
||||||
#.apidoc title: Common Services: netsvc
|
:param sock: the network socket to close
|
||||||
#.apidoc module-mods: member-order: bysource
|
: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):
|
def abort_response(dummy_1, description, dummy_2, details):
|
||||||
# TODO Replace except_{osv,orm} with these directly.
|
# TODO Replace except_{osv,orm} with these directly.
|
||||||
|
|
|
@ -22,8 +22,6 @@
|
||||||
#.apidoc title: NET-RPC Server
|
#.apidoc title: NET-RPC Server
|
||||||
|
|
||||||
""" This file contains instance of the net-rpc server
|
""" This file contains instance of the net-rpc server
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
import select
|
import select
|
||||||
|
@ -38,24 +36,6 @@ import openerp.tools as tools
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_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:
|
class Server:
|
||||||
""" Generic interface for all servers with an event loop etc.
|
""" Generic interface for all servers with an event loop etc.
|
||||||
Override this to impement http, net-rpc etc. servers.
|
Override this to impement http, net-rpc etc. servers.
|
||||||
|
@ -133,7 +113,7 @@ class Server:
|
||||||
return '\n'.join(res)
|
return '\n'.join(res)
|
||||||
|
|
||||||
def _close_socket(self):
|
def _close_socket(self):
|
||||||
close_socket(self.socket)
|
netsvc.close_socket(self.socket)
|
||||||
|
|
||||||
class TinySocketClientThread(threading.Thread):
|
class TinySocketClientThread(threading.Thread):
|
||||||
def __init__(self, sock, threads):
|
def __init__(self, sock, threads):
|
||||||
|
|
Loading…
Reference in New Issue