/// <summary> /// 发送文件数据 /// </summary> /// <param name="onSend">发送数据回调处理</param> /// <param name="fileName">文件名称</param> /// <param name="seek">起始位置</param> /// <param name="size">发送字节长度</param> public void SendFile(onSendType onSend, string fileName, long seek, long size) { try { fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read, fastCSharp.config.appSetting.StreamBufferSize, FileOptions.SequentialScan); if (fileStream.Length >= seek + size) { if (seek != 0) { fileStream.Seek(seek, SeekOrigin.Begin); } this.onSend = onSend; sendStartTime = date.nowTime.Now.AddTicks(date.SecondTicks); fileSize = size; sendLength = 0; memoryPool = net.socket.ServerSendBuffers; buffer = memoryPool.Get(); readFile(); return; } else { fileStream.Dispose(); } } catch (Exception error) { log.Error.Add(error, null, false); } onSendFalse(onSend); }
/// <summary> /// 发送数据 /// </summary> /// <param name="onSend">发送数据回调处理</param> /// <param name="buffer">发送数据缓冲区</param> /// <param name="memoryPool">发送数据缓冲区内存池</param> public void Send(onSendType onSend, ref subArray <byte> buffer, memoryPool memoryPool) { this.onSend = onSend; sendStartTime = date.nowTime.Now.AddTicks(date.SecondTicks); this.memoryPool = memoryPool; this.buffer = buffer.array; sendIndex = buffer.startIndex; sendLength = 0; sendEndIndex = sendIndex + buffer.length; send(); }
public void Send(onSendType onSend, subArray <byte> buffer) { Send(onSend, ref buffer, null); }