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);
		}
Example #2
0
		public virtual void SetUp()
		{
			@out = new PipedOutputStream();
			@in = new PipedInputStream(@out);
			timer = new InterruptTimer();
			@is = new TimeoutInputStream(@in, timer);
			@is.SetTimeout(timeout);
		}
		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 #5
0
 /// <summary>Wrap an input stream with a timeout on all read operations.</summary>
 /// <remarks>Wrap an input stream with a timeout on all read operations.</remarks>
 /// <param name="src">
 /// base input stream (to read from). The stream must be
 /// interruptible (most socket streams are).
 /// </param>
 /// <param name="timer">timer to manage the timeouts during reads.</param>
 public TimeoutInputStream(InputStream src, InterruptTimer timer)
     : base(src)
 {
     myTimer = timer;
 }
Example #6
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 #7
0
 internal AutoKiller(InterruptTimer.AlarmState s)
 {
     // The trick here is, the AlarmThread does not have a reference to the
     // AutoKiller instance, only the InterruptTimer itself does. Thus when
     // the InterruptTimer is GC'd, the AutoKiller is also unreachable and
     // can be GC'd. When it gets finalized, it tells the AlarmThread to
     // terminate, triggering the thread to exit gracefully.
     //
     state = s;
 }
Example #8
0
 internal AlarmThread(string name, InterruptTimer.AlarmState q)
     : base(q)
 {
     //
     SetName(name);
     SetDaemon(true);
 }
Example #9
0
		/// <summary>Wrap an output stream with a timeout on all write operations.</summary>
		/// <remarks>Wrap an output stream with a timeout on all write operations.</remarks>
		/// <param name="destination">
		/// base input stream (to write to). The stream must be
		/// interruptible (most socket streams are).
		/// </param>
		/// <param name="timer">timer to manage the timeouts during writes.</param>
		public TimeoutOutputStream(OutputStream destination, InterruptTimer timer)
		{
			dst = destination;
			myTimer = timer;
		}