Пример #1
0
        // IoBuff
        /// <summary>
        /// Class constructor for output buffers.  Sub-class must set
        /// buffer size to initialize the input buffer.
        /// </summary>
        /// <param name="outStream">The associated output stream.</param>
        protected internal IoBuff(OutputStream outStream)
        {
            trace = new Tracing(DAM_NL_TRACE_ID);

                title = "IoBuff[out]";
                this.outputStream = outStream;
        }
Пример #2
0
        /*
        ** Name: close
        **
        ** Description:
        **	Close the associated I/O stream.
        **
        ** Input:
        **	None.
        **
        ** Output:
        **	None.
        **
        ** Returns:
        **	void
        **
        ** History:
        **	 9-Jun-99 (gordy)
        **	    Created.
        **	29-Sep-99 (gordy)
        **	    A recursive loop can occur if a flush fails, which
        **	    calls close() which calls flush(), etc.  Made sure
        **	    close() won't recurse by setting the closed flag
        **	    prior to calling flush().*/
        /// <summary>
        /// Close the associated I/O stream.
        /// </summary>
        public virtual void close()
        {
            lock(this)
            {
                if (!closed)
                {
                    closed = true;

                    if (inputStream != null)
                        try
                        {
                            inputStream.Close();
                        }
                        catch (Exception /* ignore */)
                        {
                        }

                    if (outputStream != null)
                    {
                        try
                        {
                            setSegSize();
                            flushBuffer(true);
                        }
                        catch (Exception /* ignore */)
                        {
                        }
                        try
                        {
                            outputStream.Close();
                        }
                        catch (Exception /* ignore */)
                        {
                        }
                    }

                    clearBuffer();
                    inputStream  = null;
                    outputStream = null;
                    if (trace.enabled(3))
                        trace.write(title + ": closed");
                }

                return ;
            }
        }
Пример #3
0
        /*
        ** Name: cancel
        **
        ** Description:
        **	Issues an interrupt to the Data Access Server which
        **	will attempt to cancel any active query.
        **
        ** Input:
        **	None.
        **
        ** Output:
        **	None.
        **
        ** Returns:
        **	void.
        **
        ** History:
        **	 4-Nov-99 (gordy)
        **	    Created.
        **	26-Dec-02 (gordy)
        **	    Allocate cncl buffer on first request.
        */
        public virtual void cancel()
        {
            lock(this)
            {
                /*
                ** Allocate cancel buffer on first request.
                */
                if ( cncl == null )
                    try
                    {
                        // wrap the socket's NetworkStream in our OutputStream
                        OutputStream outputStream = new OutputStream(socket.GetStream());
                        cncl = new OutBuff(outputStream, ConnID, 16);
                        cncl.TL_ProtocolLevel = this.TL_ProtocolLevel;
                    }
                    catch( Exception ex )
                    {
                        if ( trace.enabled( 1 ) )
                            trace.write( title + ": error creating cancel buffer: " +
                                ex.Message );
                        disconnect();
                        throw SqlEx.get( ERR_GC4001_CONNECT_ERR, ex );
                    }

                try
                {
                    if ( trace.enabled( 2 ) )
                        trace.write( title + ": interrupt network connection" );
                    cncl.begin( DAM_TL_INT, 0 );
                    cncl.flush();
                }
                catch( SqlEx ex )
                {
                    disconnect();
                    throw ex;
                }

                return;
            }
        }
Пример #4
0
        /*
        ** Name: connect
        **
        ** Description:
        **	Connect to target server.  Initializes the output buffer.
        **
        ** Input:
        **	host	Host name or address.
        **	portID	Symbolic or numeric port ID.
        **
        ** Output:
        **	None.
        **
        ** Returns:
        **	void.
        **
        ** History:
        **	 7-Jun-99 (gordy)
        **	    Created.
        **	17-Nov-99 (gordy)
        **	    Extracted output functionality from DbConn.
        **	 3-Nov-08 (gordy, ported by thoda04)
        **	    Extracted from constructor.
        */
        protected internal override void connect(String host, String portID)
        {
            base.connect( host, portID );

            try
            {
            // wrap the socket's NetworkStream in our OutputStream
            OutputStream outputStream = new OutputStream(socket.GetStream());
            outBuff = new OutBuff(outputStream, ConnID, 1 << DAM_TL_PKT_MIN);
            }
            catch (System.Exception ex)
            {
            if (trace.enabled(1))
                trace.write(title + ": error creating output buffer: " + ex.Message);
            disconnect();
            throw SqlEx.get(ERR_GC4001_CONNECT_ERR, ex);
            }

            return;
        }
Пример #5
0
 public OutputStreamWriter(OutputStream stream, System.Text.Encoding encoding)
     : base(stream, encoding)
 {
 }
