Exemplo n.º 1
0
        /// <summary>
        /// 开始接收表单数据
        /// </summary>
        internal void Receive()
        {
            try
            {
                AutoCSer.Memory.BufferSize size = httpSocket.GetFormPage.MaxMemoryStreamSize;
                if ((contentLength = header.ContentLength) + sizeof(int) > (int)size >> 1)
                {
                    SubBuffer.Pool.GetPool(size).Get(ref buffer);
                }
                else
                {
                    SubBuffer.Pool.GetBuffer(ref buffer, contentLength + sizeof(int));
                }
                contentLength -= (receiveEndIndex = header.CopyToFormData(ref buffer));
                bufferSize     = buffer.Length - sizeof(int);
#if !DOTNET2
                socketAsyncEventArgs.SocketError = SocketError.Success;
                socketAsyncEventArgs.SetBuffer(buffer.Buffer, receiveEndIndex, Math.Min(bufferSize - receiveEndIndex, contentLength));
#endif
                boundary = header.BoundaryIndex;
                httpSocket.SetTimeout(contentLength);
                if (onFirstBoundary())
                {
                    return;
                }
            }
            catch (Exception error)
            {
                httpSocket.DomainServer.RegisterServer.TcpServer.Log.Exception(error, null, LogLevel.Exception | LogLevel.AutoCSer);
            }
            this.error();
        }
Exemplo n.º 2
0
        /// <summary>
        /// 文件块
        /// </summary>
        /// <param name="fileName">文件名称</param>
        /// <param name="index">磁盘块编号</param>
        /// <param name="maxFlushSize">最大等待写入字节数</param>
        /// <param name="cacheSize">文件块读取缓冲区大小</param>
        /// <param name="bufferSize">文件流缓冲区大小</param>
        /// <param name="log">日志处理</param>
        /// <param name="isDataCache">是否建立数据缓存</param>
        public File(string fileName, int index, int maxFlushSize = 1 << 20, int cacheSize = 100 << 20, AutoCSer.Memory.BufferSize bufferSize = AutoCSer.Memory.BufferSize.Kilobyte4, ILog log = null, bool isDataCache = true)
            : base(index, cacheSize, log, isDataCache)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentNullException("fileName is null");
            }
            this.bufferSize   = bufferSize;
            this.maxFlushSize = waitFlushFileSize = Math.Max(maxFlushSize, 0);
            FileInfo file = new FileInfo(fileName);

            this.fileName = file.FullName;
            if (file.Extension.toLower() != ExtensionName)
            {
                this.fileName += ExtensionName;
            }
            if (file.Exists)
            {
                writeStream = new FileStream(this.fileName, FileMode.Open, FileAccess.ReadWrite, FileShare.Read, (int)bufferSize, FileOptions.None);
                fileLength  = writeStream.Length;
            }
            else
            {
                writeStream = new FileStream(this.fileName, FileMode.CreateNew, FileAccess.Write, FileShare.Read, (int)bufferSize, FileOptions.None);
                fileLength  = 0;
            }
            if (fileLength == 0)
            {
                writeWait.Set(1);
                writeRequests.Push(new WriteRequest(index));
            }
            else
            {
                byte[] data = new byte[sizeof(int) * 3];
                if (writeStream.Read(data, 0, sizeof(int) * 3) != sizeof(int) * 3)
                {
                    Dispose();
                    throw new FileLoadException(this.fileName);
                }

                fixed(byte *dataFixed = data)
                {
                    if (((*(int *)dataFixed ^ Common.PuzzleValue) | (*(int *)(dataFixed + sizeof(int)) ^ (int)AutoCSer.IO.FileHead.DiskBlockFile) | (*(int *)(dataFixed + sizeof(int) * 2) ^ index)) != 0)
                    {
                        Dispose();
                        throw new FileLoadException(this.fileName);
                    }
                }

                writeWait.Set(0);
            }
            writeStream.Seek(0, SeekOrigin.End);
            readWait.Set(0);
            AutoCSer.Threading.ThreadPool.TinyBackground.FastStart(read);
            AutoCSer.Threading.ThreadPool.Tiny.FastStart(write);
        }
