Beispiel #1
0
        /// <summary>取得該錯誤的信件內容</summary>
        /// <param name="sessionKey"></param>
        /// <param name="ex"></param>
        /// <returns></returns>
        private static string GetExceptionLogString(string sessionKey, Exception ex)
        {
            StringBuilder sb = new StringBuilder();

            try
            {
                sb.AppendLine(string.Format("DateTime:{0:yyyy/MM/dd HH\\:mm\\:ss.fff}", DateTime.Now));
                sb.AppendLine(string.Format("[{0}]EX:Type:{1}", sessionKey, ex.GetType()));
                if (ex.GetType().Equals(typeof(System.Net.Sockets.SocketException)))
                {
                    System.Net.Sockets.SocketException se = (System.Net.Sockets.SocketException)ex;
                    sb.AppendLine(string.Format("[{0}]EX:ErrorCode:{1}", sessionKey, se.ErrorCode));
                    sb.AppendLine(string.Format("[{0}]EX:SocketErrorCode:{1}:{2}", sessionKey, se.SocketErrorCode, (int)se.SocketErrorCode));
                    sb.AppendLine(string.Format("[{0}]EX:NativeErrorCode:{1}", sessionKey, se.NativeErrorCode));
                }
                sb.AppendLine(string.Format("[{0}]EX:Message:{1}", sessionKey, ex.Message));
                sb.AppendLine(string.Format("[{0}]EX:Source:{1}", sessionKey, ex.Source));
                sb.AppendLine(string.Format("[{0}]EX:StackTrace:{1}", sessionKey, ex.StackTrace));
                foreach (System.Collections.DictionaryEntry de in ex.Data)
                {
                    sb.AppendLine(string.Format("[{0}]EX:Data:{1}:{2}", sessionKey, de.Key, de.Value));
                }
                if (ex.InnerException != null)
                {
                    sb.AppendLine("InnerException:");
                    sb.AppendLine(GetExceptionLogString(sessionKey, ex.InnerException));
                }
            }
            catch { }
            return(sb.ToString());
        }
        private static void test2()
        {
            Exception beklenen = new System.Net.Sockets.SocketException();
            Exception sonuc    = null;

            try
            {
                ClientDemo.Client client = new ClientDemo.Client();


                client.ConnectToServer();

                for (int i = 0; i < 10; i++)
                {
                    client.SendMessage("saatkac");
                    Thread.Sleep(10);
                }
            }
            catch (Exception ex)
            {
                sonuc = ex;
            }

            if (sonuc.GetType().Name == beklenen.GetType().Name)
            {
                Console.WriteLine("beklenen hata oluştu");
            }
            Console.ReadLine();
        }
Beispiel #3
0
            unsafe public void Run(object state)
            {
                var   address = new byte [1024];
                int   size    = 1024;
                Errno errno;

                fixed(byte *ptr = address)
                do
                {
                    Accepted = accept(Socket, ptr,
                                      ref size);
                    errno = Stdlib.GetLastError();
                } while ((int)Accepted == -1 &&
                         errno == Errno.EINTR);

                if ((int)Accepted == -1)
                {
                    Except = GetException(errno);
                }

                completed = true;

                if (waithandle != null)
                {
                    waithandle.Set();
                }

                if (callback != null)
                {
                    callback(this);
                }
            }
Beispiel #4
0
 private void btnStart_Click(object sender, EventArgs e)
 {
     btnStart.Enabled = false;
     _Client          = new AsyncClient(txtIP.Text, Convert.ToInt32(txtPort.Text));
     try
     {
         _Client.Connected     += new EventHandler <AsyncClientEventArgs>(Client_OnConnected);
         _Client.DataReceived  += new EventHandler <AsyncClientEventArgs>(Client_OnDataReceived);
         _Client.DataSended    += new EventHandler <AsyncClientEventArgs>(Client_OnDataSended);
         _Client.Closing       += new EventHandler <AsyncClientEventArgs>(Client_OnClosing);
         _Client.Closed        += new EventHandler <AsyncClientEventArgs>(Client_OnClosed);
         _Client.Exception     += new EventHandler <AsyncClientEventArgs>(Client_OnException);
         _Client.ConnectTimeout = 3000;
         _Client.Connect();
     }
     catch (Exception ex)
     {
         WriteLog("無法連接至伺服器!!!");
         if (ex.GetType().Equals(typeof(System.Net.Sockets.SocketException)))
         {
             System.Net.Sockets.SocketException se = (System.Net.Sockets.SocketException)ex;
             WriteLog("{0} - {1}", se.SocketErrorCode, se.Message);
         }
         btnStart.Enabled = true;
     }
 }