Пример #6
0
        /*
        ** Name: get
        **
        ** Description:
        **	Write the current data value to an OutputStream.
        **	The current data value is consumed.  The Output-
        **	Stream is not closed.
        **
        **	Note: the value returned when the data value is
        **	NULL is not well defined.
        **
        ** Input:
        **	os	OutputStream to receive data value.
        **
        ** Output:
        **	None.
        **
        ** Returns:
        **	void.
        **
        ** History:
        **	 1-Dec-03 (gordy)
        **	    Created.
        */
        public void get(OutputStream os)
        {
            Object stream = getStream();

            if (stream != null)
                if (stream is InputStream)
                    copyIs2Os((InputStream)stream, os);
                else if (stream is Reader)
                {
                    OutputStreamWriter wtr;

                    try { wtr = charSet.getOSW(os); }
                    catch (Exception /* ex */)	// Should not happen!
                    { throw SqlEx.get(ERR_GC401E_CHAR_ENCODE); }

                    copyRdr2Wtr((Reader)stream, wtr);
                }
                else
                    throw SqlEx.get(ERR_GC401A_CONVERSION_ERR);
            return;
        }
Пример #7
0
 public OutputStreamWriter(OutputStream stream)
     : base(stream)
 {
 }
Пример #8
0
        /*
        ** Name: getOSW
        **
        ** Description:
        **	Returns an OutputStreamWriter for conversion using the
        **	associated encoding and output to provided stream.
        **
        ** Input:
        **	stream		    OutputStream to receive conversion.
        **
        ** Output:
        **	None.
        **
        ** Returns:
        **	OutputStreamWriter  Writer for encoding conversion to stream
        **
        ** History:
        **	 6-Sep-02 (gordy)
        **	    Created.
        **	11-Nov-02 (thoda04)
        **	    Ported to .NET Provider.
        */
        public virtual OutputStreamWriter getOSW(OutputStream stream)
        {
            OutputStreamWriter osw;

            if (encoding == null)
                osw = new OutputStreamWriter(stream);
            else
                osw = new OutputStreamWriter(stream, encoding);

            return (osw);
        }
Пример #9
0
        /*
        ** Name: copyIs2Os
        **
        ** Description:
        **	Writes the contents of an InputStream to an OutputStream.
        **	The InputStream is closed.  The OutputStream is flushed
        **	but not closed.
        **
        ** Input:
        **	is	InputStream.
        **	os	OutputStream.
        **
        ** Output:
        **	None.
        **
        ** Returns:
        **	void.
        **
        ** History:
        **	 1-Dec-03 (gordy)
        **	    Created.
        */
        protected void copyIs2Os(InputStream inputStream, OutputStream outputStream)
        {
            if (bbuff == null)
                lock (this)
                {
                    { if (bbuff == null)  bbuff = new byte[8192]; }
                }

            try
            {
                lock (bbuff)
                {
                    for (int len = inputStream.read(bbuff); len >= 0;
                        len = inputStream.read(bbuff))
                        outputStream.write(bbuff, 0, len);
                }

                inputStream.close();
                outputStream.flush();
            }
            catch (Exception ex)
            {
                try { inputStream.close(); }
                catch (Exception /* ignore */) { }
                try { outputStream.flush(); }
                catch (Exception /* ignore */) { }
                throw SqlEx.get(ERR_GC4007_BLOB_IO, ex);
            }

            return;
        }
Пример #10
0
 /*
 ** Name: get
 **
 ** Description:
 **	Write the current data value to an OutputStream.
 **	The current data value is consumed.  The Output-
 **	Stream is not closed.
 **
 **	Note: the value returned when the data value is
 **	NULL is not well defined.
 **
 ** Input:
 **	os	OutputStream to receive data value.  Usually ByteSegOS
 **
 ** Output:
 **	None.
 **
 ** Returns:
 **	void.
 **
 ** History:
 **	 1-Dec-03 (gordy)
 **	    Created.
 */
 public void get(OutputStream os)
 {
     copyIs2Os((InputStream)getStream(), os);
     return;
 }
Пример #11
0
        protected internal new ITrace trace; // DAM-TL tracing (overrides IoBuff)

        #endregion Fields

        #region Constructors

        /*
        ** Name: OutBuff
        **
        ** Description:
        **	Class constructor.
        **
        ** Input:
        **	out	Associated output stream.
        **	id	Connection ID.
        **	size	Length of output buffer.
        **
        ** Output:
        **	None.
        **
        ** History:
        **	16-Jun-99 (gordy)
        **	    Created.
        **	 1-Oct-02 (gordy)
        **	    Buffer size now set explicitly rather than super-class
        **	    initialization.
        */
        /// <summary>
        /// Create an OutputStream buffer with spwecified size.
        /// </summary>
        /// <param name="outputStream">Associated output stream.</param>
        /// <param name="id">Connection ID.</param>
        /// <param name="size">Length of output buffer.</param>
        public OutBuff(OutputStream outputStream, int id, int size)
            : base(outputStream)
        {
            title = "OutBuff[" + id + "]";
            trace = new Tracing(DAM_TL_TRACE_ID);
            BuffSize = size;
        }