예제 #1
0
        internal unsafe void SendMissReport(IFontCacheElement e)
        {
            //If we are not connected to the server, there's no one to send the miss report to, so don't.
            if (_conn == null)
            {
                return;
            }

            byte[] request = new byte[Math.Min(MaxMissReportSize, _conn.GetMaxRequestBytes())];

            //If the connection cannot support a long enough request to hold the message type and element type,
            //we can't send the miss report.
            if (request.Length < 2 * sizeof(int))
                return;

            fixed(byte *ptr = &request[0])
            {
                //Store the message type
                ((int *)ptr)[0] = FontCacheConstants.SendMissReportMessage;

                //Store the element type
                ((int *)ptr)[1] = e.Type;

                //Store the key information
                CheckedPointer key = new CheckedPointer(ptr, request.Length);

                key += 2 * sizeof(int);
                try
                {
                    int realSize = 0;
                    e.StoreKey(key, out realSize);
                    Debug.Assert(realSize >= 0, "realSize is negative");
                    // realSize will be zero for non-shareable elements like in-memory fonts
                    if (realSize != 0)
                    {
                        realSize += 2 * sizeof(int);//adjust for message header and miss report header
                        Debug.Assert(realSize <= request.Length, "realSize too large");

                        //Send the request as a datagram (ignore error code)
                        int errorCode = 0;
                        _protocol.TrySendRequest(_conn, request, 0, realSize, null, 0, 0, 0, out errorCode);
                    }
                }
                catch (ArgumentOutOfRangeException)
                {
                    // the key didn't fit into the buffer, just don't send the miss report
                    return;
                }
            }
        }