Remove the bizarre arrangement whereby EventChannel inherits from dict. Move

the channel-creation logic into eventChannel, making the EventChannel class
simpler.  Remove the closeEventChannel method -- it was simply doing a check
for None, and that isn't enough value to justify the extra method when there
is an EventChannel.close method there too.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
This commit is contained in:
emellor@ewan committed 2005-09-30 11:40:59 +01:00
1 parent e9a3ddb1b2
commit 1b19d438d2
3 files changed
+27 -42

No files matched your search

+2 -2
View File
@@ -32,7 +32,7 @@ import errno
import xen.lowlevel.xc
from xen.util.blkif import blkdev_uname_to_file
from xen.xend.server.channel import EventChannel
from xen.xend.server import channel
from xen.xend import image
from xen.xend import scheduler
@@ -1032,7 +1032,7 @@ class XendDomainInfo:
except:
# if anything goes wrong, assume the port was not yet set
pass
ret = EventChannel.interdomain(0, self.domid, port1=port, port2=0)
ret = channel.eventChannel(0, self.domid, port1=port, port2=0)
self.storeDom(path, ret.port1)
return ret
+2 -1
View File
@@ -358,7 +358,8 @@ class VmxImageHandler(ImageHandler):
return vncconnect
def destroy(self):
channel.eventChannelClose(self.device_channel)
if self.device_channel:
self.device_channel.close()
import signal
if not self.pid:
return
+23 -39
View File
@@ -13,59 +13,42 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#============================================================================
# Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
# Copyright (C) 2005 XenSource Ltd
#============================================================================
import threading
import select
import xen.lowlevel.xc; xc = xen.lowlevel.xc.new()
import xen.lowlevel.xc
from xen.xend.XendLogging import log
DEBUG = 0
RESPONSE_TIMEOUT = 20.0
xc = xen.lowlevel.xc.new()
class EventChannel(dict):
class EventChannel:
"""An event channel between domains.
"""
def interdomain(cls, dom1, dom2, port1=0, port2=0):
"""Create an event channel between domains.
@return EventChannel (None on error)
"""
v = xc.evtchn_bind_interdomain(dom1=dom1, dom2=dom2,
port1=port1, port2=port2)
if v:
v = cls(dom1, dom2, v)
return v
interdomain = classmethod(interdomain)
def __init__(self, dom1, dom2, d):
d['dom1'] = dom1
d['dom2'] = dom2
self.update(d)
def __init__(self, dom1, dom2, port1, port2):
self.dom1 = dom1
self.dom2 = dom2
self.port1 = d.get('port1')
self.port2 = d.get('port2')
self.port1 = port1
self.port2 = port2
def close(self):
"""Close the event channel.
"""Close the event channel. Nothrow guarantee.
"""
def evtchn_close(dom, port):
try:
xc.evtchn_close(dom=dom, port=port)
except Exception, ex:
pass
except Exception:
log.exception("Exception closing event channel %d, %d.", dom,
port)
if DEBUG:
print 'EventChannel>close>', self
evtchn_close(self.dom1, self.port1)
evtchn_close(self.dom2, self.port2)
def sxpr(self):
return ['event-channel',
['dom1', self.dom1 ],
@@ -74,19 +57,20 @@ class EventChannel(dict):
['port2', self.port2 ]
]
def __repr__(self):
return ("<EventChannel dom1:%d:%d dom2:%d:%d>"
% (self.dom1, self.port1, self.dom2, self.port2))
def eventChannel(dom1, dom2, port1=0, port2=0):
def eventChannel(dom1, dom2, port1 = 0, port2 = 0):
"""Create an event channel between domains.
@return EventChannel (None on error)
"""
return EventChannel.interdomain(dom1, dom2, port1=port1, port2=port2)
def eventChannelClose(evtchn):
"""Close an event channel.
"""
if not evtchn: return
evtchn.close()
v = xc.evtchn_bind_interdomain(dom1=dom1, dom2=dom2,
port1=port1, port2=port2)
if v and v.get('port1'):
return EventChannel(dom1, dom2, v['port1'], v['port2'])
else:
return None
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.