当前位置: 首页>>代码示例>>C++>>正文


C++ FileNode::read方法代码示例

本文整理汇总了C++中FileNode::read方法的典型用法代码示例。如果您正苦于以下问题:C++ FileNode::read方法的具体用法?C++ FileNode::read怎么用?C++ FileNode::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileNode的用法示例。


在下文中一共展示了FileNode::read方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: put

bool GlusterBackend::put(const SyncEvent* _putEvent) {
  if(_putEvent == nullptr || _putEvent->fullPathBuffer.empty())
      return false;

  FileNode* node = FileSystem::getInstance().findAndOpenNode(_putEvent->fullPathBuffer);
  if(node == nullptr){
    LOG(ERROR)<<_putEvent->fullPathBuffer<<" Does not exist! So can't upload it.";
    return false;
  }
  uint64_t inodeNum = FileSystem::getInstance().assignINodeNum((intptr_t)node);

  //Double check if not already uploaded
  if(node->flushed()){
    node->close(inodeNum);
    return true;
  }

  //CheckEvent validity
  if(!UploadQueue::getInstance().checkEventValidity(*_putEvent)) {
    //release file delete lock, so they can delete it
    node->close(inodeNum);
    return true;//going to be deletes so anyway say it's synced!
  }

  if(node->mustBeDeleted()){
    node->close(inodeNum);
    return true;
  }

  //Create necessary directories
  //Traverse FileSystem Hierarchies
  Poco::StringTokenizer tokenizer(_putEvent->fullPathBuffer,
      FileSystem::delimiter,Poco::StringTokenizer::TOK_TRIM |
      Poco::StringTokenizer::TOK_IGNORE_EMPTY);
  //Nested directories
  if(tokenizer.count()>=2){
    for(unsigned int i=0;i<tokenizer.count()-1;i++){
      string path = FileSystem::delimiter;
      for(unsigned int j=0;j<=i;j++){
        path += tokenizer[j];
        path += FileSystem::delimiter;
      }
      if(!createDirectory(path.c_str())){
        LOG(ERROR)<<"Failed to create parent directory("<<tokenizer[i]<<") for:"<<_putEvent->fullPathBuffer;
        node->close(inodeNum);
        return false;
      }
    }
  }
  //Create the file! (overwrite or create)
  glfs_fd_t *fd = glfs_creat((glfs_t*)fs, _putEvent->fullPathBuffer.c_str(), O_RDWR, 0644);
  //glfs_fd_t *fd = glfs_open(,O_RDWR| O_CREAT | O_TRUNC);
  if(!fd){
    LOG(ERROR)<<"Error in creating file:"<<_putEvent->fullPathBuffer<<" in GlusterFS. errno:"<<errno;
    return false;
  }

  //Ready to write (write each time a blocksize)
  uint64_t buffSize = 1024ll*1024ll*10ll;
  char *buff = new char[buffSize];//10MB buffer
  size_t offset = 0;
  long read = 0;
  //FileNode *node = _putEvent->node;
  do {
    //CheckEvent validity
    if(!UploadQueue::getInstance().checkEventValidity(*_putEvent)){
      glfs_close(fd);
      delete []buff;
      buff = nullptr;
      node->close(inodeNum);
      return true;
    }

    if(node->mustBeDeleted()){//Check Delete
      glfs_close(fd);
      delete []buff;
      buff = nullptr;
      node->close(inodeNum);
      return true;
    }

    //get lock delete so file won't be deleted
    read = node->read(buff,offset,buffSize);


    offset += read;
    int64_t written = glfs_write(fd,buff,read,0);
    if(written!=read){
      LOG(ERROR)<<"Error while writing to:"<<_putEvent->fullPathBuffer<<
          ". Asked to write:"<<read<<" but wrote:"<<written;
      glfs_close(fd);
      return false;
    }
  }
  while(read > 0);

  delete []buff;
  buff = nullptr;

  if(node->mustBeDeleted()){//Check Delete
//.........这里部分代码省略.........
开发者ID:40a,项目名称:BFS,代码行数:101,代码来源:GlusterBackend.cpp


注:本文中的FileNode::read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。