[banshee] Avoid freezes by opening the socket on the thread



commit 5abb0281ca44b297a53014ba3bded2647a4787dd
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Thu Nov 12 22:32:20 2009 -0800

    Avoid freezes by opening the socket on the thread
    
    Should resolve some (all?) freezes related to DAAP startup.

 .../Banshee.Services/Banshee.Web/BaseHttpServer.cs |   18 +++++++++++++-----
 .../Banshee.Daap/DaapProxyWebServer.cs             |    8 --------
 2 files changed, 13 insertions(+), 13 deletions(-)
---
diff --git a/src/Core/Banshee.Services/Banshee.Web/BaseHttpServer.cs b/src/Core/Banshee.Services/Banshee.Web/BaseHttpServer.cs
index 6cf238b..110e028 100644
--- a/src/Core/Banshee.Services/Banshee.Web/BaseHttpServer.cs
+++ b/src/Core/Banshee.Services/Banshee.Web/BaseHttpServer.cs
@@ -44,6 +44,8 @@ namespace Banshee.Web
     public abstract class BaseHttpServer
     {
         protected Socket server;
+        private int backlog;
+        private ushort port;
 
         protected readonly ArrayList clients = new ArrayList();
 
@@ -88,6 +90,10 @@ namespace Banshee.Web
             get { return chunk_length; }
         }
 
+        public ushort Port {
+            get { return port; }
+        }
+
         public void Start ()
         {
             Start (10);
@@ -102,12 +108,8 @@ namespace Banshee.Web
             if (running) {
                 return;
             }
-            
-            server = new Socket (this.EndPoint.AddressFamily, SocketType.Stream, ProtocolType.IP);
-            server.Bind (this.EndPoint);
-            
-            server.Listen (backlog);
 
+            this.backlog = backlog;
             running = true;
             Thread thread = new Thread (ServerLoop);
             thread.Name = this.Name;
@@ -131,6 +133,12 @@ namespace Banshee.Web
         
         private void ServerLoop ()
         {
+            server = new Socket (this.EndPoint.AddressFamily, SocketType.Stream, ProtocolType.IP);
+            server.Bind (this.EndPoint);
+            server.Listen (backlog);
+
+            port = (ushort)(server.LocalEndPoint as IPEndPoint).Port;
+
             while (true) {
                 try {
                     if (!running) {
diff --git a/src/Extensions/Banshee.Daap/Banshee.Daap/DaapProxyWebServer.cs b/src/Extensions/Banshee.Daap/Banshee.Daap/DaapProxyWebServer.cs
index ba27948..40e9bba 100644
--- a/src/Extensions/Banshee.Daap/Banshee.Daap/DaapProxyWebServer.cs
+++ b/src/Extensions/Banshee.Daap/Banshee.Daap/DaapProxyWebServer.cs
@@ -47,7 +47,6 @@ namespace Banshee.Daap
 {
     internal class DaapProxyWebServer : BaseHttpServer
     {
-        private ushort port;
         private ArrayList databases = new ArrayList();
       
         public DaapProxyWebServer() : base (new IPEndPoint(IPAddress.Any, 8089), "DAAP Proxy")
@@ -62,7 +61,6 @@ namespace Banshee.Daap
                 EndPoint = new IPEndPoint(IPAddress.Any, 0);
                 base.Start (backlog);
             }
-            port = (ushort)(server.LocalEndPoint as IPEndPoint).Port;
         }
         
         public void RegisterDatabase(DAAP.Database database)
@@ -218,12 +216,6 @@ namespace Banshee.Daap
                 DateTime.Now.ToString());
         }
 
-        public ushort Port {
-            get { 
-                return port;
-            }
-        }
-
         private static IPAddress local_address = IPAddress.Parse("127.0.0.1");
         public IPAddress IPAddress {
             get {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]