Esempio n. 1
0
 public UdpEndpointI(ProtocolInstance instance, Ice.InputStream s) :
     base(instance, s)
 {
     if (s.GetEncoding().Equals(Ice.Util.Encoding_1_0))
     {
         s.ReadByte();
         s.ReadByte();
         s.ReadByte();
         s.ReadByte();
     }
     // Not transmitted.
     //_connect = s.readBool();
     _connect  = false;
     _compress = s.ReadBool();
 }
Esempio n. 2
0
        private static void PrintRequestHeader(System.IO.StringWriter s, Ice.InputStream str)
        {
            PrintIdentityFacetOperation(s, str);

            try
            {
                byte mode = str.ReadByte();
                s.Write("\noperation mode = " + (int)mode + ' ');
                switch (mode)
                {
                case 0:
                {
                    s.Write("(non-idempotent)");
                    break;
                }

                case 1:
                {
                    s.Write("(idempotent/nonmutating)");
                    break;
                }

                case 2:
                {
                    s.Write("(idempotent)");
                    break;
                }

                default:
                {
                    s.Write("(unknown)");
                    break;
                }
                }

                int sz = str.ReadSize();
                s.Write("\ncontext = ");
                while (sz-- > 0)
                {
                    string key = str.ReadString();
                    string val = str.ReadString();
                    s.Write(key + '/' + val);
                    if (sz > 0)
                    {
                        s.Write(", ");
                    }
                }

                Ice.EncodingVersion v = str.SkipEncapsulation();
                if (!v.Equals(Ice.Util.Encoding_1_0))
                {
                    s.Write("\nencoding = ");
                    s.Write(Ice.Util.EncodingVersionToString(v));
                }
            }
            catch (System.IO.IOException)
            {
                Debug.Assert(false);
            }
        }
Esempio n. 3
0
        public void invoke(ServantManager servantManager, Ice.InputStream stream)
        {
            _is = stream;

            int start = _is.pos();
            //
            // Read the current.
            //
            var id = new Ice.Identity();

            id.ice_readMembers(_is);

            //
            // For compatibility with the old FacetPath.
            //
            string[] facetPath = _is.ReadStringSeq();
            string   facet;

            if (facetPath.Length > 0)
            {
                if (facetPath.Length > 1)
                {
                    throw new Ice.MarshalException();
                }
                facet = facetPath[0];
            }
            else
            {
                facet = "";
            }

            string operation = _is.ReadString();
            byte   mode      = _is.ReadByte();
            Dictionary <string, string> context = new Dictionary <string, string>();
            int sz = _is.ReadSize();

            while (sz-- > 0)
            {
                string first  = _is.ReadString();
                string second = _is.ReadString();
                context[first] = second;
            }
            _current = new Ice.Current(_adapter, id, facet, operation, (Ice.OperationMode)mode, context, _requestId, _connection);
            Ice.Instrumentation.CommunicatorObserver?obsv = _communicator.Observer;
            if (obsv != null)
            {
                // Read the encapsulation size.
                int size = _is.ReadInt();
                _is.pos(_is.pos() - 4);

                _observer = obsv.getDispatchObserver(_current, _is.pos() - start + size);
                if (_observer != null)
                {
                    _observer.attach();
                }
            }

            //
            // Don't put the code above into the try block below. Exceptions
            // in the code above are considered fatal, and must propagate to
            // the caller of this operation.
            //

            if (servantManager != null)
            {
                _servant = servantManager.findServant(_current.Id, _current.Facet);
                if (_servant == null)
                {
                    _locator = servantManager.findServantLocator(_current.Id.category);
                    if (_locator == null && _current.Id.category.Length > 0)
                    {
                        _locator = servantManager.findServantLocator("");
                    }

                    if (_locator != null)
                    {
                        Debug.Assert(_locator != null);
                        try
                        {
                            _servant = _locator.locate(_current, out _cookie);
                        }
                        catch (Exception ex)
                        {
                            skipReadParams(); // Required for batch requests.
                            handleException(ex, false);
                            return;
                        }
                    }
                }
            }

            if (_servant == null)
            {
                try
                {
                    if (servantManager != null && servantManager.hasServant(_current.Id))
                    {
                        throw new Ice.FacetNotExistException(_current.Id, _current.Facet, _current.Operation);
                    }
                    else
                    {
                        throw new Ice.ObjectNotExistException(_current.Id, _current.Facet, _current.Operation);
                    }
                }
                catch (Exception ex)
                {
                    skipReadParams(); // Required for batch requests
                    handleException(ex, false);
                    return;
                }
            }

            try
            {
                Task <Ice.OutputStream>?task = _servant(this, _current);
                if (task == null)
                {
                    completed(null, false);
                }
                else
                {
                    if (task.IsCompleted)
                    {
                        _os = task.GetAwaiter().GetResult(); // Get the response
                        completed(null, false);
                    }
                    else
                    {
                        task.ContinueWith((Task <Ice.OutputStream> t) =>
                        {
                            try
                            {
                                _os = t.GetAwaiter().GetResult();
                                completed(null, true); // true = asynchronous
                            }
                            catch (Exception ex)
                            {
                                completed(ex, true); // true = asynchronous
                            }
                        },
                                          CancellationToken.None,
                                          TaskContinuationOptions.ExecuteSynchronously,
                                          scheduler: TaskScheduler.Current);
                    }
                }
            }
            catch (Exception ex)
            {
                completed(ex, false);
            }
        }
