Ejemplo n.º 1
0
        private void ProcessRequestError(uint requestId, ServiceProtocolResponseCode code, int sourceState)
        {
            if (Interlocked.CompareExchange(ref requestStates[requestId], RequestStateProcessError, sourceState) != sourceState)
            {
                return;
            }

GetContinuation:

            var continuation = requestContinuations[requestId];

            if (continuation == null)
            {
                Thread.SpinWait(1);

                goto GetContinuation;
            }

            Thread.MemoryBarrier();

            ServiceProtocolResponse.localThreadCodeForErrorResponses = code;

            try
            {
                continuation();
            }
            catch (Exception e)
            {
                logger.Fatal($"Service protocol client {requestId}: Could not process request continuation! Details: {e}");
            }

            requestContinuations[requestId] = null;

            Thread.MemoryBarrier();

            Interlocked.Exchange(ref requestStates[requestId], RequestStateInactive);
        }
Ejemplo n.º 2
0
        internal static void ReadHeader(byte[] buffer, int offset, out uint id, out byte kind, out ServiceProtocolResponseCode code, out ushort size)
        {
            id = (uint)(buffer[offset] | (buffer[offset + 1] << 8) | (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24));

            kind = buffer[offset + 4];

            code = (ServiceProtocolResponseCode)buffer[offset + 5];

            size = (ushort)(buffer[offset + 6] | (buffer[offset + 7] << 8));
        }
Ejemplo n.º 3
0
        internal static void WriteHeader(byte[] buffer, int offset, uint id, byte kind, ServiceProtocolResponseCode code, ushort size)
        {
            buffer[offset]     = (byte)id;
            buffer[offset + 1] = (byte)(id >> 8);
            buffer[offset + 2] = (byte)(id >> 16);
            buffer[offset + 3] = (byte)(id >> 24);

            buffer[offset + 4] = kind;

            buffer[offset + 5] = (byte)code;

            buffer[offset + 6] = (byte)size;
            buffer[offset + 7] = (byte)(size >> 8);
        }