Beispiel #5
0
 public void new_udp_client(string ip, int port, bool force_local_port, int local_port)
 {
     this.Text = "UDP Send to " + ip + ":" + port.ToString();
     if (force_local_port)
     {
         try
         {
             this.Text += " local port:" + local_port.ToString();
             clt        = new easy_socket.udp.Socket_Data(local_port, ip, port);//error are not catch
         }
         catch (Exception e)
         {
             this.textBox_telnet_add(e.Message + "\r\n");
             if (e is System.Net.Sockets.SocketException)
             {
                 System.Net.Sockets.SocketException se = (System.Net.Sockets.SocketException)e;
                 if (se.ErrorCode == 10048)
                 {
                     if (!this.textBox_telnet.Text.EndsWith("\r\n"))
                     {
                         this.textBox_telnet_add("\r\n");
                     }
                     this.textBox_telnet_add("Please wait few seconds before retry.\r\n");
                 }
             }
             return;
         }
     }
     else
     {
         clt = new easy_socket.udp.Socket_Data(ip, port);
     }
     clt.event_Socket_Data_Error += new easy_socket.udp.Socket_Data_Error_EventHandler(client_error);
 }
Beispiel #6
0
        private void ClientNetworkManager_OnNetworkError(System.Net.Sockets.SocketException Exception)
        {
            Debug.WriteLine("Got network error: " + Exception.ErrorCode);
            switch (Exception.ErrorCode)
            {
            case 10050:     //WSAENETDOWN
                m_LoginProgressDiag.UpdateStatus(LoginProcess.Unavailable);
                break;

            case 10051:     //WSAENETUNREACH
                m_LoginProgressDiag.UpdateStatus(LoginProcess.Unavailable);
                break;

            case 10061:     //WSAECONNREFUSED
                m_LoginProgressDiag.UpdateStatus(LoginProcess.Unavailable);
                break;

            case 10064:     //WSAEHOSTDOWN
                m_LoginProgressDiag.UpdateStatus(LoginProcess.Unavailable);
                break;

            case 10065:     //WSAEHOSTUNREACH
                m_LoginProgressDiag.UpdateStatus(LoginProcess.Unavailable);
                break;
            }
        }
Beispiel #7
0
        public static string GetExceptionInfo(Exception ex)
        {
            string msg = "";

            if (ex.GetType() == typeof(LkException))
            {
                LkException lkex = (LkException)ex;
                msg = "LINKAR EXCEPTION ERROR";
                if (lkex.ErrorCode == LkException.ERRORCODE.C0003)
                {
                    msg += "\r\nERROR CODE: " + lkex.ErrorCode +
                           "\r\nERROR MESSAGE: " + lkex.ErrorMessage +
                           "\r\nInternal ERROR CODE: " + lkex.InternalCode +
                           "\r\nInternal ERROR MESSAGE: " + lkex.InternalMessage;
                }
                else
                {
                    msg += "\r\nERROR CODE: " + lkex.ErrorCode +
                           "\r\nERROR MESSAGE: " + lkex.ErrorMessage;
                }
            }
            else if (ex.GetType() == typeof(System.Net.Sockets.SocketException))
            {
                System.Net.Sockets.SocketException soex = (System.Net.Sockets.SocketException)ex;
                msg = "SOCKET EXCEPTION ERROR\r\n" + soex.Message;
            }
            else
            {
                msg = "EXCEPTION ERROR\r\n" + ex.Message;
            }

            return(msg);
        }
