本文整理汇总了C#中SocketError.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# SocketError.ToString方法的具体用法?C# SocketError.ToString怎么用?C# SocketError.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SocketError
的用法示例。
在下文中一共展示了SocketError.ToString方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
/// <summary>
/// Create and return a new NetMQException with no Message containing the given SocketError and Exception.
/// </summary>
/// <param name="error">a SocketError that this exception will carry and expose via its ErrorCode property</param>
/// <param name="innerException">an Exception that this exception will expose via its InnerException property</param>
/// <returns>a new NetMQException</returns>
public static NetMQException Create(SocketError error, Exception innerException = null)
{
var errorCode = error.ToErrorCode();
#if DEBUG
if (errorCode == 0)
{
var s = string.Format("(And within NetMQException.Create: Unanticipated error-code: {0})", error.ToString());
return Create(errorCode: errorCode, message: s, innerException: innerException);
}
#endif
return Create(errorCode, innerException);
}
示例2: CheckAsyncCallOverlappedResult
// This method is called after an asynchronous call is made for the user.
// It checks and acts accordingly if the IO:
// 1) completed synchronously.
// 2) was pended.
// 3) failed.
internal unsafe SocketError CheckAsyncCallOverlappedResult(SocketError errorCode)
{
GlobalLog.Print(
"BaseOverlappedAsyncResult#" + LoggingHash.HashString(this) +
"::CheckAsyncCallOverlappedResult(" + errorCode.ToString() + ")");
if (errorCode == SocketError.Success || errorCode == SocketError.IOPending)
{
// Ignore cases in which a completion packet will be queued:
// we'll deal with this IO in the callback.
return SocketError.Success;
}
// In the remaining cases a completion packet will NOT be queued:
// we have to call the callback explicitly signaling an error.
ErrorCode = (int)errorCode;
Result = -1;
ReleaseUnmanagedStructures(); // Additional release for the completion that won't happen.
return errorCode;
}
示例3: UpdateStatusAfterSocketError
internal void UpdateStatusAfterSocketError(SocketError errorCode)
{
// If we already know the socket is disconnected
// we don't need to do anything else.
GlobalLog.Print("Socket#" + Logging.HashString(this) + "::UpdateStatusAfterSocketError(socketException)");
if (s_loggingEnabled)
{
Logging.PrintError(Logging.Sockets, this, "UpdateStatusAfterSocketError", errorCode.ToString());
}
if (_isConnected && (_handle.IsInvalid || (errorCode != SocketError.WouldBlock &&
errorCode != SocketError.IOPending && errorCode != SocketError.NoBufferSpaceAvailable &&
errorCode != SocketError.TimedOut)))
{
// The socket is no longer a valid socket.
GlobalLog.Print("Socket#" + Logging.HashString(this) + "::UpdateStatusAfterSocketError(socketException) Invalidating socket.");
SetToDisconnected();
}
}
示例4: Create
public static NetMQException Create(SocketError error, [CanBeNull] Exception innerException = null)
{
ErrorCode errorCode;
switch (error)
{
case SocketError.AccessDenied:
errorCode = ErrorCode.AccessDenied;
break;
case SocketError.Fault:
errorCode = ErrorCode.Fault;
break;
case SocketError.InvalidArgument:
errorCode = ErrorCode.Invalid;
break;
case SocketError.TooManyOpenSockets:
errorCode = ErrorCode.TooManyOpenSockets;
break;
case SocketError.InProgress:
errorCode = ErrorCode.TryAgain;
break;
case SocketError.MessageSize:
errorCode = ErrorCode.MessageSize;
break;
case SocketError.ProtocolNotSupported:
errorCode = ErrorCode.ProtocolNotSupported;
break;
case SocketError.AddressFamilyNotSupported:
errorCode = ErrorCode.AddressFamilyNotSupported;
break;
case SocketError.AddressNotAvailable:
errorCode = ErrorCode.AddressNotAvailable;
break;
case SocketError.NetworkDown:
errorCode = ErrorCode.NetworkDown;
break;
case SocketError.NetworkUnreachable:
errorCode = ErrorCode.NetworkUnreachable;
break;
case SocketError.NetworkReset:
errorCode = ErrorCode.NetworkReset;
break;
case SocketError.ConnectionAborted:
errorCode = ErrorCode.ConnectionAborted;
break;
case SocketError.ConnectionReset:
errorCode = ErrorCode.ConnectionReset;
break;
case SocketError.NoBufferSpaceAvailable:
errorCode = ErrorCode.NoBufferSpaceAvailable;
break;
case SocketError.NotConnected:
errorCode = ErrorCode.NotConnected;
break;
case SocketError.TimedOut:
errorCode = ErrorCode.TimedOut;
break;
case SocketError.ConnectionRefused:
errorCode = ErrorCode.ConnectionRefused;
break;
case SocketError.HostUnreachable:
errorCode = ErrorCode.HostUnreachable;
break;
default:
errorCode = 0; // to indicate no valid SocketError.
#if DEBUG
string s = string.Format("(And within NetMQException.Create: Unanticipated error-code: {0})", error.ToString());
return Create(errorCode: errorCode, message: s, innerException: innerException);
#else
break;
#endif
}
return Create(errorCode, innerException);
}
示例5: UpdateStatusAfterSocketError
internal void UpdateStatusAfterSocketError(SocketError errorCode)
{
// If we already know the socket is disconnected
// we don't need to do anything else.
if (GlobalLog.IsEnabled)
{
GlobalLog.Print("Socket#" + LoggingHash.HashString(this) + "::UpdateStatusAfterSocketError(socketException)");
}
if (s_loggingEnabled)
{
NetEventSource.PrintError(NetEventSource.ComponentType.Socket, this, nameof(UpdateStatusAfterSocketError), errorCode.ToString());
}
if (_isConnected && (_handle.IsInvalid || (errorCode != SocketError.WouldBlock &&
errorCode != SocketError.IOPending && errorCode != SocketError.NoBufferSpaceAvailable &&
errorCode != SocketError.TimedOut)))
{
// The socket is no longer a valid socket.
if (GlobalLog.IsEnabled)
{
GlobalLog.Print("Socket#" + LoggingHash.HashString(this) + "::UpdateStatusAfterSocketError(socketException) Invalidating socket.");
}
SetToDisconnected();
}
}
示例6: OnReceiveResolved
/// <summary>
/// Gets called when a receive operation resolves. If we were listening for data and the connection
/// closed, that also counts as a receive operation resolving.
/// </summary>
/// <param name="args"></param>
private void OnReceiveResolved(bool isUDP, byte[] buffer, int bytesReceived, SocketError status, SockState sockState)
{
SocketDebug(19);
//// Log.LogMsg("==>++++ Async RECEIVE Op Completed - #" + ((SockState)args.UserToken).ID.ToString() + "#");
try
{
if (!OwningConnection.IsAlive && bytesReceived > 0)
{
SocketDebug(20);
return;
}
SocketDebug(21);
// If there was a socket error, close the connection. This is NOT a normal
// situation, if you get an error here.
if (status != SocketError.Success)
{
SocketDebug(22);
Log.LogMsg("Receive status = " + status.ToString());
if (!OwningConnection.ShuttingDown)
{
//// Log.LogMsg("Testy 111");
OwningConnection.KillConnection("Connection lost! Network receive error: " + status);
}
//Jump out of the ProcessReceive method.
SocketDebug(23);
return;
}
SocketDebug(24);
m_TCPSockState.AsyncEventArgs.RemoteEndPoint = OwningConnection.MyTCPSocket.RemoteEndPoint;
// If no data was received, close the connection. This is a NORMAL
// situation that shows when the client has finished sending data.
if (bytesReceived == 0)
{
SocketDebug(25);
if (!OwningConnection.ShuttingDown)
{
//// Log.LogMsg("Testy 114");
OwningConnection.KillConnection("Connection closed by remote host.");
}
return;
}
SocketDebug(26);
OwningConnection.ReceivedBytes(bytesReceived);
// restart listening process
SocketDebug(27);
OwningConnection.AssembleInboundPacket(buffer, bytesReceived, sockState);
SocketDebug(28);
}
catch (Exception ex)
{
Log.LogMsg("Error ProcessReceive. " + ex.Message);
OwningConnection.KillConnection("Error receive. " + ex.Message);
}
}
示例7: ProcessSocketError
private void ProcessSocketError(Socket socket, SocketError socketError)
{
if (socketError == SocketError.Success)
{
// No problems here
return;
}
if (socketError == SocketError.ConnectionReset) // disconnect
{
if (this.RemoteDisconnect != null)
{
this.RemoteDisconnect(socket, EventArgs.Empty);
return; // That's all we need to do
}
}
if (this.UnhandledSocketError != null)
{
this.UnhandledSocketError(socket, socketError);
return;
}
Console.WriteLine(string.Format("Socket error: {0}", socketError.ToString()));
// throw new CommunicationException("Socket error: " + socketError.ToString(), new SocketException());
}
示例8: Create
public static NetMQException Create(SocketError error, [CanBeNull] Exception innerException = null)
{
var errorCode = error.ToErrorCode();
#if DEBUG
if (errorCode == 0)
{
var s = $"(And within NetMQException.Create: Unanticipated error-code: {error.ToString()})";
return Create(errorCode: errorCode, message: s, innerException: innerException);
}
#endif
return Create(errorCode, innerException);
}
示例9: ShouldRetryAccept
bool ShouldRetryAccept(SocketError error)
{
if (error == SocketError.OperationAborted)
{
// Close/Abort was called
return false;
}
else
{
AmqpTrace.Provider.AmqpListenSocketAcceptError(this, true, error.ToString());
return true;
}
}