[farsight2/master] Cleanup server-side when client is disconnected

Olivier Crête olivier.crete at collabora.co.uk
Tue Dec 23 15:20:39 PST 2008


---
 tests/gui/fs2-gui.py     |   41 ++++++++++++++++++++++++++++++++++-
 tests/gui/fs2_gui_net.py |   53 +++++++++++++++++++++++++++++++--------------
 2 files changed, 76 insertions(+), 18 deletions(-)

diff --git a/tests/gui/fs2-gui.py b/tests/gui/fs2-gui.py
index d8809a3..b67e370 100644
--- a/tests/gui/fs2-gui.py
+++ b/tests/gui/fs2-gui.py
@@ -367,7 +367,7 @@ class FsUIParticipant:
         self.glade.get_widget("user_drawingarea").set_size_request(x,y)
         gtk.gdk.threads_leave()
         self.videosink.get_pad("sink").remove_buffer_probe(self.havesize)
-        print "HAVE Size ",x,"x",y
+        del self.havesize
         return True
                  
 
@@ -377,10 +377,37 @@ class FsUIParticipant:
             self.outcv.acquire()
             while self.funnel is None:
                 self.outcv.wait()
+            print >>sys.stderr, "LINKING SINK"
             pad.link(self.funnel.get_pad("sink%d"))
         finally:
             self.outcv.release()
 
+    def destroy(self):
+        try:
+            self.videosink.get_pad("sink").disconnect_handler(self.havesize)
+            pass
+        except AttributeError:
+            pass
+        self.glade.get_widget("user_drawingarea").disconnect_by_func(self.exposed)
+        del self.streams
+        self.outcv.acquire()
+        self.videosink.set_state(gst.STATE_NULL)
+        self.funnel.set_state(gst.STATE_NULL)
+        self.pipeline.pipeline.remove(self.videosink)
+        self.pipeline.pipeline.remove(self.funnel)
+        del self.videosink
+        del self.funnel
+        self.outcv.release()
+        gtk.gdk.threads_enter()
+        self.userframe.destroy()
+        gtk.gdk.threads_leave()
+
+    def error(self):
+        if self.id == 1:
+            self.mainui.fatal_error("<b>Disconnected from server</b>")
+        else:
+            print "ERROR ON %d" % (self.id)
+
     
 
 class FsMainUI:
@@ -425,6 +452,18 @@ class FsMainUI:
     def __del__(self):
         self.mainwindow.destroy()
 
+    def fatal_error(self, errormsg):
+        gtk.gdk.threads_enter()
+        dialog = gtk.MessageDialog(self.mainwindow,
+                                   gtk.DIALOG_MODAL,
+                                   gtk.MESSAGE_ERROR,
+                                   gtk.BUTTONS_OK)
+        dialog.set_markup(errormsg);
+        dialog.run()
+        dialog.destroy()
+        gtk.main_quit()
+        gtk.gdk.threads_leave()
+
 class FsUIStartup:
     def __init__(self):
         self.glade = gtk.glade.XML("fs2-gui.glade", "neworconnect_dialog")
diff --git a/tests/gui/fs2_gui_net.py b/tests/gui/fs2_gui_net.py
index 9fe0a2e..519eef5 100644
--- a/tests/gui/fs2_gui_net.py
+++ b/tests/gui/fs2_gui_net.py
@@ -2,6 +2,7 @@
 
 import sys, os, pwd, os.path
 import socket, struct
+import gc
 
 try:
     import farsight
@@ -33,6 +34,7 @@ class FsUIConnect:
         self.__reset()
         self.callbacks = callbacks
         self.myid = myid
+        self.partid = 1
         sock.setblocking(0)
         gobject.io_add_watch(self.sock.fileno(), gobject.IO_IN,
                              self.__data_in)
@@ -41,11 +43,17 @@ class FsUIConnect:
                              self.__error)
 
     def __error(self, source, condition):
