private void CloseSockets() { try { sender.Close(); receiver.Close(); } catch { } }
public static bool SendFd(string sockPath, Java.IO.FileDescriptor fd) { var socket = new LocalSocket(); try { socket.Connect(new LocalSocketAddress(sockPath, LocalSocketAddress.Namespace.Filesystem)); socket.SetFileDescriptorsForSend(new Java.IO.FileDescriptor[] { fd }); socket.OutputStream.Write(new byte[] { 42 }); } catch (Exception e) { Logging.warning("sendfd: " + e.Message); return(false); } finally { socket.Close(); } return(true); }
protected void closeSockets() { if (sPipeApi == PIPE_API_LS) { try { mReceiver.Close(); } catch (Exception e) { System.Diagnostics.Trace.WriteLine(e.StackTrace.ToString()); } try { mSender.Close(); } catch (Exception e) { System.Diagnostics.Trace.WriteLine(e.StackTrace.ToString()); } try { mLss.Close(); } catch (Exception e) { System.Diagnostics.Trace.WriteLine(e.StackTrace.ToString()); } mLss = null; mSender = null; mReceiver = null; } else { try { if (mParcelRead != null) { mParcelRead.Close(); } } catch (Exception e) { System.Diagnostics.Trace.WriteLine(e.StackTrace.ToString()); } try { if (mParcelWrite != null) { mParcelWrite.Close(); } } catch (Exception e) { System.Diagnostics.Trace.WriteLine(e.StackTrace.ToString()); } } }
/// <summary> /// Properly closes all connections /// and shuts down the server. /// </summary> public void Shutdown() { try { lock (ConnectedClients) { Handler.Debug("Shutting down all connections...", DebugType.Info); foreach (NetComCData client in ConnectedClients) { try { client.LocalSocket.Shutdown(SocketShutdown.Both); client.LocalSocket.Close(); } catch (Exception ex) { Handler.Debug("Could not close clients socket.", DebugType.Error); if (HandlerData.ShowExceptions) { Handler.Debug($"({ex.GetType().Name}) {ex.Message}", DebugType.Exception); } } } } Handler.Debug("Shutting down server...", DebugType.Info); LocalSocket.Close(); Handler.Debug("Shutdown complete!", DebugType.Info); } catch (Exception ex) { Handler.Debug("Shutdown could not be completed. Some connections might stay opened.", DebugType.Error); if (HandlerData.ShowExceptions) { Handler.Debug($"({ex.GetType().Name}) {ex.Message}", DebugType.Exception); } } }