summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2011-05-18 11:09:00 +0100
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2011-05-18 11:09:00 +0100
commit77f745f8a27af7b0ff4692ec02278591cdda2bbf (patch)
tree3bb54b5b8c41e81ec34cfc02879fc688b83fa30a /examples
parent917c41bfcad70c2c519c56a8f2a62e1804c08fc1 (diff)
unix-fd-service example: also exercise returning UnixFd(int)
Also, cycle through the three possible return types deterministically, rather than choosing at random.
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/unix-fd-service.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/examples/unix-fd-service.py b/examples/unix-fd-service.py
index 2347dcd..7850049 100755
--- a/examples/unix-fd-service.py
+++ b/examples/unix-fd-service.py
@@ -39,17 +39,22 @@ import random
class SomeObject(dbus.service.Object):
+ counter = 0
+
@dbus.service.method("com.example.SampleInterface",
in_signature='', out_signature='h')
def GetFd(self):
- # both forms are acceptable while sending fd
- if random.random() > 0.5:
+ self.counter = (self.counter + 1) % 3
+
+ if self.counter == 0:
+ print "sending UnixFd(filelike)"
return dbus.types.UnixFd(f)
- else:
+ elif self.counter == 1:
+ print "sending int"
return f.fileno()
- # The only unacceptable form to send fd would be
- # UnixFd(f.fileno()) because UnixFd takes fd
- # ownership when receives an integer.
+ else:
+ print "sending UnixFd(int)"
+ return dbus.types.UnixFd(f.fileno())
if len(sys.argv) < 2:
print usage