本文整理汇总了C#中SNIPacket类的典型用法代码示例。如果您正苦于以下问题:C# SNIPacket类的具体用法?C# SNIPacket怎么用?C# SNIPacket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SNIPacket类属于命名空间,在下文中一共展示了SNIPacket类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Send
/// <summary>
/// Send a packet synchronously
/// </summary>
/// <param name="packet">SNI packet</param>
/// <returns>SNI error code</returns>
public uint Send(SNIPacket packet)
{
lock (this)
{
return _lowerHandle.Send(packet);
}
}
示例2: ReceiveAsync
/// <summary>
/// Receive a packet asynchronously
/// </summary>
/// <param name="packet">SNI packet</param>
/// <returns>SNI error code</returns>
public override uint ReceiveAsync(ref SNIPacket packet)
{
lock (_receivedPacketQueue)
{
int queueCount = _receivedPacketQueue.Count;
if (_connectionError != null)
{
return SNICommon.ReportSNIError(_connectionError);
}
if (queueCount == 0)
{
_asyncReceives++;
return TdsEnums.SNI_SUCCESS_IO_PENDING;
}
packet = _receivedPacketQueue.Dequeue();
if (queueCount == 1)
{
_packetEvent.Reset();
}
}
lock (this)
{
_receiveHighwater++;
}
SendAckIfNecessary();
return TdsEnums.SNI_SUCCESS;
}
示例3: HandleSendComplete
/// <summary>
/// Process a send completion
/// </summary>
/// <param name="packet">SNI packet</param>
/// <param name="sniErrorCode">SNI error code</param>
public void HandleSendComplete(SNIPacket packet, uint sniErrorCode)
{
packet.InvokeCompletionCallback(sniErrorCode);
}
示例4: ReceiveAsync
/// <summary>
/// Receive a packet asynchronously
/// </summary>
/// <param name="packet">SNI packet</param>
/// <returns>SNI error code</returns>
public override uint ReceiveAsync(ref SNIPacket packet)
{
lock (this)
{
packet = new SNIPacket(null);
packet.Allocate(_bufferSize);
try
{
packet.ReadFromStreamAsync(_stream, _receiveCallback);
return TdsEnums.SNI_SUCCESS_IO_PENDING;
}
catch (ObjectDisposedException ode)
{
return ReportErrorAndReleasePacket(packet, ode);
}
catch (SocketException se)
{
return ReportErrorAndReleasePacket(packet, se);
}
catch (IOException ioe)
{
return ReportErrorAndReleasePacket(packet, ioe);
}
}
}
示例5: ReportErrorAndReleasePacket
private uint ReportErrorAndReleasePacket(SNIPacket packet, uint nativeError, uint sniError, string errorMessage)
{
if (packet != null)
{
packet.Release();
}
return ReportTcpSNIError(nativeError, sniError, errorMessage);
}
示例6: ReceiveAsync
/// <summary>
/// Receive a packet asynchronously
/// </summary>
/// <param name="packet">SNI packet</param>
/// <returns>SNI error code</returns>
public abstract uint ReceiveAsync(ref SNIPacket packet);
示例7: 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;
}
}
}
示例8: PacketGetData
/// <summary>
/// Get packet data
/// </summary>
/// <param name="packet">SNI packet</param>
/// <param name="inBuff">Buffer</param>
/// <param name="dataSize">Data size</param>
/// <returns>SNI error status</returns>
public uint PacketGetData(SNIPacket packet, byte[] inBuff, ref uint dataSize)
{
int dataSizeInt = 0;
packet.GetData(inBuff, ref dataSizeInt);
dataSize = (uint)dataSizeInt;
return TdsEnums.SNI_SUCCESS;
}
示例9: ReadSyncOverAsync
/// <summary>
/// Read synchronously
/// </summary>
/// <param name="handle">SNI handle</param>
/// <param name="packet">SNI packet</param>
/// <param name="timeout">Timeout</param>
/// <returns>SNI error status</returns>
public uint ReadSyncOverAsync(SNIHandle handle, out SNIPacket packet, int timeout)
{
return handle.Receive(out packet, timeout);
}
示例10: SendControlPacket
/// <summary>
/// Send control packet
/// </summary>
/// <param name="flags">SMUX header flags</param>
private void SendControlPacket(SNISMUXFlags flags)
{
byte[] headerBytes = null;
lock (this)
{
GetSMUXHeaderBytes(0, (byte)flags, ref headerBytes);
}
SNIPacket packet = new SNIPacket(null);
packet.SetData(headerBytes, SNISMUXHeader.HEADER_LENGTH);
_connection.Send(packet);
}
示例11: ReportErrorAndReleasePacket
private uint ReportErrorAndReleasePacket(SNIPacket packet, string errorMessage)
{
packet.Release();
return ReportTcpSNIError(0, 0, errorMessage);
}
示例12: 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)
{
packet = null;
int queueCount;
uint result = TdsEnums.SNI_SUCCESS_IO_PENDING;
while (true)
{
lock (_receivedPacketQueue)
{
if (_connectionError != null)
{
return SNICommon.ReportSNIError(_connectionError);
}
queueCount = _receivedPacketQueue.Count;
if (queueCount > 0)
{
packet = _receivedPacketQueue.Dequeue();
if (queueCount == 1)
{
_packetEvent.Reset();
}
result = TdsEnums.SNI_SUCCESS;
}
}
if (result == TdsEnums.SNI_SUCCESS)
{
lock (this)
{
_receiveHighwater++;
}
SendAckIfNecessary();
return result;
}
if (!_packetEvent.Wait(timeoutInMilliseconds))
{
SNILoadHandle.SingletonInstance.LastError = new SNIError(SNIProviders.SMUX_PROV, 0, 11, SR.SNI_ERROR_11);
return TdsEnums.SNI_WAIT_TIMEOUT;
}
}
}
示例13: HandleReceiveComplete
/// <summary>
/// Handle receive completion
/// </summary>
/// <param name="packet">SNI packet</param>
/// <param name="header">SMUX header</param>
public void HandleReceiveComplete(SNIPacket packet, SNISMUXHeader header)
{
lock (this)
{
if (_sendHighwater != header.highwater)
{
HandleAck(header.highwater);
}
lock (_receivedPacketQueue)
{
if (_asyncReceives == 0)
{
_receivedPacketQueue.Enqueue(packet);
_packetEvent.Set();
return;
}
_asyncReceives--;
Debug.Assert(_callbackObject != null);
#if MANAGED_SNI // Causes build issue if uncommented in unmanaged version
((TdsParserStateObject)_callbackObject).ReadAsyncCallback(packet, 0);
#endif
}
}
lock (this)
{
_receiveHighwater++;
}
SendAckIfNecessary();
}
示例14: HandleSendComplete
/// <summary>
/// Handle send completion
/// </summary>
/// <param name="packet">SNI packet</param>
/// <param name="sniErrorCode">SNI error code</param>
public void HandleSendComplete(SNIPacket packet, uint sniErrorCode)
{
lock (this)
{
Debug.Assert(_callbackObject != null);
#if MANAGED_SNI // Causes build issue if uncommented in unmanaged version
((TdsParserStateObject)_callbackObject).WriteAsyncCallback(packet, sniErrorCode);
#endif
}
}
示例15: SendAsync
/// <summary>
/// Send a packet asynchronously
/// </summary>
/// <param name="packet">SNI packet</param>
/// <param name="callback">Completion callback</param>
/// <returns>SNI error code</returns>
public abstract uint SendAsync(SNIPacket packet, SNIAsyncCallback callback = null);