Beispiel #8
0
 /// <summary>記錄錯誤事件</summary>
 /// <param name="logger">log4Net.ILog</param>
 /// <param name="sessionKey">關鍵索引鍵</param>
 /// <param name="ex">錯誤類別</param>
 /// <param name="sendMail">是否寄發信件</param>
 private static void LogException(ILog logger, string sessionKey, Exception ex, bool sendMail)
 {
     try
     {
         logger.ErrorFormat("[{0}]EX:Type:{1}", sessionKey, ex.GetType());
         if (ex.GetType().Equals(typeof(NullReferenceException)))
         {
             NullReferenceException ne = (NullReferenceException)ex;
             logger.ErrorFormat("[{0}]EX:Source:{1}", sessionKey, ne.Source);
             logger.ErrorFormat("[{0}]EX:TargetSite:{1}", sessionKey, ne.TargetSite.Name);
         }
         else if (ex.GetType().Equals(typeof(System.Net.Sockets.SocketException)))
         {
             System.Net.Sockets.SocketException se = (System.Net.Sockets.SocketException)ex;
             logger.ErrorFormat("[{0}]EX:ErrorCode:{1}", sessionKey, se.ErrorCode);
             logger.ErrorFormat("[{0}]EX:SocketErrorCode:{1}:{2}", sessionKey, se.SocketErrorCode, (int)se.SocketErrorCode);
             logger.ErrorFormat("[{0}]EX:NativeErrorCode:{1}", sessionKey, se.NativeErrorCode);
         }
         else if (ex.GetType().Equals(typeof(System.Net.HttpListenerException)))
         {
             System.Net.HttpListenerException se = (System.Net.HttpListenerException)ex;
             logger.ErrorFormat("[{0}]EX:ErrorCode:{1}", sessionKey, se.ErrorCode);
             logger.ErrorFormat("[{0}]EX:NativeErrorCode:{1}", sessionKey, se.NativeErrorCode);
         }
         else if (ex.GetType().Equals(typeof(System.Data.SqlClient.SqlException)))
         {
             System.Data.SqlClient.SqlException se = (System.Data.SqlClient.SqlException)ex;
             logger.ErrorFormat("[{0}]EX:Class:{1:X2}", sessionKey, se.Class);
             logger.ErrorFormat("[{0}]EX:Number:{1}", sessionKey, se.Number);
             logger.ErrorFormat("[{0}]EX:LineNumber:{1}", sessionKey, se.LineNumber);
             logger.ErrorFormat("[{0}]EX:ErrorCode:{1}", sessionKey, se.ErrorCode);
             logger.ErrorFormat("[{0}]EX:Errors:{1}", sessionKey, se.Errors);
         }
         logger.ErrorFormat("[{0}]EX:Message:{1}", sessionKey, ex.Message);
         logger.ErrorFormat("[{0}]EX:Source:{1}", sessionKey, ex.Source);
         logger.ErrorFormat("[{0}]EX:StackTrace:{1}", sessionKey, ex.StackTrace);
         foreach (System.Collections.DictionaryEntry de in ex.Data)
         {
             logger.ErrorFormat("[{0}]EX:Data:{1}:{2}", sessionKey, de.Key, de.Value);
         }
         if (ex.InnerException != null)
         {
             logger.ErrorFormat("[{0}]EX:InnerException", sessionKey);
             LogException(logger, sessionKey, ex.InnerException, false);
         }
         if (sendMail)
         {
             string content = GetExceptionLogString(sessionKey, ex);
             System.Threading.Tasks.Task.Factory.StartNew(() => SendMail("Exception Notice", content, false));
         }
     }
     catch (Exception nex)
     {
         logger.ErrorFormat("[LOG]EX:Type:{0}", nex.GetType());
         logger.ErrorFormat("[LOG]EX:Message:{0}", nex.Message);
         logger.ErrorFormat("[LOG]EX:Source:{0}", nex.Source);
         logger.ErrorFormat("[LOG]EX:StackTrace:{0}", nex.StackTrace);
     }
 }
 public bool isWouldBlock(System.Net.Sockets.SocketException e)
 {
     if (e.SocketErrorCode == System.Net.Sockets.SocketError.WouldBlock)
     {
         return(true);
     }
     return(false);
 }
