Write Git style pkt-line formatting to an output stream. This class is not thread safe and may issue multiple writes to the underlying stream for each method call made. This class performs no buffering on its own. This makes it suitable to interleave writes performed by this class with writes performed directly against the underlying OutputStream.
Пример #1
0
        /// <summary>
        /// Execute the receive task on the socket.
        /// </summary>
        /// <param name="input">Raw input to read client commands and pack data from. Caller must ensure the input is buffered, otherwise read performance may suffer. Response back to the Git network client. 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>
        public void receive(Stream input, Stream output, Stream messages)
        {
            try
            {
                rawInput  = input;
                rawOutput = output;

                pckIn  = new PacketLineIn(rawInput);
                pckOut = new PacketLineOut(rawOutput);

                // TODO: [henon] port jgit's timeout behavior which is obviously missing here

                if (messages != null)
                {
                    msgs = new StreamWriter(messages, Constants.CHARSET);
                }

                enabledCapabilities = new List <string>();
                commands            = new List <ReceiveCommand>();

                Service();
            }
            finally
            {
                try
                {
                    if (pckOut != null)
                    {
                        pckOut.Flush();
                    }
                    if (msgs != null)
                    {
                        msgs.Flush();
                    }
                    if (sideBand)
                    {
                        // If we are using side band, we need to send a final
                        // flush-pkt to tell the remote peer the side band is
                        // complete and it should stop decoding. We need to
                        // use the original output stream as rawOut is now the
                        // side band data channel.
                        //
                        new PacketLineOut(output).End();
                    }
                }
                finally
                {
                    // TODO : [nulltoken] Aren't we missing some Dispose() love, here ?
                    UnlockPack();
                    rawInput            = null;
                    rawOutput           = null;
                    pckIn               = null;
                    pckOut              = null;
                    msgs                = null;
                    refs                = null;
                    enabledCapabilities = null;
                    commands            = null;
                }
            }
        }
Пример #2
0
        public override void Write(byte[] b, int off, int len)
        {
            while (0 < len)
            {
                int capacity = _buffer.Length - cnt;
                if (cnt == HDR_SIZE && capacity < len)
                {
                    // Our block to write is bigger than the packet size,
                    // stream it out as-is to avoid unnecessary copies.
                    PacketLineOut.FormatLength(_buffer, _buffer.Length);
                    _out.Write(_buffer, 0, HDR_SIZE);
                    _out.Write(b, off, capacity);
                    off += capacity;
                    len -= capacity;
                }
                else
                {
                    if (capacity == 0)
                    {
                        WriteBuffer();
                    }

                    int n = Math.Min(len, capacity);
                    Array.Copy(b, off, _buffer, cnt, n);
                    cnt += n;
                    off += n;
                    len -= n;
                }
            }
        }
Пример #3
0
        protected void init(Stream instream, Stream outstream)
        {
            inStream  = instream is BufferedStream ? instream : new BufferedStream(instream, IndexPack.BUFFER_SIZE);
            outStream = outstream is BufferedStream ? outstream : new BufferedStream(outstream, IndexPack.BUFFER_SIZE);

            pckIn  = new PacketLineIn(inStream);
            pckOut = new PacketLineOut(outStream);

            outNeedsEnd = true;
        }
Пример #4
0
        public RefAdvertiser(PacketLineOut o, RevWalk.RevWalk protoWalk, RevFlag advertisedFlag)
        {
            _tmpLine = new StringBuilder(100);
            _tmpId = new char[2 * Constants.OBJECT_ID_LENGTH];
            _capabilities = new List<string>();
            _first = true;

            _pckOut = o;
            _walk = protoWalk;
            ADVERTISED = advertisedFlag;
        }
Пример #5
0
        public RefAdvertiser(PacketLineOut o, RevWalk.RevWalk protoWalk, RevFlag advertisedFlag)
        {
            _tmpLine      = new StringBuilder(100);
            _tmpId        = new char[2 * Constants.OBJECT_ID_LENGTH];
            _capabilities = new List <string>();
            _first        = true;

            _pckOut    = o;
            _walk      = protoWalk;
            ADVERTISED = advertisedFlag;
        }
