本文整理汇总了C#中SNIPacket.ReadFromStream方法的典型用法代码示例。如果您正苦于以下问题:C# SNIPacket.ReadFromStream方法的具体用法?C# SNIPacket.ReadFromStream怎么用?C# SNIPacket.ReadFromStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SNIPacket
的用法示例。
在下文中一共展示了SNIPacket.ReadFromStream方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Receive
public override uint Receive(out SNIPacket packet, int timeout)
{
lock (this)
{
packet = null;
try
{
packet = new SNIPacket(null);
packet.Allocate(_bufferSize);
packet.ReadFromStream(_stream);
if (packet.Length == 0)
{
return ReportErrorAndReleasePacket(packet, 0, SNICommon.ConnTerminatedError, string.Empty);
}
}
catch (ObjectDisposedException ode)
{
return ReportErrorAndReleasePacket(packet, ode);
}
catch (IOException ioe)
{
return ReportErrorAndReleasePacket(packet, ioe);
}
return TdsEnums.SNI_SUCCESS;
}
}
示例2: Receive
/// <summary>
/// Receive a packet synchronously
/// </summary>
/// <param name="packet">SNI packet</param>
/// <param name="timeoutInMilliseconds">Timeout in Milliseconds</param>
/// <returns>SNI error code</returns>
public override uint Receive(out SNIPacket packet, int timeoutInMilliseconds)
{
lock (this)
{
packet = null;
try
{
if (timeoutInMilliseconds > 0)
{
_socket.ReceiveTimeout = timeoutInMilliseconds;
}
else if (timeoutInMilliseconds == -1)
{ // SqlCient internally represents infinite timeout by -1, and for TcpClient this is translated to a timeout of 0
_socket.ReceiveTimeout = 0;
}
else
{
// otherwise it is timeout for 0 or less than -1
ReportTcpSNIError(0, SNICommon.ConnTimeoutError, string.Empty);
return TdsEnums.SNI_WAIT_TIMEOUT;
}
packet = new SNIPacket(null);
packet.Allocate(_bufferSize);
packet.ReadFromStream(_stream);
if (packet.Length == 0)
{
return ReportErrorAndReleasePacket(packet, 0, SNICommon.ConnTerminatedError, string.Empty);
}
return TdsEnums.SNI_SUCCESS;
}
catch (ObjectDisposedException ode)
{
return ReportErrorAndReleasePacket(packet, ode);
}
catch (SocketException se)
{
return ReportErrorAndReleasePacket(packet, se);
}
catch (IOException ioe)
{
uint errorCode = ReportErrorAndReleasePacket(packet, ioe);
if (ioe.InnerException is SocketException && ((SocketException)(ioe.InnerException)).SocketErrorCode == SocketError.TimedOut)
{
errorCode = TdsEnums.SNI_WAIT_TIMEOUT;
}
return errorCode;
}
finally
{
_socket.ReceiveTimeout = 0;
}
}
}
示例3: Receive
/// <summary>
/// Receive a packet synchronously
/// </summary>
/// <param name="packet">SNI packet</param>
/// <param name="timeout">Timeout</param>
/// <returns>SNI error code</returns>
public override uint Receive(ref SNIPacket packet, int timeout)
{
lock (this)
{
try
{
_tcpClient.ReceiveTimeout = (timeout != 0) ? timeout : 1;
packet = new SNIPacket(null);
packet.Allocate(_bufferSize);
packet.ReadFromStream(_stream);
if (packet.Length == 0)
{
return ReportErrorAndReleasePacket(packet, "Connection was terminated");
}
return TdsEnums.SNI_SUCCESS;
}
catch (ObjectDisposedException ode)
{
return ReportErrorAndReleasePacket(packet, ode.Message);
}
catch (SocketException se)
{
return ReportErrorAndReleasePacket(packet, se.Message);
}
catch (IOException ioe)
{
uint errorCode = ReportErrorAndReleasePacket(packet, ioe.Message);
if (ioe.InnerException is SocketException && ((SocketException)(ioe.InnerException)).SocketErrorCode == SocketError.TimedOut)
{
errorCode = TdsEnums.SNI_WAIT_TIMEOUT;
}
return errorCode;
}
finally
{
_tcpClient.ReceiveTimeout = 0;
}
}
}