Beispiel #10
0
        private void m_prcClient_SocketException(PRoConClient sender, System.Net.Sockets.SocketException se)
        {
            this.InvokeIfRequired(() => {
                this.ErrorMessage = this.m_clocLanguage.GetLocalized("uscServerConnection.OnServerConnectionFailure", se.Message);

                this.Connecting = this.LoggedIn = false;
            });
        }
        public async Task<IEnumerable<WeatherForecast>> Get()
        {
            Exception fault = new System.Net.Sockets.SocketException(errorCode: 10013);

            var chaosPolicy = MonkeyPolicy.InjectExceptionAsync(with 
            => with.Fault(fault)
                   .InjectionRate(0.15)
                   .Enabled(true));
            var mix = Policy.WrapAsync(GetPolicy(), chaosPolicy);
            return await mix.ExecuteAsync((ct) => GetForecasts(ct), CancellationToken.None);
        }
Beispiel #12
0
 private void commDataSender_ConnectionError(System.Net.Sockets.SocketException ex)
 {
     if (this.InvokeRequired)
     {
         this.Invoke(new Sender.ConnectionErrorHandler(commDataSender_ConnectionError), ex);
         return;
     }
     ConnectionError?.Invoke(this, ex);
     showError(ex);
     DisableEnableItems(true);
     SetStatus("<Connection Error>");
 }
Beispiel #13
0
 private void client_ErrorReceived(object sender, NetSockErrorReceivedEventArgs e)
 {
     if (e.Exception.GetType() == typeof(System.Net.Sockets.SocketException))
     {
         System.Net.Sockets.SocketException s = (System.Net.Sockets.SocketException)e.Exception;
         this.Log("Error: " + e.Function + " - " + s.SocketErrorCode.ToString() + "\r\n" + s.ToString());
     }
     else
     {
         this.Log("Error: " + e.Function + "\r\n" + e.Exception.ToString());
     }
 }
        public void CanGenerateDataListFromSocketException()
        {
            // Arrange
            var socketException = new System.Net.Sockets.SocketException(100);

            // Act
            var result = socketException.ToDataList();

            // Assert
            Assert.That(result.Count, Is.EqualTo(2));
            Assert.That(result.Any(r => r.Key == "SocketException.SocketErrorCode" && r.Value == "100"));
            Assert.That(result.Any(r => r.Key == "SocketException.ErrorCode" && r.Value == "100"));
        }
Beispiel #15
0
        public async void IsRunningAsyncWhenResultCodeFails()
        {
            var mockLogger = new Mock <ILogger <TrexWebClient> >();
            var settings   = new TrexWebClient.Settings()
            {
                StatusUrl = "http://localhost"
            };
            var socketException = new System.Net.Sockets.SocketException(0);
            var ex         = new HttpRequestException("test", socketException);
            var httpClient = HttpClientMock.GetResponseThatThrowsException(ex);
            var webClient  = new TrexWebClient(mockLogger.Object, Options.Create(settings), httpClient);

            (await webClient.IsRunningAsync()).Should().Be(false, "We should swallow the conenction refused exception");
        }
Beispiel #16
0
        static public void LogSocketException(Exception ex)
        {
            System.Net.Sockets.SocketException socketEx = ex as System.Net.Sockets.SocketException;

            if (socketEx == null)
            {
                //Not a socket exception
                Debug.WriteLine("[" + GetFormattedTime(DateTime.Now) + "] " + string.Format("Exception: {0} occured at {1}\n", ex.Message, ex.StackTrace), "SOCKETS");
            }
            else
            {
                Debug.WriteLine("[" + GetFormattedTime(DateTime.Now) + "] " + string.Format("Socket Exception: Code {0}, Message {1} occured at {2}\n", socketEx.ErrorCode, socketEx.Message, socketEx.StackTrace), "SOCKETS");
            }
        }
