Esempio n. 1
0
void writereq(Ptr_MemoryAccessRequest ptr_memAccReq)//将访存请求写入FIFO文件
{
	int fd;
    //struct stat statbuf;
	if((fd=open("/tmp/server",O_WRONLY))<0)//以只写方式打开FIFO文件,文件标识符为fd
        error_info("打开文件失败");
    if(write(fd,ptr_memAccReq,DATALEN)<0)
        error_info("写入失败");
    printf("写入成功\n");
    //写入完成
    close(fd);
}
Esempio n. 2
0
bool async_result_handler<T>::check(error_info *error)
{
	if (!m_data->checker(m_data->statuses, m_data->total)) {
		if (error) {
			size_t success = 0;
			dnet_cmd command;
			command.status = 0;
			for (auto it = m_data->statuses.begin(); it != m_data->statuses.end(); ++it) {
				const bool failed_to_send = !(it->flags & DNET_FLAGS_REPLY);
				const bool ignore_error = failed_to_send && it->status == -ENXIO;

				if (it->status == 0) {
					++success;
				} else if (command.status == 0 && !ignore_error) {
					command = *it;
				}
			}
			if (success == 0 && command.status) {
				*error = create_error(command);
			} else {
				*error = create_error(-ENXIO, "insufficient results count due to checker: "
						"%zu of %zu (%zu)",
					success, m_data->total, m_data->statuses.size());
			}
		}
		return false;
	}
	if (error)
		*error = error_info();
	return true;
}
Esempio n. 3
0
static error_info create_info(int err, const char *id, const char *format, va_list args)
{
	if (err == -ENOMEM)
		return error_info(err, std::string());

	std::ostringstream message;
	char buffer[1024];
	const size_t buffer_size = sizeof(buffer);
	if (id) {
		message << id << ": ";
	}
	vsnprintf(buffer, buffer_size, format, args);
	buffer[buffer_size - 1] = '\0';
	message << buffer << ": " << strerror(-err) << ": " << err;
	return error_info(err, message.str());
}
Esempio n. 4
0
inline bool semaphore_open
   (sem_t *&handle, create_enum_t type, const char *origname,
    unsigned int count = 0, const permissions &perm = permissions())
{
   std::string name;
   #ifndef BOOST_INTERPROCESS_FILESYSTEM_BASED_POSIX_SEMAPHORES
   add_leading_slash(origname, name);
   #else
   create_shared_dir_cleaning_old_and_get_filepath(origname, name);
   #endif

   //Create new mapping
   int oflag = 0;
   switch(type){
      case DoOpen:
      {
         //No addition
         handle = ::sem_open(name.c_str(), oflag);
      }
      break;
      case DoOpenOrCreate:
      case DoCreate:
      {
         while(1){
            oflag = (O_CREAT | O_EXCL);
            handle = ::sem_open(name.c_str(), oflag, perm.get_permissions(), count);
            if(handle != BOOST_INTERPROCESS_POSIX_SEM_FAILED){
               //We can't change semaphore permissions!
               //::fchmod(handle, perm.get_permissions());
               break;
            }
            else if(errno == EEXIST && type == DoOpenOrCreate){
               oflag = 0;
               if( (handle = ::sem_open(name.c_str(), oflag)) != BOOST_INTERPROCESS_POSIX_SEM_FAILED
                   || (errno != ENOENT) ){
                  break;
               }
            }
            else{
               break;
            }
         }
      }
      break;
      default:
      {
         error_info err(other_error);
         throw interprocess_exception(err);
      }
   }

   //Check for error
   if(handle == BOOST_INTERPROCESS_POSIX_SEM_FAILED){
      throw interprocess_exception(error_info(errno));
   }

   return true;
}
Esempio n. 5
0
inline bool semaphore_open
   (sem_t *&handle, detail::create_enum_t type, const char *origname, mode_t mode,
    unsigned int count)
{
   std::string name;
   #ifndef BOOST_INTERPROCESS_FILESYSTEM_BASED_POSIX_SEMAPHORES
   detail::add_leading_slash(origname, name);
   #else
   detail::create_tmp_dir_and_get_filename(origname, name);
   #endif

   //Create new mapping
   int oflag = 0;
   if(mode == read_only){
      oflag |= O_RDONLY;
   }
   else if(mode == read_write){
      oflag |= O_RDWR;
   }
   else{
      error_info err(mode_error);
      throw interprocess_exception(err);
   }

   switch(type){
      case detail::DoOpen:
         //No addition
      break;
      case detail::DoCreate:
         oflag |= (O_CREAT | O_EXCL);
      break;
      case detail::DoOpenOrCreate:
         oflag |= O_CREAT;
      break;
      default:
         {
            error_info err = other_error;
            throw interprocess_exception(err);
         }
   }

   //Open file using POSIX API
   if(oflag & O_CREAT)
      handle = sem_open(name.c_str(), oflag, S_IRWXO | S_IRWXG | S_IRWXU, count);
   else
      handle = sem_open(name.c_str(), oflag);

   //Check for error
   if(handle == BOOST_INTERPROCESS_POSIX_SEM_FAILED){
      throw interprocess_exception(error_info(errno));
   }

   return true;
}
Esempio n. 6
0
   robust_mutex_lock_file()
   {
      permissions p;
      p.set_unrestricted();
      //Remove old lock files of other processes
      remove_old_robust_lock_files();
      //Create path and obtain lock file path for this process
      create_and_get_robust_lock_file_path(fname, get_current_process_id());

      //Now try to open or create the lock file
      fd = create_or_open_file(fname.c_str(), read_write, p);
      //If we can't open or create it, then something unrecoverable has happened
      if(fd == invalid_file()){
         throw interprocess_exception(other_error, "Robust emulation robust_mutex_lock_file constructor failed: could not open or create file");
      }

      //Now we must take in care a race condition with another process
      //calling "remove_old_robust_lock_files()". No other threads from this
      //process will be creating the lock file because intermodule_singleton
      //guarantees this. So let's loop acquiring the lock and checking if we
      //can't exclusively create the file (if the file is erased by another process
      //then this exclusive open would fail). If the file can't be exclusively created
      //then we have correctly open/create and lock the file. If the file can
      //be exclusively created, then close previous locked file and try again.
      while(1){
         bool acquired;
         if(!try_acquire_file_lock(fd, acquired) || !acquired ){
            throw interprocess_exception(other_error, "Robust emulation robust_mutex_lock_file constructor failed: try_acquire_file_lock");
         }
         //Creating exclusively must fail with already_exists_error
         //to make sure we've locked the file and no one has
         //deleted it between creation and locking
         file_handle_t fd2 = create_new_file(fname.c_str(), read_write, p);
         if(fd2 != invalid_file()){
            close_file(fd);
            fd = fd2;
            continue;
         }
         //If exclusive creation fails with expected error go ahead
         else if(error_info(system_error_code()).get_error_code() == already_exists_error){ //must already exist
            //Leak descriptor to mantain the file locked until the process dies
            break;
         }
         //If exclusive creation fails with unexpected error throw an unrecoverable error
         else{
            close_file(fd);
            throw interprocess_exception(other_error, "Robust emulation robust_mutex_lock_file constructor failed: create_file filed with unexpected error");
         }
      }
   }
