Exemplo n.º 1
0
        internal void LogError(int CommandID, NNTPError zErr)
        {
            //Debug.WriteLine(Module.MakeMsg(Convert.ToString(zErr.Code), "Command #" + Convert.ToString(CommandID) + " - Error " + Module.MakeErr(zErr)));

            Errors.Enqueue(zErr.Message.Replace(Environment.NewLine, ""));
            ErrorLog.Enqueue(Common.MakeMsg(Convert.ToString(zErr.Code), "Command #" + Convert.ToString(CommandID) + " - Error " + Common.MakeErr(zErr)));
        }
Exemplo n.º 2
0
		private void iSend_Completed(object sender, System.Net.Sockets.SocketAsyncEventArgs e)
		{
			if (CancelSocket) {	return;	}

			try
			{
				if (e.SocketError != SocketError.Success)
				{
                    NNTPError zErr = Common.TranslateError(e.SocketError);
					Close(zErr.Code, zErr.Message);
					return;
				}
			}
			catch (Exception ex) { Close(971, "Send: " + ex.Message); }
    	}
Exemplo n.º 3
0
		private void iReceive_Completed(object sender, System.Net.Sockets.SocketAsyncEventArgs e)
		{

			if (CancelSocket)  { return; }

			try
			{
				if (e.SocketError != SocketError.Success)
				{
                    NNTPError zErr = Common.TranslateError(e.SocketError);
					Close(zErr.Code, zErr.Message);
					return;
				}

                if (e.BytesTransferred < 1)
                {
                    Close(954, "Socket closed.");
                    return;
                }

                if (DataStream == null)
                {
                    DataStream = new MemoryStream(e.BytesTransferred + 1);
                }

                DataStream.Position = DataStream.Length;
                DataStream.Write(e.Buffer, e.Offset, e.BytesTransferred);

				if (e.BytesTransferred >= (e.Buffer.Length / 2.0)) // Dynamic resize
				{
                    if ((e.Buffer.Length - 1) < (MaxBufferSize - 5))
                    {
                        int bsize = 0;

					    if ((e.Buffer.Length * 2) < MaxBufferSize)
					    { bsize = e.Buffer.Length * 2 + 1; }
					    else
					    { bsize = MaxBufferSize + 1; }

                        SetBuffer(bsize);
                    }
				}

                SafeFire(Received, new WorkArgs(DataStream));

            }
			catch (Exception ex) { Close(960, "Rcv: " + ex.Message); }
		}
Exemplo n.º 4
0
		private void iConnect_Completed(object sender, System.Net.Sockets.SocketAsyncEventArgs e)
		{
            try
            {
                if (CancelSocket) { return; }

                if (e.SocketError != SocketError.Success)
                {
                    NNTPError zErr = Common.TranslateError(e.SocketError);
                    Close(zErr.Code, zErr.Message);
                    return;
                }

                iReceive = new System.Net.Sockets.SocketAsyncEventArgs();
                iReceive.Completed += new EventHandler<SocketAsyncEventArgs>(iReceive_Completed);

                if (MaxBufferSize < 1024) { MaxBufferSize = 1024; }

                ClearBuffer();
                SafeFire(Connected, new WorkArgs(951, "Connected"));

            }
            catch (Exception ex) { Close(950, "Connect: " + ex.Message); }
		}
Exemplo n.º 5
0
 internal void LogError(int CommandID, NNTPError zErr)
 {
     Srv.WriteStatus("Command #" + Convert.ToString(CommandID) + " - Error " + Common.MakeErr(zErr));
 }
