/// <exception cref="System.IO.IOException"></exception> public virtual void Disconnect(bool hard) { if (hard) { IOException ioe = null; switch (State) { case 0: { return; } case 2: { hard = true; goto case 3; } case 3: { if (ResponseMap.Count != 0 && !hard) { break; } try { DoDisconnect(hard); } catch (IOException ioe0) { ioe = ioe0; } goto case 4; } case 4: { Thread?.Cancel(); Thread?.Dispose(); Thread = null; State = 0; break; } default: { if (Log.Level >= 1) { Log.WriteLine("Invalid state: " + State); } Thread?.Cancel(); Thread?.Dispose(); Thread = null; State = 0; break; } } if (ioe != null) { throw ioe; } return; } lock (this) { IOException ioe = null; switch (State) { case 0: { return; } case 2: { hard = true; goto case 3; } case 3: { if (ResponseMap.Count != 0 && !hard) { break; } try { DoDisconnect(hard); } catch (IOException ioe0) { ioe = ioe0; } goto case 4; } case 4: { Thread?.Cancel(); Thread?.Dispose(); Thread = null; State = 0; break; } default: { if (Log.Level >= 1) { Log.WriteLine("Invalid state: " + State); } Thread?.Cancel(); Thread?.Dispose(); Thread = null; State = 0; break; } } if (ioe != null) { throw ioe; } } }
/// <exception cref="SharpCifs.Util.Transport.TransportException"></exception> public virtual void Connect(long timeout) { lock (this) { try { switch (State) { case 0: { break; } case 3: { return; } case 4: { // already connected State = 0; throw new TransportException("Connection in error", Te); } default: { //TransportException te = new TransportException("Invalid state: " + state); State = 0; throw new TransportException("Invalid state: " + State); } } State = 1; Te = null; if (Thread != null) { Thread.Cancel(true); Thread.Dispose(); } Thread = new Thread(this); Thread.SetDaemon(true); lock (Thread) { Thread.Start(true); Runtime.Wait(Thread, timeout); switch (State) { case 1: { State = 0; Thread?.Cancel(); Thread?.Dispose(); Thread = null; throw new TransportException("Connection timeout"); } case 2: { if (Te != null) { State = 4; Thread?.Cancel(); Thread?.Dispose(); Thread = null; throw Te; } State = 3; return; } } } } catch (Exception ie) { State = 0; Thread?.Cancel(); Thread?.Dispose(); Thread = null; throw new TransportException(ie); } finally { if (State != 0 && State != 3 && State != 4) { if (Log.Level >= 1) { Log.WriteLine("Invalid state: " + State); } State = 0; Thread?.Cancel(); Thread?.Dispose(); Thread = null; } } } }