コード例 #1
0
ファイル: ModMonoWorkerRequest.cs プロジェクト: nuxleus/xsp
        public override void SendResponseFromFile(string filename, long offset, long length)
        {
            if (offset == 0)
            {
                FileInfo info = new FileInfo(filename);
                if (info.Length == length)
                {
                    if (requestId == -1)
                    {
                        worker.SendFile(filename);
                    }
                    else
                    {
                        requestBroker.SendFile(requestId, filename);
                    }
                    return;
                }
            }

            FileStream file = null;

            try {
                file = File.OpenRead(filename);
                // We must not call the SendResponseFromFile overload which
                // takes  IntPtr in this case since it will callthe base
                // implementation of that overload which, in turn, will
                // close the handle (as it uses FileStream to wrap the
                // handle we pass). This will cause the handle to be closed
                // twice (FileStream owns the handle). So we just take a
                // shortcut to what the base overload does here.
                SendFromStream(file, offset, length);
            } finally {
                if (file != null)
                {
                    file.Close();
                }
            }
        }