Пример #1
0
bool FileUtil::saveDescriptorWithLabel(const cv::Mat &descriptor,
                                       const int32_t label,
                                       const std::string &outputPath,
                                       const std::string &descriptorFileName,
                                       const std::string &labelFileName, const std::string &prefix)
{
    FileWriter<BIN> writer;

    if(!descriptor.empty()) {
        QDir outputDir(QString::fromStdString(outputPath));
        if(outputDir.exists()) {
            if(writer.write(descriptor, outputPath, descriptorFileName, prefix)) {
                if(appendDescriptor(labelFileName,
                                    outputPath,
                                    descriptorFileName,
                                    label,
                                    prefix)) {
                    return true;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        } else {
            error("Output directory doesn't exist, aborting.");
            return false;
        }
    } else {
        error("Empty output object given, aborting.");
        return false;
    }
}
Пример #2
0
static int 
acceptClient(int handle, void *context) 
{
  int newHandle = 0;
  int opts;
  struct sockaddr_in6 addr;
  socklen_t addrlen = sizeof(addr);

  newHandle = accept(handle, (struct sockaddr *) &addr, &addrlen);
  if (newHandle < 0) { 
    perror("accept");
    goto error;
  }

  opts = fcntl(newHandle, F_GETFL);
  if (opts < 0) {
    perror("fcntl(F_GETFL)");
    goto error;
  }  

  opts = opts | O_NONBLOCK;
  if (fcntl(newHandle, F_SETFL, opts) < 0) {
    perror("fcntl(F_SETFL)");
    goto error;
  }

  ClientRef client = createClient(newHandle);
  if (client == NULL) {
    fputs("failed to create client\n", stderr);
    goto error;
  }

  fprintf(stdout, "client [%s]:%d connected\n", 
      addrtostr((struct sockaddr *) &addr, addrlen, NULL, 0),
      addr.sin6_port);
          
  appendDescriptor(
      createDescriptor(newHandle, client, handleClient),
      (SocketDescriptorListRef) context);

  return 1;
  
error:
  if (client != NULL) disposeClient(client);
  if (newHandle >= 0) close(newHandle);
  return -1;
  
}
Пример #3
0
int 
dispatch(int port)
{
  int handle;
  fd_set fds;
  
  handle = createListener(port, 5);
  if (handle < 0) return -1;  
  appendDescriptor(
      createDescriptor(handle, &descriptorList, acceptClient),
      &descriptorList);
  
  while (1) {
    FD_ZERO(&fds);
    iterateDescriptors(&descriptorList, setFdBit, &fds);
    if (select(descriptorList.numHandles, &fds, NULL, NULL, NULL) < 0) {
      perror("select");
      return -1;
    }
    iterateDescriptors(&descriptorList, checkFdBit, &fds);
  }
}