Пример #1
0
 /// <summary>
 /// 读取数据线程
 /// </summary>
 private void read()
 {
     using (FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, (int)bufferSize, FileOptions.RandomAccess))
     {
         do
         {
             if (isDisposed == 0)
             {
                 readWait.Wait();
             }
             ReadRequest head = readRequests.GetClear();
             if (head == null)
             {
                 return;
             }
             do
             {
                 try
                 {
                     do
                     {
                         head = head.Read(this, fileStream);
                     }while (head != null);
                     break;
                 }
                 catch (Exception error)
                 {
                     log.add(LogType.Error, error);
                 }
                 head = head.Error();
             }while (head != null);
         }while (true);
     }
 }
Пример #2
0
 /// <summary>
 /// 添加数据
 /// </summary>
 /// <param name="buffer">数据</param>
 /// <param name="onWrite">添加数据回调委托</param>
 void IBlock.Append(ref AppendBuffer buffer, AutoCSer.Net.TcpServer.ServerCallback <ulong> onWrite)
 {
     if (isDisposed == 0)
     {
         ulong index = buffer.Index & Server.MaxIndex;
         if (index == 0 || (long)index + (buffer.Buffer.Length + sizeof(int)) > fileLength)
         {
             if (writeRequests.IsPushHead(new WriteRequest(ref buffer, onWrite)))
             {
                 writeWait.Set();
             }
             if (isDisposed != 0)
             {
                 for (WriteRequest head = writeRequests.GetClear(); head != null; head = head.Error())
                 {
                     ;
                 }
             }
         }
         else
         {
             ReadRequest readRequest = new ReadRequest {
                 Index = (long)index, Size = buffer.Buffer.Length
             };
             readRequest.WriteRequest = new FileWriteRequest(ref buffer, onWrite, this);
             if (readRequests.IsPushHead(readRequest))
             {
                 readWait.Set();
             }
             if (isDisposed != 0)
             {
                 for (ReadRequest head = readRequests.GetClear(); head != null; head = head.Error())
                 {
                     ;
                 }
                 for (WriteRequest head = writeRequests.GetClear(); head != null; head = head.Error())
                 {
                     ;
                 }
             }
         }
     }
     else
     {
         onWrite.Callback(0);
     }
 }