Esempio n. 4
0
        private static byte PrintHeader(System.IO.StringWriter s, Ice.InputStream str)
        {
            try
            {
                str.ReadByte(); // Don't bother printing the magic number
                str.ReadByte();
                str.ReadByte();
                str.ReadByte();

                /* byte pMajor = */
                str.ReadByte();
                /* byte pMinor = */
                str.ReadByte();
                //s.Write("\nprotocol version = " + (int)pMajor + "." + (int)pMinor);

                /* byte eMajor = */
                str.ReadByte();
                /* byte eMinor = */
                str.ReadByte();
                //s.Write("\nencoding version = " + (int)eMajor + "." + (int)eMinor);

                byte type = str.ReadByte();
                s.Write("\nmessage type = " + (int)type + " (" + GetMessageTypeAsString(type) + ')');

                byte compress = str.ReadByte();
                s.Write("\ncompression status = " + (int)compress + ' ');
                switch (compress)
                {
                case 0:
                {
                    s.Write("(not compressed; do not compress response, if any)");
                    break;
                }

                case 1:
                {
                    s.Write("(not compressed; compress response, if any)");
                    break;
                }

                case 2:
                {
                    s.Write("(compressed; compress response, if any)");
                    break;
                }

                default:
                {
                    s.Write("(unknown)");
                    break;
                }
                }

                int size = str.ReadInt();
                s.Write("\nmessage size = " + size);
                return(type);
            }
            catch (System.IO.IOException)
            {
                Debug.Assert(false);
                return(0);
            }
        }
