listener tcp: catch some potential exceptions

This commit is contained in:
Hylke Bons 2012-03-17 19:16:53 +00:00
parent 7fa5bcf505
commit e91de7f442
2 changed files with 9 additions and 37 deletions

View file

@ -133,6 +133,7 @@ namespace SparkleLib {
this.last_ping = DateTime.Now;
} else {
// Check when the last ping occured. If it's
// significantly longer than our regular interval the
// system likely woke up from sleep and we want to
@ -156,8 +157,10 @@ namespace SparkleLib {
this.is_connected = false;
this.is_connecting = false;
if (this.socket != null)
if (this.socket != null) {
this.socket.Close ();
this.socket = null;
}
OnDisconnected ("Ping timeout");
return;
@ -215,7 +218,7 @@ namespace SparkleLib {
this.last_ping = DateTime.Now;
} catch (SocketException e) {
} catch (Exception e) {
this.is_connected = false;
this.is_connecting = false;
@ -231,11 +234,12 @@ namespace SparkleLib {
try {
lock (this.socket_lock)
this.socket.Send (Encoding.UTF8.GetBytes (to_send));
if (this.socket != null)
this.socket.Send (Encoding.UTF8.GetBytes (to_send));
this.last_ping = DateTime.Now;
} catch (SocketException e) {
} catch (Exception e) {
this.is_connected = false;
this.is_connecting = false;
@ -250,7 +254,7 @@ namespace SparkleLib {
this.thread.Join ();
if (this.socket != null)
this.socket.Close ();
this.socket.Close ();
base.Dispose ();
}

View file

@ -59,37 +59,5 @@ namespace SparkleShare {
return html_reader.ReadToEnd ();
}
public static ImageSource ToImageSource(FrameworkElement obj)
{
// Save current canvas transform
Transform transform = obj.LayoutTransform;
obj.LayoutTransform = null;
// fix margin offset as well
Thickness margin = obj.Margin;
obj.Margin = new Thickness(0, 0,
margin.Right - margin.Left, margin.Bottom - margin.Top);
// Get the size of canvas
Size size = new Size(obj.Width, obj.Height);
// force control to Update
obj.Measure(size);
obj.Arrange(new Rect(size));
RenderTargetBitmap bmp = new RenderTargetBitmap(
(int)obj.Width, (int)obj.Height, 96, 96, PixelFormats.Pbgra32);
bmp.Render(obj);
bmp.Freeze ();
// return values as they were before
obj.LayoutTransform = transform;
obj.Margin = margin;
return bmp;
}
}
}