Пример #6
0
        private void EnableCapabilities()
        {
            reportStatus = enabledCapabilities.Contains(BasePackPushConnection.CAPABILITY_REPORT_STATUS);

            sideBand = enabledCapabilities.Contains(BasePackPushConnection.CAPABILITY_SIDE_BAND_64K);
            if (sideBand)
            {
                Stream @out = rawOutput;

                rawOutput = new SideBandOutputStream(SideBandOutputStream.CH_DATA, SideBandOutputStream.MAX_BUF, @out);
                pckOut    = new PacketLineOut(rawOutput);
                msgs      = new StreamWriter(new SideBandOutputStream(SideBandOutputStream.CH_PROGRESS,
                                                                      SideBandOutputStream.MAX_BUF, @out), Constants.CHARSET);
            }
        }
Пример #7
0
        /// <summary>
        /// Execute the upload task on the socket.
        /// </summary>
        /// <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="IOException"></exception>
        public void Upload(Stream input, Stream output, Stream messages)
        {
            _rawIn  = input;
            _rawOut = output;

            if (_timeout > 0)
            {
                var i = new TimeoutStream(_rawIn, _timeout * 1000);
                var o = new TimeoutStream(_rawOut, _timeout * 1000);
                _rawIn  = i;
                _rawOut = o;
            }

            _pckIn  = new PacketLineIn(_rawIn);
            _pckOut = new PacketLineOut(_rawOut);
            Service();
        }
Пример #8
0
        public override void Close()
        {
            if (outStream != null)
            {
                try
                {
                    if (outNeedsEnd)
                    {
                        pckOut.End();
                    }
                    outStream.Close();
                }
                catch (IOException)
                {
                    // Ignore any close errors.
                }
                finally
                {
                    outStream = null;
                    pckOut    = null;
                }
            }

            if (inStream != null)
            {
                try
                {
                    inStream.Close();
                }
                catch (IOException)
                {
                    // Ignore any close errors.
                }
                finally
                {
                    inStream = null;
                    pckIn    = null;
                }
            }

#if DEBUG
            GC.SuppressFinalize(this); // Disarm lock-release checker
#endif
        }
Пример #9
0
        private void Service(string name, PacketLineOut pckOut)
        {
            var cmd = new StringBuilder();

            cmd.Append(name);
            cmd.Append(' ');
            cmd.Append(Uri.Path);
            cmd.Append('\0');
            cmd.Append("host=");
            cmd.Append(Uri.Host);
            if (Uri.Port > 0 && Uri.Port != GIT_PORT)
            {
                cmd.Append(":");
                cmd.Append(Uri.Port);
            }
            cmd.Append('\0');
            pckOut.WriteString(cmd.ToString());
            pckOut.Flush();
        }
Пример #10
0
        public void receive(Stream stream, Stream messages)
        {
            try
            {
                raw = stream;

                pckIn  = new PacketLineIn(raw);
                pckOut = new PacketLineOut(raw);

                if (messages != null)
                {
                    msgs = new StreamWriter(messages);
                }

                enabledCapabilities = new List <string>();
                commands            = new List <ReceiveCommand>();

                Service();
            }
            finally
            {
                try
                {
                    if (msgs != null)
                    {
                        msgs.Flush();
                    }
                }
                finally
                {
                    UnlockPack();
                    raw    = null;
                    pckIn  = null;
                    pckOut = null;
                    msgs   = null;
                    refs   = null;
                    enabledCapabilities = null;
                    commands            = null;
                }
            }
        }
Пример #11
0
 public SideBandOutputStream(int chan, PacketLineOut outPLO)
 {
     channel = chan;
     pckOut = outPLO;
 }
Пример #12
0
        public SideBandProgressMonitor(PacketLineOut pckOut)
        {
            int bufsz = SideBandOutputStream.SMALL_BUF - SideBandOutputStream.HDR_SIZE;

            writer = new StreamWriter(new BufferedStream(new SideBandOutputStream(SideBandOutputStream.CH_PROGRESS, pckOut), bufsz), Constants.CHARSET);
        }
Пример #13
0
        /// <summary>
        /// Execute the upload task on the socket.
        /// </summary>
        /// <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="IOException"></exception>
        public void Upload(Stream input, Stream output, Stream messages)
        {
            _rawIn = input;
            _rawOut = output;

            if (_timeout > 0)
            {
                var i = new TimeoutStream(_rawIn);
					i.setTimeout(_timeout * 1000);
                var o = new TimeoutStream(_rawOut );
					 o.setTimeout(_timeout * 1000);
                _rawIn = i;
                _rawOut = o;
            }

            _pckIn = new PacketLineIn(_rawIn);
            _pckOut = new PacketLineOut(_rawOut);
            Service();
        }
Пример #14
0
 public ServiceReporter(PacketLineOut pck)
 {
     _pckOut = pck;
 }
