Пример #1
0
        protected internal virtual bool TryGetAllInfo(int timeout, out IEnumerable <HandleInfo> infos, ref Exception exception)
        {
            IList <HandleInfo> out_infos     = emptryhandleinfos;
            Exception          out_exception = null;

            try
            {
                if (timeout <= 0 && timeout != -1)
                {
                    out_exception = EventWaitHandle.NewTimeoutException();
                    return(false);
                }
                using (ManualResetEvent events = new ManualResetEvent(false))
                {
                    bool success = false;
                    bool abort   = false;
                    if (!MalockMessage.TryInvokeAsync(this, MalockNodeMessage.New(null, this.Identity,
                                                                                  MalockNodeMessage.CLIENT_COMMAND_GETALLINFO, timeout), timeout,
                                                      (errno, message, stream) =>
                    {
                        if (errno == MalockMessage.Mappable.ERROR_NOERROR)
                        {
                            if (message.Command == MalockNodeMessage.CLIENT_COMMAND_GETALLINFO)
                            {
                                out_infos = new List <HandleInfo>();
                                success = HandleInfo.Fill(out_infos, stream);
                            }
                        }
                        else if (errno == MalockMessage.Mappable.ERROR_ABORTED)
                        {
                            abort = true;
                        }
                        else if (errno == MalockMessage.Mappable.ERROR_TIMEOUT)
                        {
                            out_exception = EventWaitHandle.NewTimeoutException();
                        }
                        events.Set();
                    }, ref out_exception) || out_exception != null)
                    {
                        return(false);
                    }
                    events.WaitOne();
                    if (abort)
                    {
                        out_exception = EventWaitHandle.NewAbortedException();
                        return(false);
                    }
                    return(success);
                }
            }
            finally
            {
                infos     = out_infos;
                exception = out_exception;
            }
        }
Пример #2
0
 protected internal virtual void GetAllInfoAsync(int timeout, Action <int, IEnumerable <HandleInfo> > state)
 {
     if (state == null)
     {
         throw new ArgumentNullException("callback");
     }
     if (timeout <= 0 && timeout != -1)
     {
         state(kERROR_TIMEOUT, emptryhandleinfos);
     }
     else
     {
         Exception exception = null;
         if (!MalockMessage.TryInvokeAsync(this,
                                           MalockNodeMessage.New(null, this.Identity, MalockNodeMessage.CLIENT_COMMAND_GETALLINFO, timeout), timeout,
                                           (errno, message, stream) =>
         {
             if (errno == MalockMessage.Mappable.ERROR_NOERROR)
             {
                 bool error = true;
                 if (message.Command == MalockNodeMessage.CLIENT_COMMAND_GETALLINFO)
                 {
                     IList <HandleInfo> results = new List <HandleInfo>();
                     if (HandleInfo.Fill(results, stream))
                     {
                         error = false;
                         state(kERROR_NOERROR, results);
                     }
                 }
                 if (error)
                 {
                     state(kERROR_ERRORNO, emptryhandleinfos);
                 }
             }
             else if (errno == MalockMessage.Mappable.ERROR_ABORTED)
             {
                 state(kERROR_ABORTED, emptryhandleinfos);
             }
             else if (errno == MalockMessage.Mappable.ERROR_TIMEOUT)
             {
                 state(kERROR_TIMEOUT, emptryhandleinfos);
             }
         }, ref exception))
         {
             state(kERROR_ABORTED, emptryhandleinfos);
         }
     }
 }