From: Yosuke Iwamatsu <y-iwamatsu@ab.jp.nec.com>
To: xen-devel@lists.xensource.com
Subject: [PATCH 1/5] Implement DGRAM (connectionless) type socket listeners
Date: Fri, 13 Mar 2009 21:06:08 +0900 [thread overview]
Message-ID: <49BA4C30.7050207@ab.jp.nec.com> (raw)
In-Reply-To: <49BA4209.1020702@ab.jp.nec.com>
Introduce SocketDgramListener and UnixDgramListener classes.
We already have STREAM (connection) type socket listener classes in the
source tree, but we need DGRAM (connectionless) type listeners to receive
udev events.
Signed-off-by: Yosuke Iwamatsu <y-iwamatsu@ab.jp.nec.com>
diff -r c30742011bb8 tools/python/xen/web/connection.py
--- a/tools/python/xen/web/connection.py Thu Mar 12 18:48:09 2009 +0000
+++ b/tools/python/xen/web/connection.py Fri Mar 13 16:36:19 2009 +0900
@@ -292,3 +292,40 @@
return True
log.warn("Rejected connection from %s (%s).", addrport[0], fqdn)
return False
+
+
+class SocketDgramListener:
+ """A connectionless server socket, running listen in a thread.
+ """
+
+ def __init__(self, protocol_class):
+ self.protocol = protocol_class()
+ self.sock = self.createSocket()
+ threading.Thread(target=self.main).start()
+
+
+ def close(self):
+ try:
+ self.sock.close()
+ except:
+ pass
+
+
+ def createSocket(self):
+ raise NotImplementedError()
+
+
+ def main(self):
+ try:
+ while True:
+ try:
+ data = self.sock.recv(BUFFER_SIZE)
+ self.protocol.dataReceived(data)
+ except socket.error, ex:
+ if ex.args[0] not in (EWOULDBLOCK, EAGAIN, EINTR):
+ break
+ finally:
+ try:
+ self.close()
+ except:
+ pass
diff -r c30742011bb8 tools/python/xen/web/unix.py
--- a/tools/python/xen/web/unix.py Thu Mar 12 18:48:09 2009 +0000
+++ b/tools/python/xen/web/unix.py Fri Mar 13 16:36:19 2009 +0900
@@ -27,16 +27,19 @@
import connection
-def bind(path):
- """Create a Unix socket, and bind it to the given path. The socket is
-created such that only the current user may access it."""
+def bind(path, type = socket.SOCK_STREAM):
+ """Create a Unix socket, and bind it to the given path.
+ The socket is created such that only the current user may access it."""
- parent = os.path.dirname(path)
- mkdir.parents(parent, stat.S_IRWXU, True)
- if os.path.exists(path):
- os.unlink(path)
+ if path[0] == '\0': # Abstract namespace is used for the path
+ pass
+ else:
+ parent = os.path.dirname(path)
+ mkdir.parents(parent, stat.S_IRWXU, True)
+ if os.path.exists(path):
+ os.unlink(path)
- sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+ sock = socket.socket(socket.AF_UNIX, type)
sock.bind(path)
return sock
@@ -48,8 +51,19 @@
def createSocket(self):
- return bind(self.path)
+ return bind(self.path, socket.SOCK_STREAM)
def acceptConnection(self, sock, _):
connection.SocketServerConnection(sock, self.protocol_class)
+
+
+class UnixDgramListener(connection.SocketDgramListener):
+ def __init__(self, path, protocol_class):
+ self.path = path
+ connection.SocketDgramListener.__init__(self, protocol_class)
+
+
+ def createSocket(self):
+ return bind(self.path, socket.SOCK_DGRAM)
+
next parent reply other threads:[~2009-03-13 12:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <49BA4209.1020702@ab.jp.nec.com>
2009-03-13 12:06 ` Yosuke Iwamatsu [this message]
2009-03-13 12:06 ` [PATCH 2/5] Add lock for xen-api class instances in XendAPIStore.py Yosuke Iwamatsu
2009-03-13 12:06 ` [PATCH 3/5] Add lock for lspci_info in pci.py Yosuke Iwamatsu
2009-03-13 12:06 ` [PATCH 4/5] Accept udev events and update physical resource information Yosuke Iwamatsu
2009-03-23 7:05 ` [PATCH 4/5] Accept udev events and update physicalresource information Masaki Kanno
2009-03-24 8:12 ` [PATCH] xend: save the state of PPCIs after hot-plug ([PATCH 4/5] Accept udev events and update physical resource information) Yosuke Iwamatsu
2009-03-25 9:24 ` Masaki Kanno
2009-03-13 12:06 ` [PATCH 5/5] Add udev rules to deliver hw events to xend Yosuke Iwamatsu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=49BA4C30.7050207@ab.jp.nec.com \
--to=y-iwamatsu@ab.jp.nec.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.