Пример #15
0
        public void receive(Stream stream, Stream messages)
        {
            try
            {
                raw = stream;

                pckIn = new PacketLineIn(raw);
                pckOut = new PacketLineOut(raw);

                if (messages != null)
                {
                    msgs = new StreamWriter(messages);
                }

                enabledCapabilities = new List<string>();
                commands = new List<ReceiveCommand>();

                Service();
            }
            finally
            {
                try
                {
                    if (msgs != null)
                        msgs.Flush();
                }
                finally
                {
                    UnlockPack();
                    raw = null;
                    pckIn = null;
                    pckOut = null;
                    msgs = null;
                    refs = null;
                    enabledCapabilities = null;
                    commands = null;
                }
            }
        }
Пример #16
0
        public override void Close()
        {
            if (stream != null)
            {
                try
                {
                    if (outNeedsEnd)
                        pckOut.End();
                    stream.Close();
                }
                catch (IOException)
                {

                }
                finally
                {
                    stream = null;
                    pckOut = null;
                }
            }
        }
Пример #17
0
 private void WriteBuffer()
 {
     PacketLineOut.FormatLength(_buffer, cnt);
     _out.Write(_buffer, 0, cnt);
     cnt = HDR_SIZE;
 }
Пример #18
0
 public ServiceReporter(PacketLineOut pck)
 {
     _pckOut = pck;
 }
 public SideBandProgressMonitor(PacketLineOut pckOut)
 {
     int bufsz = SideBandOutputStream.SMALL_BUF - SideBandOutputStream.HDR_SIZE;
     _writer = new StreamWriter(new BufferedStream(new SideBandOutputStream(SideBandOutputStream.CH_PROGRESS, pckOut), bufsz), Constants.CHARSET);
 }
Пример #20
0
 public SideBandOutputStream(int chan, PacketLineOut outPLO)
 {
     channel = chan;
     pckOut  = outPLO;
 }
Пример #21
0
 /// <summary>
 /// Create a new advertiser for the supplied stream.
 /// </summary>
 /// <param name="out">the output stream.</param>
 public PacketLineOutRefAdvertiser(PacketLineOut @out)
 {
     pckOut = @out;
 }
Пример #22
0
 private void Service(string name, PacketLineOut pckOut)
 {
     var cmd = new StringBuilder();
     cmd.Append(name);
     cmd.Append(' ');
     cmd.Append(Uri.Path);
     cmd.Append('\0');
     cmd.Append("host=");
     cmd.Append(Uri.Host);
     if (Uri.Port > 0 && Uri.Port != GIT_PORT)
     {
         cmd.Append(":");
         cmd.Append(Uri.Port);
     }
     cmd.Append('\0');
     pckOut.WriteString(cmd.ToString());
     pckOut.Flush();
 }
Пример #23
0
        protected void init(Stream instream, Stream outstream)
        {
            this.inStream = instream is BufferedStream ? instream : new BufferedStream(instream, IndexPack.BUFFER_SIZE);
            this.outStream = outstream is BufferedStream ? outstream : new BufferedStream(outstream, IndexPack.BUFFER_SIZE);

            pckIn = new PacketLineIn(inStream);
            pckOut = new PacketLineOut(outStream);

            outNeedsEnd = true;
        }
Пример #24
0
 /// <summary>
 /// Create a new advertiser for the supplied stream.
 /// </summary>
 /// <param name="out">the output stream.</param>
 public PacketLineOutRefAdvertiser(PacketLineOut @out)
 {
     pckOut = @out;
 }
Пример #25
0
        public override void Close()
        {
            if (inStream != null)
            {
                try
                {
                    inStream.Close();
                }
                catch (IOException)
                {

                }
                finally
                {
                    inStream = null;
                    pckIn = null;
                }
            }

            if (outStream != null)
            {
                try
                {
                    if (outNeedsEnd)
                        pckOut.End();
                    outStream.Close();
                }
                catch (IOException)
                {

                }
                finally
                {
                    outStream = null;
                    pckOut = null;
                }
            }

            #if DEBUG
                GC.SuppressFinalize(this); // Disarm lock-release checker
            #endif
        }
Пример #26
0
		protected void setUp()
		{
			rawOut = new MemoryStream();
			o = new PacketLineOut(rawOut);
		}
Пример #27
0
        protected void init(Stream myStream)
        {
            stream = myStream is BufferedStream ? myStream : new BufferedStream(myStream, IndexPack.BUFFER_SIZE);

            pckIn = new PacketLineIn(stream);
            pckOut = new PacketLineOut(stream);
            outNeedsEnd = true;
        }