Esempio n. 5
0
        private static void PrintReply(System.IO.StringWriter s, Ice.InputStream str)
        {
            int requestId = str.ReadInt();

            s.Write("\nrequest id = " + requestId);

            byte replyStatus = str.ReadByte();

            s.Write("\nreply status = " + (int)replyStatus + ' ');

            switch (replyStatus)
            {
            case ReplyStatus.replyOK:
            {
                s.Write("(ok)");
                break;
            }

            case ReplyStatus.replyUserException:
            {
                s.Write("(user exception)");
                break;
            }

            case ReplyStatus.replyObjectNotExist:
            case ReplyStatus.replyFacetNotExist:
            case ReplyStatus.replyOperationNotExist:
            {
                switch (replyStatus)
                {
                case ReplyStatus.replyObjectNotExist:
                {
                    s.Write("(object not exist)");
                    break;
                }

                case ReplyStatus.replyFacetNotExist:
                {
                    s.Write("(facet not exist)");
                    break;
                }

                case ReplyStatus.replyOperationNotExist:
                {
                    s.Write("(operation not exist)");
                    break;
                }

                default:
                {
                    Debug.Assert(false);
                    break;
                }
                }

                PrintIdentityFacetOperation(s, str);
                break;
            }

            case ReplyStatus.replyUnknownException:
            case ReplyStatus.replyUnknownLocalException:
            case ReplyStatus.replyUnknownUserException:
            {
                switch (replyStatus)
                {
                case ReplyStatus.replyUnknownException:
                {
                    s.Write("(unknown exception)");
                    break;
                }

                case ReplyStatus.replyUnknownLocalException:
                {
                    s.Write("(unknown local exception)");
                    break;
                }

                case ReplyStatus.replyUnknownUserException:
                {
                    s.Write("(unknown user exception)");
                    break;
                }

                default:
                {
                    Debug.Assert(false);
                    break;
                }
                }

                string unknown = str.ReadString();
                s.Write("\nunknown = " + unknown);
                break;
            }

            default:
            {
                s.Write("(unknown)");
                break;
            }
            }

            if (replyStatus == ReplyStatus.replyOK || replyStatus == ReplyStatus.replyUserException)
            {
                Ice.EncodingVersion v = str.SkipEncapsulation();
                if (!v.Equals(Ice.Util.Encoding_1_0))
                {
                    s.Write("\nencoding = ");
                    s.Write(Ice.Util.EncodingVersionToString(v));
                }
            }
        }
Esempio n. 6
0
File: Incoming.cs Progetto: yzun/ice
        public void Invoke(Ice.InputStream stream)
        {
            _is = stream;

            int start = _is.Pos;
            //
            // Read the current.
            //
            var id = new Ice.Identity(_is);

            //
            // For compatibility with the old FacetPath.
            //
            string[] facetPath = _is.ReadStringArray();
            string   facet;

            if (facetPath.Length > 0)
            {
                if (facetPath.Length > 1)
                {
                    throw new Ice.MarshalException();
                }
                facet = facetPath[0];
            }
            else
            {
                facet = "";
            }

            string operation = _is.ReadString();
            byte   mode      = _is.ReadByte();
            var    context   = new Dictionary <string, string>();
            int    sz        = _is.ReadSize();

            while (sz-- > 0)
            {
                string first  = _is.ReadString();
                string second = _is.ReadString();
                context[first] = second;
            }
            _current = new Ice.Current(_adapter, id, facet, operation, (Ice.OperationMode)mode, context, _requestId, _connection);
            Ice.Instrumentation.ICommunicatorObserver?obsv = _communicator.Observer;
            if (obsv != null)
            {
                // Read the encapsulation size.
                int size = _is.ReadInt();
                _is.Pos -= 4;

                _observer = obsv.GetDispatchObserver(_current, _is.Pos - start + size);
                if (_observer != null)
                {
                    _observer.Attach();
                }
            }

            //
            // Don't put the code above into the try block below. Exceptions
            // in the code above are considered fatal, and must propagate to
            // the caller of this operation.
            //
            _servant = _adapter.Find(_current.Id, _current.Facet);

            if (_servant == null)
            {
                try
                {
                    throw new Ice.ObjectNotExistException(_current.Id, _current.Facet, _current.Operation);
                }
                catch (Exception ex)
                {
                    SkipReadParams(); // Required for batch requests
                    HandleException(ex, false);
                    return;
                }
            }

            try
            {
                Task <Ice.OutputStream?>?task = _servant.Dispatch(this, _current);
                if (task == null)
                {
                    Completed(null, false);
                }
                else
                {
                    if (task.IsCompleted)
                    {
                        _os = task.GetAwaiter().GetResult(); // Get the response
                        Completed(null, false);
                    }
                    else
                    {
                        task.ContinueWith((Task <Ice.OutputStream> t) =>
                        {
                            try
                            {
                                _os = t.GetAwaiter().GetResult();
                                Completed(null, true); // true = asynchronous
                            }
                            catch (Exception ex)
                            {
                                Completed(ex, true); // true = asynchronous
                            }
                        },
                                          CancellationToken.None,
                                          TaskContinuationOptions.ExecuteSynchronously,
                                          scheduler: TaskScheduler.Current);
                    }
                }
            }
            catch (Exception ex)
            {
                Completed(ex, false);
            }
        }