Example #1
0
		public virtual void SetUp()
		{
			@out = new PipedOutputStream();
			@in = new TimeoutOutputStreamTest.FullPipeInputStream(this, @out);
			timer = new InterruptTimer();
			os = new TimeoutOutputStream(@out, timer);
			os.SetTimeout(timeout);
		}
 public virtual void SetUp()
 {
     @out  = new PipedOutputStream();
     @in   = new TimeoutOutputStreamTest.FullPipeInputStream(this, @out);
     timer = new InterruptTimer();
     os    = new TimeoutOutputStream(@out, timer);
     os.SetTimeout(timeout);
 }
 public virtual void TestTimeout_close_Success()
 {
     bool[] called = new bool[1];
     os = new TimeoutOutputStream(new _OutputStream_206(called), timer);
     os.SetTimeout(timeout);
     os.Close();
     NUnit.Framework.Assert.IsTrue(called[0]);
 }
 public virtual void TestTimeout_close_Timeout()
 {
     bool[] called = new bool[1];
     os = new TimeoutOutputStream(new _OutputStream_225(called), timer);
     os.SetTimeout(timeout);
     BeginWrite();
     try
     {
         os.Close();
         NUnit.Framework.Assert.Fail("incorrectly closed");
     }
     catch (ThreadInterruptedException)
     {
     }
     // expected
     AssertTimeout();
     NUnit.Framework.Assert.IsTrue(called[0]);
 }
		public override void Close()
		{
			if (@out != null)
			{
				try
				{
					if (outNeedsEnd)
					{
						outNeedsEnd = false;
						pckOut.End();
					}
					@out.Close();
				}
				catch (IOException)
				{
				}
				finally
				{
					// Ignore any close errors.
					@out = null;
					pckOut = null;
				}
			}
			if (@in != null)
			{
				try
				{
					@in.Close();
				}
				catch (IOException)
				{
				}
				finally
				{
					// Ignore any close errors.
					@in = null;
					pckIn = null;
				}
			}
			if (myTimer != null)
			{
				try
				{
					myTimer.Terminate();
				}
				finally
				{
					myTimer = null;
					timeoutIn = null;
					timeoutOut = null;
				}
			}
		}
		/// <summary>Configure this connection with the directional pipes.</summary>
		/// <remarks>Configure this connection with the directional pipes.</remarks>
		/// <param name="myIn">
		/// input stream to receive data from the peer. Caller must ensure
		/// the input is buffered, otherwise read performance may suffer.
		/// </param>
		/// <param name="myOut">
		/// output stream to transmit data to the peer. Caller must ensure
		/// the output is buffered, otherwise write performance may
		/// suffer.
		/// </param>
		protected internal void Init(InputStream myIn, OutputStream myOut)
		{
			int timeout = transport.GetTimeout();
			if (timeout > 0)
			{
				Sharpen.Thread caller = Sharpen.Thread.CurrentThread();
				myTimer = new InterruptTimer(caller.GetName() + "-Timer");
				timeoutIn = new TimeoutInputStream(myIn, myTimer);
				timeoutOut = new TimeoutOutputStream(myOut, myTimer);
				timeoutIn.SetTimeout(timeout * 1000);
				timeoutOut.SetTimeout(timeout * 1000);
				myIn = timeoutIn;
				myOut = timeoutOut;
			}
			@in = myIn;
			@out = myOut;
			pckIn = new PacketLineIn(@in);
			pckOut = new PacketLineOut(@out);
			outNeedsEnd = true;
		}
Example #7
0
		/// <summary>Execute the upload task on the socket.</summary>
		/// <remarks>Execute the upload task on the socket.</remarks>
		/// <param name="input">
		/// raw input to read client commands from. Caller must ensure the
		/// input is buffered, otherwise read performance may suffer.
		/// </param>
		/// <param name="output">
		/// response back to the Git network client, to write the pack
		/// data onto. Caller must ensure the output is buffered,
		/// otherwise write performance may suffer.
		/// </param>
		/// <param name="messages">
		/// secondary "notice" channel to send additional messages out
		/// through. When run over SSH this should be tied back to the
		/// standard error channel of the command execution. For most
		/// other network connections this should be null.
		/// </param>
		/// <exception cref="System.IO.IOException">System.IO.IOException</exception>
		public virtual void Upload(InputStream input, OutputStream output, OutputStream messages
			)
		{
			try
			{
				rawIn = input;
				rawOut = output;
				if (timeout > 0)
				{
					Sharpen.Thread caller = Sharpen.Thread.CurrentThread();
					timer = new InterruptTimer(caller.GetName() + "-Timer");
					TimeoutInputStream i = new TimeoutInputStream(rawIn, timer);
					TimeoutOutputStream o = new TimeoutOutputStream(rawOut, timer);
					i.SetTimeout(timeout * 1000);
					o.SetTimeout(timeout * 1000);
					rawIn = i;
					rawOut = o;
				}
				pckIn = new PacketLineIn(rawIn);
				pckOut = new PacketLineOut(rawOut);
				Service();
			}
			finally
			{
				walk.Release();
				if (timer != null)
				{
					try
					{
						timer.Terminate();
					}
					finally
					{
						timer = null;
					}
				}
			}
		}
Example #8
0
		public virtual void TestTimeout_close_Timeout()
		{
			bool[] called = new bool[1];
			os = new TimeoutOutputStream(new _OutputStream_224(called), timer);
			os.SetTimeout(timeout);
			BeginWrite();
			try
			{
				os.Close();
				NUnit.Framework.Assert.Fail("incorrectly closed");
			}
			catch (ThreadInterruptedException)
			{
			}
			// expected
			AssertTimeout();
			NUnit.Framework.Assert.IsTrue(called[0]);
		}
Example #9
0
		public virtual void TestTimeout_close_Success()
		{
			bool[] called = new bool[1];
			os = new TimeoutOutputStream(new _OutputStream_205(called), timer);
			os.SetTimeout(timeout);
			os.Close();
			NUnit.Framework.Assert.IsTrue(called[0]);
		}