示例#1
0
文件: Descriptor.cpp 项目: Jurrie/ola
ssize_t ConnectedDescriptor::Send(const uint8_t *buffer,
                                  unsigned int size) {
  if (!ValidWriteDescriptor())
    return 0;

  ssize_t bytes_sent;
#ifdef _WIN32
  if (WriteDescriptor().m_type == PIPE_DESCRIPTOR) {
    DWORD bytes_written = 0;
    if (!WriteFile(ToHandle(WriteDescriptor()),
                   buffer,
                   size,
                   &bytes_written,
                   NULL)) {
      OLA_WARN << "WriteFile() failed with " << GetLastError();
      bytes_sent = -1;
    } else {
      bytes_sent = bytes_written;
    }
  } else if (WriteDescriptor().m_type == SOCKET_DESCRIPTOR) {
    bytes_sent = send(ToFD(WriteDescriptor()),
                      reinterpret_cast<const char*>(buffer),
                      size,
                      0);
  } else {
    OLA_WARN << "Send() called on unsupported descriptor type";
    return 0;
  }
#else
  // BSD Sockets
#if HAVE_DECL_MSG_NOSIGNAL
  if (IsSocket()) {
    bytes_sent = send(WriteDescriptor(), buffer, size, MSG_NOSIGNAL);
  } else {
#endif
    bytes_sent = write(WriteDescriptor(), buffer, size);
#if HAVE_DECL_MSG_NOSIGNAL
  }
#endif

#endif

  if (bytes_sent < 0 || static_cast<unsigned int>(bytes_sent) != size) {
    OLA_INFO << "Failed to send on " << WriteDescriptor() << ": " <<
      strerror(errno);
  }
  return bytes_sent;
}
示例#2
0
int ZFecFSDecoder::Open(const char *path, fuse_file_info *fileInfo)
{
    try {
        struct stat statBuf;
        std::vector<std::string> paths = GetFirstNumPathMatchesInAnyShare(path,
                                                                          GetFecWrapper().GetSharesRequired(),
                                                                          &statBuf);
        if (paths.size() < fecWrapper.GetSharesRequired() || fecWrapper.GetSharesRequired() < 1)
            throw SimpleException("Not enough encoded files.");

        // TODO vector of shared_ptr is not nice...
        std::vector<boost::shared_ptr<AbstractFile> > files;
        BOOST_FOREACH(const std::string& path, paths)
            files.push_back(boost::make_shared<File>(path));

        fileInfo->fh = ToHandle(FileDecoder::Open(files, fecWrapper));
    } catch (const std::exception& exc) {
        return -ENOENT;
    }

    return 0;
}
示例#3
0
    {
        NMediaType value;
        NCheck(NMediaFormatGetMediaType(GetHandle(), &value));
        return value;
    }

    NUInt GetMediaSubtype() const
    {
        NUInt value;
        NCheck(NMediaFormatGetMediaSubtype(GetHandle(), &value));
        return value;
    }

    void SetMediaSubtype(NUInt value)
    {
        NCheck(NMediaFormatSetMediaSubtype(GetHandle(), value));
    }

    bool IsCompatibleWith(N_CLASS(NMediaFormat) * pOtherFormat) const
    {
        NBool result;
        NCheck(NMediaFormatIsCompatibleWith(GetHandle(), ToHandle(pOtherFormat), &result));
        return result != 0;
    }
};

}
}

#endif // !N_MEDIA_FORMAT_HPP_INCLUDED