示例#1
0
        public void SendFile(string file_name)
        {
            EnsureMetadata();

            var write_file = SocketStream.MakeSendFile(file_name);

            write_file.Chunked = chunk_encode;

            if (!chunk_encode)
            {
                pending_length_cbs++;
                if (Loop.IsWindows)
                {
                    Manos.Managed.Libeio.stat(file_name, (stat, err) =>
                    {
                        if (err != null)
                        {
                            write_file.SetLength(stat.Length);
                        }
                        LengthCallback(stat.Length, err == null ? 0 : -1);
                    });
                }
                else
                {
                    Libeio.Libeio.stat(file_name, (r, stat, err) => {
                        if (r != -1)
                        {
                            write_file.SetLength(stat.st_size);
                        }
                        LengthCallback(stat.st_size, err);
                    });
                }
            }
            else
            {
                write_file.Completed += delegate {
                    length += write_file.Length;
                };
            }

            // If chunk encoding is used the initial chunk will be written by the sendfile operation
            // because only it knows the length at the time.
            //

            QueueWriteOperation(write_file);

            if (chunk_encode)
            {
                SendChunk(-1, false);
            }
        }