-        self.callbacks[self.ERROR]()
+        print "have error"
+        self.callbacks[self.ERROR](self.partid)
         return False
 
     def __data_in(self, source, condition):
         data = self.sock.recv(self.size-len(self.data))
+
+        if len(data) == 0:
+            print "received nothing"
+            self.callbacks[self.ERROR](self.partid)
+            return False
         
         self.data += data
         if len(self.data) == self.size:
@@ -68,7 +76,7 @@ class FsUIConnect:
                  self.size) = struct.unpack("!IIIIII", self.data)
                 if check != 0xDEADBEEF:
                     print "CORRUPTION"
-                    mainloop.quit()
+                    sys.exit(1)
                 self.data=""
                 if self.size == 0:
                     self.callbacks[self.type](self.src, self.dest,
@@ -79,14 +87,18 @@ class FsUIConnect:
     def __send_data(self, dest, type, media=0, data="", src=None):
         if src is None: src = self.myid
         if src == 0 and type != self.INTRO: raise Exception
-        self.sock.sendall(struct.pack("!IIIIII",
-                                      0xDEADBEEF,
-                                      int(src),
-                                      int(dest),
-                                      int(type),
-                                      int(media),
-                                      len(data)))
-        self.sock.sendall(data)
+        try:
+            self.sock.sendall(struct.pack("!IIIIII",
+                                          0xDEADBEEF,
+                                          int(src),
+                                          int(dest),
+                                          int(type),
+                                          int(media),
+                                          len(data)))
+            self.sock.sendall(data)
+        except socket.error:
+            print "have error"
+            self.callbacks[self.ERROR](self.partid)
 
 
     def send_intro(self, dest, cname, src=None):
@@ -198,7 +210,7 @@ class FsUIListener:
 
     def error(self, source, condition):
         print "Error on listen"
-        mainloop.quit()
+        sys.exit(1)
         return False
 
     def data_in(self, source, condition):
@@ -229,7 +241,7 @@ class FsUIClient:
     def __candidate_done(self, src, dest, media, data):
         self.participants[src].candidates_done(media)
     def __intro(self, src, dest, media, cname):
-        print "Got Intro"
+        print "Got Intro from %s" % src
         if src == 1:
             self.connect.myid = dest
         if not self.participants.has_key(src):
@@ -238,8 +250,10 @@ class FsUIClient:
             self.participants[src] = self.get_participant(self.connect, src,
                                                           cname,
                                                           *self.args)
-    def __error(self, *arg):
-        print "ERROR"
+    def __error(self, participantid, *arg):
+        print "Client Error", participantid
+        self.participants[participantid].error()
+
 
 class FsUIServer:
     nextid = 2
@@ -276,7 +290,7 @@ class FsUIServer:
                                                                        media,
                                                                        src)
     def __intro(self, src, dest, media, cname):
-        print "Got Intro"
+        print "Got Intro from %s to %s" % (src, dest)
         if src == 0 and dest == 1:
             newid = FsUIServer.nextid
             # Forward the introduction to all other participants
@@ -285,6 +299,7 @@ class FsUIServer:
                 FsUIServer.participants[pid].connect.send_intro(pid, cname,
                                                                 newid)
             self.connect.send_intro(newid, self.cname)
+            self.connect.partid = newid
             FsUIServer.participants[newid] = self.get_participant(self.connect,
                                                                   newid,
                                                                   cname,
@@ -297,8 +312,12 @@ class FsUIServer:
                                                              src)
         else:
             print "ERROR SRC != 0"
-    def __error(self, *args):
-        print "ERROR"
+            
+    def __error(self, participantid, *args):
+        print "Server Error", participantid
+        FsUIServer.participants[participantid].destroy()
+        del FsUIServer.participants[participantid]
+        gc.collect()
 
 if __name__ == "__main__":
     class TestMedia:
-- 
1.5.6.5




More information about the farsight-commits mailing list