Exemplo n.º 3
0
 /// <summary>
 /// HTML标题获取客户端任务池
 /// </summary>
 /// <param name="maxClientCount">最大实例数量</param>
 /// <param name="timeoutSeconds">套接字操作超时时间</param>
 /// <param name="bufferSize">收发数据缓冲区字节数</param>
 /// <param name="maxSearchSize">最大搜索字节数</param>
 /// <param name="isValidateCertificate">是否验证安全证书</param>
 /// <param name="log">日志处理</param>
 public HttpTask(int maxClientCount = 1, int timeoutSeconds = 15, AutoCSer.Memory.BufferSize bufferSize = AutoCSer.Memory.BufferSize.Kilobyte4, int maxSearchSize = 0, bool isValidateCertificate = false, AutoCSer.ILog log = null)
 {
     if (bufferSize < MinBufferSize)
     {
         bufferSize = MinBufferSize;
     }
     else if (bufferSize > AutoCSer.Memory.BufferSize.Kilobyte32)
     {
         bufferSize = AutoCSer.Memory.BufferSize.Kilobyte32;
     }
     BufferSize            = (int)bufferSize;
     MaxSearchSize         = Math.Min(BufferSize - sizeof(int), maxSearchSize);
     IsValidateCertificate = isValidateCertificate;
     this.Log      = log ?? AutoCSer.LogHelper.Default;
     BufferPool    = AutoCSer.SubBuffer.Pool.GetPool(bufferSize);
     uris          = new Uri.Queue(new Uri());
     socketTimeout = new SocketTimeoutLink(Math.Max(timeoutSeconds, 15));
     clients       = new HttpClient[maxClientCount <= 0 ? 1 : maxClientCount];
 }
Exemplo n.º 4
0
        /// <summary>
        /// 设置远程对象
        /// </summary>
        /// <param name="value"></param>
        /// <param name="blockIndex">磁盘块编号</param>
        /// <param name="bufferSize">序列化缓冲区大小</param>
        /// <returns></returns>
        public async Task <bool> SetAsync(valueType value, int blockIndex, AutoCSer.Memory.BufferSize bufferSize = AutoCSer.Memory.BufferSize.Kilobyte4)
        {
            if (value == null)
            {
                SetNull();
                return(true);
            }
            Server.TcpInternalClient client = ClientPool.Get(blockIndex);
            if (client != null)
            {
                BinarySerializer         serializer = BinarySerializer.YieldPool.Default.Pop() ?? new BinarySerializer();
                SubBuffer.PoolBufferFull buffer     = default(SubBuffer.PoolBufferFull);
                SubBuffer.Pool.GetPool(bufferSize).Get(ref buffer);
                try
                {
                    int          size;
                    AppendBuffer appendBuffer = getAppendBuffer(ref value, serializer, ref buffer, out size);
                    appendBuffer.BlockIndex = (ushort)blockIndex;
                    AutoCSer.Net.TcpServer.ReturnValue <ulong> index = await client.appendAwaiter(appendBuffer);

                    if (index.Type == Net.TcpServer.ReturnType.Success && index.Value != 0)
                    {
                        Index = index.Value;
                        Size  = size;
                        value = Value;
                        state = MemberState.Remote;
                        return(true);
                    }
                }
                finally
                {
                    buffer.Free();
                    serializer.Free();
                }
            }
            return(false);
        }
Exemplo n.º 5
0
 /// <summary>
 /// TCP 服务客户端
 /// </summary>
 /// <param name="attribute">TCP 服务调用配置</param>
 /// <param name="receiveBufferSize">接受数据缓冲区字节大小</param>
 /// <param name="sendBufferSize">发送数据缓冲区字节大小</param>
 /// <param name="sendBufferMaxSize">发送数据缓存区最大字节大小</param>
 /// <param name="log">日志接口</param>
 internal CommandBuffer(ServerBaseAttribute attribute, AutoCSer.Memory.BufferSize receiveBufferSize, AutoCSer.Memory.BufferSize sendBufferSize, int sendBufferMaxSize, ILog log)
     : base(attribute, sendBufferMaxSize, log)
 {
     SendBufferPool    = SubBuffer.Pool.GetPool(sendBufferSize);
     ReceiveBufferPool = SubBuffer.Pool.GetPool(receiveBufferSize);
 }