try catch finally return

  public override bool Start(IServerConfig config)
        {
            bool flag = true;
            listenSocket = new Socket(ListenerInfo.IpEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            try
            {
                listenSocket.Bind(ListenerInfo.IpEndPoint);
                listenSocket.Listen(ListenerInfo.BackLog);

                SocketAsyncEventArgs tempSocketAsyncEventArgs = new SocketAsyncEventArgs();
                socketAsyncEventArgs = tempSocketAsyncEventArgs;
                tempSocketAsyncEventArgs.Completed += TempSocketAsyncEventArgs_Completed;

                bool willRaiseEvent = listenSocket.AcceptAsync(tempSocketAsyncEventArgs);
                if (willRaiseEvent == false)
                {
                    ProcessAccept(tempSocketAsyncEventArgs);
                }
            }
            catch (Exception ex)
            {
                OnError(new ErrorEventArgs {Exception = ex});
                flag = false;
            }
            return flag;
        }

 

posted @ 2014-10-28 15:24  ChuckLu  阅读(178)  评论(0编辑  收藏  举报