Beispiel #17
0
        public void new_tcp_client(string ip, int port, bool force_local_port, int local_port, bool telnet_protocol)
        {
            myip      = ip;
            myport    = port;
            this.Text = "Connected to " + myip + ":" + myport.ToString();
            if (force_local_port)
            {
                try
                {
                    this.Text += " local port:" + local_port.ToString();
                    clt        = new easy_socket.tcp.Socket_Data(1024, local_port);//error are not catch
                }
                catch (Exception e)
                {
                    this.textBox_telnet_add(e.Message + "\r\n");
                    if (e is System.Net.Sockets.SocketException)
                    {
                        System.Net.Sockets.SocketException se = (System.Net.Sockets.SocketException)e;
                        if (se.ErrorCode == 10048)
                        {
                            // return to a new line (split != send and send/receive)
                            if (!this.textBox_telnet.Text.EndsWith("\r\n"))
                            {
                                this.textBox_telnet_add("\r\n");
                            }
                            this.textBox_telnet_add("Please wait few seconds before retry.\r\n");
                        }
                    }
                    return;
                }
            }
            else
            {
                clt = new easy_socket.tcp.Socket_Data();
            }
            add_events();
            clt.connect(ip, port);

            // for telnet protocol
            #region telnet protocol
            if (telnet_protocol)
            {
                this.set_telnet_protocol(true);
            }
            this.checkBox_telnet.Checked            = telnet_protocol;
            this.checkBox_beep_on_bell.Enabled      = telnet_protocol;
            this.checkBox_send_function_key.Enabled = telnet_protocol;
            this.checkBox_no_buffer.Enabled         = telnet_protocol;
            #endregion
        }
Beispiel #18
0
 void onError(object sender, ErrorEventArgs e)
 {
     System.Net.Sockets.SocketException ex = e.Exception as System.Net.Sockets.SocketException;
     if (null != NetMgr)
     {
         ByteBuffer buffer = new ByteBuffer();
         buffer.WriteInt(ex.ErrorCode);
         buffer.WriteString(ex.Message);
         NetMgr.AddEvent(Protocal.Exception, new ByteBuffer(buffer.ToBytes()));
     }
     else
     {
         LogUtil.LogWarning("Socket Error {0}:{1}", ex.ErrorCode, ex.Message);
     }
 }
Beispiel #19
0
 /// <summary>
 /// 过滤Socket不可用异常
 /// </summary>
 /// <param name="error">异常</param>
 /// <returns>过滤后的异常,匹配返回null</returns>
 private static Exception filterSocketDisposed(Exception error)
 {
     if (error != null)
     {
         ObjectDisposedException disposedError = error.InnerException as ObjectDisposedException;
         if (disposedError == null)
         {
             System.Net.Sockets.SocketException socketException = error as System.Net.Sockets.SocketException;
             if (socketException != null && socketException.ErrorCode == 10053 && socketException.ErrorCode == 10054)
             {
                 return(null);
             }
         }
     }
     return(error);
 }
Beispiel #20
0
        /// <summary>
        /// Retorna el mensaje para mostrar al usuario
        /// </summary>
        /// <param name="ex">Excepcion</param>
        /// <returns>Mensaje al usuario</returns>
        public static string GetFriendlyMessage(Exception ex)
        {
            System.Net.Sockets.SocketException SocketException = ex as System.Net.Sockets.SocketException;
            if (SocketException != null)
            {
                return(Stoca.Common.CommonTexts.MSG_EXCEPTION_NETWORK);
            }

            //recupero texto extendido de la excepcion
            string sText = GetExtendedInfo(ex);

            if (sText != null && sText.Length > 0)
            {
                return(sText);
            }

            //extrae el mensaje de la base de datos
            return(GetCustomDatabaseMessage(ex));
        }
        public async Task <IEnumerable <WeatherForecast> > Get()
        {
            Exception fault         = new System.Net.Sockets.SocketException(errorCode: 10013);
            var       latencyMonkey = MonkeyPolicy.InjectLatencyAsync(with =>
                                                                      with.Latency(TimeSpan.FromSeconds(1))
                                                                      .InjectionRate(0.1)
                                                                      .Enabled(true));

            var errorMonkey = MonkeyPolicy.InjectExceptionAsync(with =>
                                                                with.Fault(fault)
                                                                .InjectionRate(0.1)
                                                                .Enabled(true));

            var monkeyPolicy = Policy.WrapAsync(latencyMonkey, errorMonkey);

            var mix = Policy.WrapAsync(GetPolicy(), monkeyPolicy);

            return(await mix.ExecuteAsync((ct) => GetForecasts(ct), CancellationToken.None));
        }