Esempio n. 7
0
inline bool semaphore_open
   (sem_t *&handle, ipcdetail::create_enum_t type, const char *origname, 
    unsigned int count, const permissions &perm = permissions())
{
   std::string name;
   #ifndef BOOST_INTERPROCESS_FILESYSTEM_BASED_POSIX_SEMAPHORES
   ipcdetail::add_leading_slash(origname, name);
   #else
   ipcdetail::create_tmp_and_clean_old_and_get_filename(origname, name);
   #endif

   //Create new mapping
   int oflag = 0;
   switch(type){
      case ipcdetail::DoOpen:
         //No addition
      break;
      case ipcdetail::DoCreate:
         oflag |= (O_CREAT | O_EXCL);
      break;
      case ipcdetail::DoOpenOrCreate:
         oflag |= O_CREAT;
      break;
      default:
         {
            error_info err = other_error;
            throw interprocess_exception(err);
         }
   }

   //Open file using POSIX API
   if(oflag & O_CREAT)
      handle = sem_open(name.c_str(), oflag, perm.get_permissions(), count);
   else
      handle = sem_open(name.c_str(), oflag);

   //Check for error
   if(handle == BOOST_INTERPROCESS_POSIX_SEM_FAILED){
      throw interprocess_exception(error_info(errno));
   }

   return true;
}
Esempio n. 8
0
inline bool file_wrapper::priv_open_or_create
   (detail::create_enum_t type, 
    const char *filename,
    mode_t mode)
{
   m_filename = filename;

   if(mode != read_only && mode != read_write){
      error_info err(mode_error);
      throw interprocess_exception(err);
   }

   //Open file existing native API to obtain the handle
   switch(type){
      case detail::DoOpen:
         m_handle = open_existing_file(filename, mode);
      break;
      case detail::DoCreate:
         m_handle = create_new_file(filename, mode);
      break;
      case detail::DoOpenOrCreate:
         m_handle = create_or_open_file(filename, mode);
      break;
      default:
         {
            error_info err = other_error;
            throw interprocess_exception(err);
         }
   }

   //Check for error
   if(m_handle == invalid_file()){
      throw interprocess_exception(error_info(system_error_code()));
   }

   m_mode = mode;
   return true;
}
Esempio n. 9
0
inline bool robust_spin_mutex<Mutex>::is_owner_dead(boost::uint32_t own)
{
   //If owner is an invalid id, then it's clear it's dead
   if(own == (boost::uint32_t)get_invalid_process_id()){
      return true;
   }

   //Obtain the lock filename of the owner field
   std::string file;
   this->owner_to_filename(own, file);

   //Now the logic is to open and lock it
   file_handle_t fhnd = open_existing_file(file.c_str(), read_write);

   if(fhnd != invalid_file()){
      //If we can open the file, lock it.
      bool acquired;
      if(try_acquire_file_lock(fhnd, acquired) && acquired){
         //If locked, just delete the file
         delete_file(file.c_str());
         close_file(fhnd);
         return true;
      }
      //If not locked, the owner is suppossed to be still alive
      close_file(fhnd);
   }
   else{
      //If the lock file does not exist then the owner is dead (a previous cleanup)
      //function has deleted the file. If there is another reason, then this is
      //an unrecoverable error
      if(error_info(system_error_code()).get_error_code() == not_found_error){
         return true;
      }
   }
   return false;
}
Esempio n. 10
0
bool async_result_handler<get_index_metadata_result_entry>::check(error_info *error)
{
	if (error)
		*error = error_info();
	return true;
}
Esempio n. 11
0
bool async_result_handler<find_indexes_result_entry>::check(error_info *error)
{
	if (error)
		*error = error_info();
	return true;
}
Esempio n. 12
0
void SMFL_GLCheckError(const std::string&, const std::string& file, unsigned int line)
{
	// Get the last error
	GLenum LastErrorCode = GL_NO_ERROR;

	for(GLenum ErrorCode = glGetError(); ErrorCode != GL_NO_ERROR; ErrorCode = glGetError())
	{
		CASPAR_LOG(error) << "OpenGL Error: " << ErrorCode << L" " << glewGetErrorString(ErrorCode);
		LastErrorCode = ErrorCode;
	}

	if (LastErrorCode != GL_NO_ERROR)
	{
		// Decode the error code
		switch (LastErrorCode)
		{
			case GL_INVALID_ENUM :
				CASPAR_THROW_EXCEPTION(ogl_invalid_enum()
					<< msg_info("an unacceptable value has been specified for an enumerated argument")
					<< error_info("GL_INVALID_ENUM")
					<< line_info(line)
					<< source_info(file));

			case GL_INVALID_VALUE :
				CASPAR_THROW_EXCEPTION(ogl_invalid_value()
					<< msg_info("a numeric argument is out of range")
					<< error_info("GL_INVALID_VALUE")
					<< line_info(line)
					<< source_info(file));

			case GL_INVALID_OPERATION :
				CASPAR_THROW_EXCEPTION(ogl_invalid_operation()
					<< msg_info("the specified operation is not allowed in the current state")
					<< error_info("GL_INVALID_OPERATION")
					<< line_info(line)
					<< source_info(file));

			case GL_STACK_OVERFLOW :
				CASPAR_THROW_EXCEPTION(ogl_stack_overflow()
					<< msg_info("this command would cause a stack overflow")
					<< error_info("GL_STACK_OVERFLOW")
					<< line_info(line)
					<< source_info(file));

			case GL_STACK_UNDERFLOW :
				CASPAR_THROW_EXCEPTION(ogl_stack_underflow()
					<< msg_info("this command would cause a stack underflow")
					<< error_info("GL_STACK_UNDERFLOW")
					<< line_info(line)
					<< source_info(file));

			case GL_OUT_OF_MEMORY :
				CASPAR_THROW_EXCEPTION(ogl_out_of_memory()
					<< msg_info("there is not enough memory left to execute the command")
					<< error_info("GL_OUT_OF_MEMORY")
					<< line_info(line)
					<< source_info(file));

			case GL_INVALID_FRAMEBUFFER_OPERATION_EXT :
				CASPAR_THROW_EXCEPTION(ogl_stack_underflow()
					<< msg_info("the object bound to FRAMEBUFFER_BINDING_EXT is not \"framebuffer complete\"")
					<< error_info("GL_INVALID_FRAMEBUFFER_OPERATION_EXT")
					<< line_info(line)
					<< source_info(file));
		}
	}
}