Exemplo n.º 6
0
        internal static NNTPError TranslateError(SocketError SockErr)
        {
            NNTPError eOut = new NNTPError();

            switch (SockErr)
            {
                case SocketError.Success:

                    eOut.Code = (int)NNTPCodes.SocketSuccess;
                    eOut.Message = "Success.";
                    break;

                case SocketError.Interrupted:

                    eOut.Code = (int)NNTPCodes.SocketInterrupted;
                    eOut.Message = "A blocking Socket call was canceled.";
                    break;

                case SocketError.AccessDenied:

                    eOut.Code = (int)NNTPCodes.SocketAccessDenied;
                    eOut.Message = "An attempt was made to access a Socket in a way that is forbidden by its access permissions.";
                    break;

                case SocketError.Fault:

                    eOut.Code = (int)NNTPCodes.SocketFault;
                    eOut.Message = "An invalid pointer address was detected by the underlying socket provider.";
                    break;

                case SocketError.InvalidArgument:

                    eOut.Code = (int)NNTPCodes.SocketInvalidArgument;
                    eOut.Message = "An invalid argument was supplied to a Socket member.";
                    break;

                case SocketError.TooManyOpenSockets:

                    eOut.Code = (int)NNTPCodes.SocketTooManyOpenSockets;
                    eOut.Message = "There are too many open sockets in the underlying socket provider.";
                    break;

                case SocketError.WouldBlock:

                    eOut.Code = (int)NNTPCodes.SocketWouldBlock;
                    eOut.Message = "An operation on a nonblocking socket cannot be completed immediately.";
                    break;

                case SocketError.InProgress:

                    eOut.Code = (int)NNTPCodes.SocketInProgress;
                    eOut.Message = "A blocking operation is in progress.";
                    break;

                case SocketError.AlreadyInProgress:

                    eOut.Code = (int)NNTPCodes.SocketAlreadyInProgress;
                    eOut.Message = "The nonblocking Socket already has an operation in progress.";
                    break;

                case SocketError.NotSocket:

                    eOut.Code = (int)NNTPCodes.SocketNotSocket;
                    eOut.Message = "A Socket operation was attempted on a non-socket.";
                    break;

                case SocketError.DestinationAddressRequired:

                    eOut.Code = (int)NNTPCodes.SocketDestinationAddressRequired;
                    eOut.Message = "A required address was omitted from an operation on a Socket.";
                    break;

                case SocketError.MessageSize:

                    eOut.Code = (int)NNTPCodes.SocketMessageSize;
                    eOut.Message = "The datagram is too long.";
                    break;

                case SocketError.ProtocolType:

                    eOut.Code = (int)NNTPCodes.SocketProtocolType;
                    eOut.Message = "The protocol type is incorrect for this Socket.";
                    break;

                case SocketError.ProtocolOption:

                    eOut.Code = (int)NNTPCodes.SocketProtocolOption;
                    eOut.Message = "An unknown, invalid, or unsupported option or level was used with a Socket.";
                    break;

                case SocketError.ProtocolNotSupported:

                    eOut.Code = (int)NNTPCodes.SocketProtocolNotSupported;
                    eOut.Message = "The protocol is not implemented or has not been configured.";
                    break;

                case SocketError.SocketNotSupported:

                    eOut.Code = (int)NNTPCodes.SocketSocketNotSupported;
                    eOut.Message = "The support for the specified socket type does not exist in this address family.";
                    break;

                case SocketError.OperationNotSupported:

                    eOut.Code = (int)NNTPCodes.SocketOperationNotSupported;
                    eOut.Message = "The address family is not supported by the protocol family.";
                    break;

                case SocketError.ProtocolFamilyNotSupported:

                    eOut.Code = (int)NNTPCodes.SocketProtocolFamilyNotSupported;
                    eOut.Message = "The protocol family is not implemented or has not been configured.";
                    break;

                case SocketError.AddressFamilyNotSupported:

                    eOut.Code = (int)NNTPCodes.SocketAddressFamilyNotSupported;
                    eOut.Message = "The address family specified is not supported. This error is returned if the IPv6 address family was specified and the IPv6 stack is not installed on the local machine. This error is returned if the IPv4 address family was specified and the IPv4 stack is not installed on the local machine.";
                    break;

                case SocketError.AddressAlreadyInUse:

                    eOut.Code = (int)NNTPCodes.SocketAddressAlreadyInUse;
                    eOut.Message = "Only one use of an address is normally permitted.";
                    break;

                case SocketError.AddressNotAvailable:

                    eOut.Code = (int)NNTPCodes.SocketAddressNotAvailable;
                    eOut.Message = "The selected IP address is not valid in this context.";
                    break;

                case SocketError.NetworkDown:

                    eOut.Code = (int)NNTPCodes.SocketNetworkDown;
                    eOut.Message = "The network is not available.";
                    break;

                case SocketError.NetworkUnreachable:

                    eOut.Code = (int)NNTPCodes.SocketNetworkUnreachable;
                    eOut.Message = "No route to the remote host exists.";
                    break;

                case SocketError.NetworkReset:

                    eOut.Code = (int)NNTPCodes.SocketNetworkReset;
                    eOut.Message = "The application tried to set KeepAlive on a connection that has already timed out.";
                    break;

                case SocketError.ConnectionAborted:

                    eOut.Code = (int)NNTPCodes.SocketConnectionAborted;
                    eOut.Message = "The connection was aborted by the .NET Framework or the underlying socket provider.";
                    break;

                case SocketError.ConnectionReset:

                    eOut.Code = (int)NNTPCodes.SocketConnectionReset;
                    eOut.Message = "The connection was reset by the remote peer.";
                    break;

                case SocketError.NoBufferSpaceAvailable:

                    eOut.Code = (int)NNTPCodes.SocketNoBufferSpaceAvailable;
                    eOut.Message = "No free buffer space is available for a Socket operation.";
                    break;

                case SocketError.IsConnected:

                    eOut.Code = (int)NNTPCodes.SocketIsConnected;
                    eOut.Message = "The Socket is already connected.";
                    break;

                case SocketError.NotConnected:

                    eOut.Code = (int)NNTPCodes.SocketNotConnected;
                    eOut.Message = "The application tried to send or receive data, and the Socket is not connected.";
                    break;

                case SocketError.Shutdown:

                    eOut.Code = (int)NNTPCodes.SocketShutdown;
                    eOut.Message = "A request to send or receive data was disallowed because the Socket has already been closed.";
                    break;

                case SocketError.TimedOut:

                    eOut.Code = (int)NNTPCodes.SocketTimedOut;
                    eOut.Message = "The connection attempt timed out, or the connected host has failed to respond.";
                    break;

                case SocketError.ConnectionRefused:

                    eOut.Code = (int)NNTPCodes.SocketConnectionRefused;
                    eOut.Message = "The remote host is actively refusing a connection.";
                    break;

                case SocketError.HostDown:

                    eOut.Code = (int)NNTPCodes.SocketHostDown;
                    eOut.Message = "The operation failed because the remote host is down.";
                    break;

                case SocketError.HostUnreachable:

                    eOut.Code = (int)NNTPCodes.SocketHostUnreachable;
                    eOut.Message = "There is no network route to the specified host.";
                    break;

                case SocketError.ProcessLimit:

                    eOut.Code = (int)NNTPCodes.SocketProcessLimit;
                    eOut.Message = "Too many processes are using the underlying socket provider.";
                    break;

                case SocketError.SystemNotReady:

                    eOut.Code = (int)NNTPCodes.SocketSystemNotReady;
                    eOut.Message = "The network subsystem is unavailable.";
                    break;

                case SocketError.VersionNotSupported:

                    eOut.Code = (int)NNTPCodes.SocketVersionNotSupported;
                    eOut.Message = "The version of the underlying socket provider is out of range.";
                    break;

                case SocketError.NotInitialized:

                    eOut.Code = (int)NNTPCodes.SocketNotInitialized;
                    eOut.Message = "The underlying socket provider has not been initialized.";
                    break;

                case SocketError.Disconnecting:

                    eOut.Code = (int)NNTPCodes.SocketDisconnecting;
                    eOut.Message = "A graceful shutdown is in progress.";
                    break;

                case SocketError.TypeNotFound:

                    eOut.Code = (int)NNTPCodes.SocketTypeNotFound;
                    eOut.Message = "The specified class was not found.";
                    break;

                case SocketError.HostNotFound:

                    eOut.Code = (int)NNTPCodes.SocketHostNotFound;
                    eOut.Message = "No such host is known. The name is not an official host name or alias.";
                    break;

                case SocketError.TryAgain:

                    eOut.Code = (int)NNTPCodes.SocketTryAgain;
                    eOut.Message = "The name of the host could not be resolved. Try again later.";
                    break;

                case SocketError.NoRecovery:

                    eOut.Code = (int)NNTPCodes.SocketNoRecovery;
                    eOut.Message = "The error is unrecoverable or the requested database cannot be located.";
                    break;

                case SocketError.NoData:

                    eOut.Code = (int)NNTPCodes.SocketNoData;
                    eOut.Message = "The requested name or IP address was not found on the name server.";
                    break;

                case SocketError.IOPending:

                    eOut.Code = (int)NNTPCodes.SocketIOPending;
                    eOut.Message = "The application has initiated an overlapped operation that cannot be completed immediately.";
                    break;

                case SocketError.OperationAborted:

                    eOut.Code = (int)NNTPCodes.SocketOperationAborted;
                    eOut.Message = "The overlapped operation was aborted due to the closure of the Socket.";
                    break;

                default:

                    eOut.Code = (int)NNTPCodes.SocketUnknown;
                    eOut.Message = "An unspecified Socket error has occurred.";
                    break;
            }

            return eOut;
        }
Exemplo n.º 7
0
 internal static string MakeErr(NNTPError zErr)
 {
     return (Convert.ToString(zErr.Code) + " " + zErr.Message);
 }