Beispiel #22
0
        private string BuildExceptionMessages(Exception ex)
        {
            string message = "";

            if (ex is System.Net.Sockets.SocketException)
            {
                System.Net.Sockets.SocketException socketEx = (System.Net.Sockets.SocketException)ex;
                message = $"{socketEx.Message} + Native Error Code: {socketEx.NativeErrorCode} + Socket Error Code: {socketEx.SocketErrorCode}";
            }
            else
            {
                message = ex.Message;
            }

            if (ex.InnerException != null)
            {
                message += $" - {BuildExceptionMessages( ex.InnerException )}";
            }

            return(message);
        }
Beispiel #23
0
        /// <summary>
        /// Open Socket listener on specific port
        /// </summary>
        protected void openSocketListener(int port)
        {
            try {
                                #if DEBUG
                log("[2] Opening Listener on port " + port + "...");
                                #endif
                if (httpServer == null)
                {
                    httpServer = new HttpServer(new Server(port));
                }
                socketOpened = true;

                                #if DEBUG
                log("[2] Listener OPENED on port: " + httpServer.Server.Port);
                                #endif

                // Adding Resource Handler.
                IPhoneResourceHandler resourceHandler = new IPhoneResourceHandler(ApplicationSource.FILE);
                //resourceHandler.Substitute = false;
                httpServer.Handlers.Add(resourceHandler);
                httpServer.Handlers.Add(new RemoteResourceHandler(IPhoneServiceLocator.GetInstance()));
            } catch (Exception ex) {
                                #if DEBUG
                log("[2] Cannot open internal server socket: " + ex.Message);
                                #endif
                if (ex.GetType() == typeof(System.Net.Sockets.SocketException))
                {
                    System.Net.Sockets.SocketException socketException = ex as System.Net.Sockets.SocketException;
                    //log ("[2] Socket exception: " + socketException.SocketErrorCode);
                    if (socketException.SocketErrorCode == System.Net.Sockets.SocketError.AddressAlreadyInUse)
                    {
                                                #if DEBUG
                        log("[2] Address already in use; trying with next port...");
                                                #endif
                        this.openSocketListener(port + 1);
                    }
                }
            }
        }
        protected void thread_watching_reply()
        {
            int nBytes;

            byte[] ReceiveBuffer = new byte[this.us_receive_buffer_size];

            ipv4_header iph = new ipv4_header();

            byte[] data_buffer;
            byte   b_ret;

            try
            {
                while (true)
                {
                    nBytes = this.srv_socket.Receive(ReceiveBuffer, 0, this.us_receive_buffer_size, System.Net.Sockets.SocketFlags.None);
                    if (nBytes > 0)
                    {
                        // allow to have an array matching data rcv size (avoid to send the size as parameter for each next methodes)
                        data_buffer = new byte[nBytes];
                        System.Array.Copy(ReceiveBuffer, 0, data_buffer, 0, nBytes);
                        // end allow to have an array matching data rcv size (avoid to send the size as parameter for each next methodes)

                        // decode ipheader
                        b_ret = iph.decode(data_buffer, nBytes);
                        // if decoding was successful
                        if (b_ret == ipv4_header.error_success)
                        {
                            if (this.check_wanted_packet(ref iph))
                            {
                                // throw the data arrival event
                                if (this.event_Socket_Data_Arrival != null)
                                {
#if (!DEBUG)
                                    try // avoid to close server if error in the event handler code
#endif
                                    {
                                        this.event_Socket_Data_Arrival(iph, new EventArgs_FullPacket(data_buffer));
                                    }
#if (!DEBUG)
                                    catch {}
#endif
                                }
                            }
                        }
                        else
                        {
                            if ((b_ret == ipv4_header.error_datagram_internet_header_length_too_small) ||
                                (b_ret == ipv4_header.error_datagram_total_length_too_small))
                            {
                                // send
                                if (this.event_Socket_RcvPacket_Error != null)
                                {
                                    this.event_Socket_RcvPacket_Error(this, new EventArgs_Exception_Packet(new Exception("Error in Ipv4 header"), data_buffer));
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                // close socket
                this.close_socket();


                if (e is System.Net.Sockets.SocketException)
                {
                    System.Net.Sockets.SocketException se = (System.Net.Sockets.SocketException)e;
                    if (se.ErrorCode == 10004) // close methode as been called
                    {
                        return;
                    }
                }
                if (e is System.ObjectDisposedException)//throw by Receive (socket has been closed)
                {
                    return;
                }
                if (e is System.NullReferenceException)//throw by Receive if we put socket=null after socket.close
                {
                    return;
                }
                // send event_Socket_Server_Error

                //if (this.event_Socket_Error!=null)
                //    this.event_Socket_Error(iph,new EventArgs_Exception(e));

                this.send_socket_error_event(e);
            }
        }
Beispiel #25
0
 public HiddenSocketExceptionEventArgs(RtpSession session, System.Net.Sockets.SocketException ex)
 {
     Session   = session;
     Exception = ex;
 }
Beispiel #26
0
 private void m_prcClient_SocketException(PRoConClient sender, System.Net.Sockets.SocketException se)
 {
     this.ProcessEvent(EventType.Connection, CapturableEvents.LostConnection);
 }
Beispiel #27
0
 void _client_OnError(TCPClient client, System.Net.Sockets.SocketException exc)
 {
     this._err_reporter.OnException(String.Format("TCPClient {0} exception", client), exc);
 }
Beispiel #28
0
        private static bool HandleWebException(WebException webException, out WebResponse response)
        {
            // return whether or not it has been handled
            // find out if the exception was caused by a socket exception

            Exception innerException = webException.InnerException;

            System.Net.Sockets.SocketException sockException = null;

            while (innerException != null)
            {
                if (innerException is System.Net.Sockets.SocketException)
                {
                    sockException = innerException as System.Net.Sockets.SocketException;
                    break;
                }
                else
                {
                    innerException = innerException.InnerException;
                }
            }

            if (sockException != null)
            {
                // Ignore exceptions caused by Fiddler.
                if (sockException.SocketErrorCode == System.Net.Sockets.SocketError.ConnectionReset)
                {
                    AstoriaTestLog.WriteLine("Connection was reset. Retrying...");
                    response = null;
                    return(true);
                }
                AstoriaTestLog.WriteLine("A socket exception occurred, waiting 30 seconds before retrying");
                AstoriaTestLog.WriteLine("Message: " + sockException.Message);
                AstoriaTestLog.WriteLine("Error Code: " + sockException.SocketErrorCode);
                AstoriaTestLog.WriteLineIgnore("Time before sleep: " + DateTime.Now);
                Threading.Thread.Sleep(new TimeSpan(0, 0, 30));
                AstoriaTestLog.WriteLineIgnore("Time after sleep: " + DateTime.Now);
                response = null;
                return(true);
            }

            if (webException.Status == WebExceptionStatus.Timeout)
            {
                AstoriaTestLog.WriteLine("The request timeout out, waiting 30 seconds before retrying");
                AstoriaTestLog.WriteLine("Message: " + webException.Message);
                AstoriaTestLog.WriteLineIgnore("Time before sleep: " + DateTime.Now);
                Threading.Thread.Sleep(new TimeSpan(0, 0, 30));
                AstoriaTestLog.WriteLineIgnore("Time after sleep: " + DateTime.Now);
                response = null;
                return(true);
            }

            if (webException.Response != null)
            {
                response = webException.Response;
                return(true);
            }

            response = null;
            return(false);
        }
Beispiel #29
0
 internal void create(IAsyncResult ar, System.Net.Sockets.SocketException SockEx, string ClosArg)
 {
     m_ar = ar;
     m_SockEx = SockEx;
     m_CloseArgument = ClosArg;
 }
Beispiel #30
0
			unsafe public void Run (object state)
			{
				var address = new byte [1024];
				int size = 1024;
				Errno errno;
				fixed (byte* ptr = address)
					do {
						Accepted = accept (Socket, ptr,
							ref size);
						errno = Stdlib.GetLastError ();
					} while ((int) Accepted == -1 &&
						errno == Errno.EINTR);
				
				if ((int) Accepted == -1)
					Except = GetException (errno);
				
				completed = true;
				
				if (waithandle != null)
					waithandle.Set ();
				
				if (callback != null)
					callback (this);
			}
Beispiel #31
0
 public HiddenSocketExceptionEventArgs( RtpSession session, System.Net.Sockets.SocketException ex )
 {
     Session = session;
     Exception = ex;
 }
Beispiel #32
0
        public string InterpreteException(Exception e, out WellKownCpanelProblems problem)
        {
            problem = WellKownCpanelProblems.Unknown;
            if (e is CPanelException)
            {
                problem = (e as CPanelException).Status;
                return(e.Message);
            }
            else if (e is WebException)
            {
                WebException we = e as WebException;
                switch (we.Status)
                {
                case WebExceptionStatus.ProtocolError:
                    HttpWebResponse wr = we.Response as HttpWebResponse;
                    if (wr != null)
                    {
                        if (wr.StatusCode == HttpStatusCode.Forbidden)
                        {
                            problem = WellKownCpanelProblems.LoginError;
                            return(CPanelException.GetStatusDescription(problem));
                        }
                        return(string.Format(Polish.strBladProtokoluHTTP, wr.StatusCode));
                    }
                    return(Polish.strInnyBladProtokoluHTTP);

                case WebExceptionStatus.NameResolutionFailure:
                    string hostName = "";
                    try
                    {
                        Uri u = new Uri(this.uRL);
                        hostName = u.Host;
                    }
                    catch { }
                    return(string.Format(Polish.strNieMoznaZnalezcSerwera0 + " " + Polish.strSprawdzNazweSerweraOrazPolaczenieZInternetem, hostName));

                case WebExceptionStatus.ConnectFailure:
                    return(string.Format(Polish.strNieMoznaPodlaczycSieDoCPanela0 + " " + Polish.strSprawdzPoprawnoscAdresuOrazPolaczenieZInternetem, uRL));

                case WebExceptionStatus.Timeout:
                    return(Polish.strSerwerNieOdpowiedzialWOczekiwanymCzasie + " " + Polish.strMozeToBycWinaSerweraLubProblemZPolaczeniemDoInternetu);

                default:
                    return(string.Format(Polish.strBladSieciowy0, we.Status));
                }
            }
            if (e is System.Net.Sockets.SocketException)
            {
                System.Net.Sockets.SocketException se = e as System.Net.Sockets.SocketException;
                switch (se.SocketErrorCode)
                {
                case System.Net.Sockets.SocketError.HostNotFound:
                    return(Polish.strNieMoznaOdnalezcSerwera);

                case System.Net.Sockets.SocketError.ConnectionReset:
                    return(Polish.strPolaczenieZostaloUtracone);

                default:
                    return(string.Format(Polish.strInnyBladPolaczenia0, se.SocketErrorCode));
                }
                ;
            }
            return(string.Format(Polish.strInnyBlad0, e.Message));
        }
Beispiel #33
0
 public CloseEventArgs()
 {
     m_ar = null;
     m_SockEx = null;
     m_CloseArgument = "Not set yet";
 }
Beispiel #34
0
 /// <summary>
 /// Logs a socket exception
 /// </summary>
 /// <param name="ex">
 /// The SocketException to log
 /// </param>
 /// <param name="es">
 /// The severity to log
 /// </param>
 public void LogSocketException(SocketException ex, EventSeverity es)
 {
     LogEvent(es, ex.Message);
     LogEvent(es, "Socket Error Code: " + ex.SocketErrorCode);
     LogEvent(es, "Stack Trace:" + ex.StackTrace);
 }
Beispiel #35
0
 public ConnectionFailedEventArgs(System.Net.Sockets.SocketException socketException)
 {
     this.reason          = ConnectionFailReasons.socketException;
     this.socketException = socketException;
 }