Esempio n. 1
0
 public override uint Send(SNIPacket packet)
 {
     lock (this)
     {
         try
         {
             packet.WriteToStream(_stream);
             return(TdsEnums.SNI_SUCCESS);
         }
         catch (ObjectDisposedException ode)
         {
             return(ReportErrorAndReleasePacket(packet, ode));
         }
         catch (IOException ioe)
         {
             return(ReportErrorAndReleasePacket(packet, ioe));
         }
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Send a packet synchronously
 /// </summary>
 /// <param name="packet">SNI packet</param>
 /// <returns>SNI error code</returns>
 public override uint Send(SNIPacket packet)
 {
     try
     {
         packet.WriteToStream(_stream);
         return(TdsEnums.SNI_SUCCESS);
     }
     catch (ObjectDisposedException ode)
     {
         return(ReportTcpSNIError(ode));
     }
     catch (SocketException se)
     {
         return(ReportTcpSNIError(se));
     }
     catch (IOException ioe)
     {
         return(ReportTcpSNIError(ioe));
     }
 }
Esempio n. 3
0
        public override uint SendAsync(SNIPacket packet, SNIAsyncCallback callback = null)
        {
            SNIPacket newPacket = packet;

            _writeTaskFactory.StartNew(() =>
            {
                try
                {
                    lock (this)
                    {
                        packet.WriteToStream(_stream);
                    }
                }
                catch (Exception e)
                {
                    SNICommon.ReportSNIError(SNIProviders.NP_PROV, SNICommon.InternalExceptionError, e);

                    if (callback != null)
                    {
                        callback(packet, TdsEnums.SNI_ERROR);
                    }
                    else
                    {
                        _sendCallback(packet, TdsEnums.SNI_ERROR);
                    }

                    return;
                }

                if (callback != null)
                {
                    callback(packet, TdsEnums.SNI_SUCCESS);
                }
                else
                {
                    _sendCallback(packet, TdsEnums.SNI_SUCCESS);
                }
            });

            return(TdsEnums.SNI_SUCCESS_IO_PENDING);
        }
Esempio n. 4
0
        /// <summary>
        /// Send a packet asynchronously
        /// </summary>
        /// <param name="packet">SNI packet</param>
        /// <param name="callback">Completion callback</param>
        /// <returns>SNI error code</returns>
        public override uint SendAsync(SNIPacket packet, SNIAsyncCallback callback = null)
        {
            SNIPacket newPacket = packet;

            _writeTaskFactory.StartNew(() =>
            {
                try
                {
                    lock (this)
                    {
                        packet.WriteToStream(_stream);
                    }
                }
                catch (Exception e)
                {
                    SNILoadHandle.SingletonInstance.LastError = new SNIError(SNIProviders.TCP_PROV, 0, 0, e.Message);

                    if (callback != null)
                    {
                        callback(packet, TdsEnums.SNI_ERROR);
                    }
                    else
                    {
                        _sendCallback(packet, TdsEnums.SNI_ERROR);
                    }

                    return;
                }

                if (callback != null)
                {
                    callback(packet, TdsEnums.SNI_SUCCESS);
                }
                else
                {
                    _sendCallback(packet, TdsEnums.SNI_SUCCESS);
                }
            });

            return(TdsEnums.SNI_SUCCESS_IO_PENDING);
        }
Esempio n. 5
0
 /// <summary>
 /// Send a packet synchronously
 /// </summary>
 /// <param name="packet">SNI packet</param>
 /// <returns>SNI error code</returns>
 public sealed override SNIError Send(SNIPacket packet)
 {
     using (_debugLock.Acquire(this))
     {
         try
         {
             packet.WriteToStream(_stream);
             return(null);
         }
         catch (ObjectDisposedException ode)
         {
             return(new SNIError(ProviderNumber, 0, ode));
         }
         catch (SocketException se)
         {
             return(new SNIError(ProviderNumber, 0, se));
         }
         catch (IOException ioe)
         {
             return(new SNIError(ProviderNumber, 0, ioe));
         }
     }
 }