예제 #1
0
        public IEnumerator <object> GetEnumerator()
        {
            /*
             * 组装协议Header. header共10字节,格式如下:
             *       8 bytes body length
             *       1 byte command
             *       1 byte status
             */
            var header = new FDFSHeader(15 + _fileStream.Length, ProtoCommon.StorageProtoCmdUploadFile, 0);

            /*
             * 组装Body
             *  0       StorePathIndex
             *  1-8     文件长度
             *  9-14    扩展名
             *  15 +    文件
             */

            var extBuffer  = Util.StringToByte(_fileExt);
            var fileHeader = new byte[15]; // 文件头

            fileHeader[0] = _storageNode.StorePathIndex;

            var lengthBuffer = Util.LongToBuffer(_fileStream.Length);

            Array.Copy(lengthBuffer, 0, fileHeader, 1, lengthBuffer.Length);
            Array.Copy(extBuffer, 0, fileHeader, 9, extBuffer.Length);

            yield return(header.ToByte());

            yield return(fileHeader);

            yield return(_fileStream);
        }
예제 #2
0
 public void ReleaseConnection(Connection conn)
 {
     if (!conn.InUse)
     {
         try
         {
             FDFSHeader header = new FDFSHeader(0, Consts.FDFS_PROTO_CMD_QUIT, 0);
             byte[] buffer = header.ToByte();
             conn.GetStream().Write(buffer, 0, buffer.Length);
             conn.GetStream().Close();
         }
         catch
         {
         }
     }
     conn.Close();            
     lock ((inUse as ICollection).SyncRoot)
     {
         inUse.Remove(conn);
     }
     autoEvent.Set();
 }
예제 #3
0
 public void ReleaseConnection(Connection conn)
 {
     if (!conn.InUse)
     {
         try
         {
             FDFSHeader header = new FDFSHeader(0, Consts.FDFS_PROTO_CMD_QUIT, 0);
             byte[]     buffer = header.ToByte();
             conn.GetStream().Write(buffer, 0, buffer.Length);
             conn.GetStream().Close();
         }
         catch
         {
         }
     }
     conn.Close();
     lock ((inUse as ICollection).SyncRoot)
     {
         inUse.Remove(conn);
     }
     autoEvent.Set();
 }