private void writeControlMessage(List <byte> data)
        {
            List <byte> new_data = Struct.packByte((byte)1);

            new_data.AddRange(data);
            base.write(new_data.ToArray());
        }
Пример #2
0
        private byte[] core_create_proc(byte[] args)
        {
            List <byte> data = new List <byte>(args);

            // first byte indicates if STDIN, STDOUT and STDERR should be streamed to channels
            bool   use_channels  = (Struct.extractByte(data) != 0);
            string proc_filename = Struct.extractNullTerminatedString(data);
            string proc_args     = Struct.extractNullTerminatedString(data);

            ClientProcess proc = new ClientProcess(proc_filename, proc_args, use_channels, this.callbackChannelOutputPresent, this.triggerProcessingNeeded); //starts the process already

            proc.registerOnExitCallback(this.onProcessExit);


            if (use_channels)
            {
                this.AddChannel(proc.Ch_stdin);
                this.AddChannel(proc.Ch_stdout);
                this.AddChannel(proc.Ch_stderr);


                /*
                 * proc.Ch_stdin = this.tl.CreateChannel(Channel.Types.IN, Channel.Encodings.UTF8);
                 * proc.Ch_stdout = this.tl.CreateChannel(Channel.Types.OUT, Channel.Encodings.UTF8);
                 * proc.Ch_stderr = this.tl.CreateChannel(Channel.Types.OUT, Channel.Encodings.UTF8);
                 */
            }



            //generate method response
            List <byte> resp = Struct.packUInt32((UInt32)proc.Id);

            if (use_channels)
            {
                resp = Struct.packByte(1, resp);
                resp = Struct.packUInt32(proc.Ch_stdin.ID, resp);
                resp = Struct.packUInt32(proc.Ch_stdout.ID, resp);
                resp = Struct.packUInt32(proc.Ch_stderr.ID, resp);
            }
            else
            {
                resp = Struct.packByte(0, resp);
                resp = Struct.packUInt32(0, resp);
                resp = Struct.packUInt32(0, resp);
                resp = Struct.packUInt32(0, resp);
            }

            Monitor.Enter(this.pendingClientProcessesLock);
            this.pending_client_processes.Add(proc.Id, proc);
            Monitor.Exit(this.pendingClientProcessesLock);

            //throw new ClientMethodException(String.Format("Not implemented: Trying to start proc '{0}' with args: {1}", proc_filename, proc_args));
            return(resp.ToArray());
        }
        private void writeData(List <byte> data)
        {
            List <byte> new_data = Struct.packByte((byte)0);

            new_data.AddRange(data);
            this.outbuf_size += data.Count;
            if (this.passthrough && (this.outbuf_size >= this.passthrough_limit))
            {
                this.passtrough_limit_not_reached.Reset();
            }
            base.write(new_data.ToArray());
        }
        public byte[] createResponse()
        {
            // this function should only be called when the method has finished (finished member == $true), but anyway, this isn't checked here

            // first response field is uint32 method id
            List <byte> response = Struct.packUInt32(this.id);

            // next field is a ubyte indicating success or error (0 success, everything else error)
            if (this.error)
            {
                response = Struct.packByte((byte)1, response);                            // indicating an error
                response = Struct.packNullTerminatedString(this.error_message, response); //append error message
                return(response.ToArray());                                               // hand back error response
            }

            response = Struct.packByte((byte)0, response); // add success field
            response = Struct.packByteArray(this.result, response);

            return(response.ToArray()); // return result
        }