Exemplo n.º 1
0
static gboolean i3ipc_connection_initable_init(GInitable *initable, GCancellable *cancellable, GError **err) {
  i3ipcConnection *self = I3IPC_CONNECTION(initable);
  GError *tmp_error = NULL;

  g_return_val_if_fail(err == NULL || *err == NULL, FALSE);

  self->priv->socket_path = i3ipc_connection_get_socket_path(self, &tmp_error);

  if (tmp_error != NULL) {
    g_propagate_error(err, tmp_error);
    return FALSE;
  }

  int cmd_fd = get_file_descriptor(self->priv->socket_path, &tmp_error);

  if (tmp_error != NULL) {
    g_propagate_error(err, tmp_error);
    return FALSE;
  }

  self->priv->cmd_channel = g_io_channel_unix_new(cmd_fd);

  int sub_fd = get_file_descriptor(self->priv->socket_path, &tmp_error);

  if (tmp_error != NULL) {
    g_propagate_error(err, tmp_error);
    return FALSE;
  }

  self->priv->sub_channel = g_io_channel_unix_new(sub_fd);

  g_io_channel_set_encoding(self->priv->cmd_channel, NULL, &tmp_error);

  if (tmp_error != NULL) {
    g_propagate_error(err, tmp_error);
    return FALSE;
  }

  g_io_channel_set_encoding(self->priv->sub_channel, NULL, &tmp_error);

  if (tmp_error != NULL) {
    g_propagate_error(err, tmp_error);
    return FALSE;
  }

  g_io_add_watch(self->priv->sub_channel, G_IO_IN, (GIOFunc)ipc_on_data, self);

  self->priv->connected = TRUE;

  return TRUE;
}
Exemplo n.º 2
0
static void simread(const char *const *action) {
  const char *processid = action[0];
  const char *file_name = action[2];
  const char *index = action[4];
  const char *position_str =action[5];
  const char *size_str = action[6];
  msg_file_t file = NULL;
  sg_size_t size = parse_size(size_str);
  sg_offset_t position= parse_offset(position_str);
  double clock = MSG_get_clock();       /* this "call" is free thanks to inlining */
  
  if(position<2880 && (position+size)<2880)
  {
  file = get_file_descriptor("fast",file_name,index);
  ACT_DEBUG("Entering Read: %s (size: %llu)", NAME, size);
  MSG_file_seek(file,position,SEEK_SET);
  MSG_file_read(file, size);
  }
  else if(position<2880 && (position+size)>2880)
  {
  //read the Head part
  file = get_file_descriptor("fast",file_name,index);
  ACT_DEBUG("Entering Read: %s (size: %llu)", NAME, size);
  MSG_file_seek(file,position,SEEK_SET);
  MSG_file_read(file, (2880-position));
  //read the data part
  file = get_file_descriptor("slow",file_name,index);
  ACT_DEBUG("Entering Read: %s (size: %llu)", NAME, size);
  MSG_file_seek(file,2880,SEEK_SET);
  MSG_file_read(file, size-(2880-position));
  }
  else
  {
  XBT_INFO("3 position is  %llu ,size is %llu",position,size);
  file = get_file_descriptor("slow",file_name,index);
  ACT_DEBUG("Entering Read: %s (size: %llu)", NAME, size);
  MSG_file_seek(file,position,SEEK_SET);
  MSG_file_read(file, size);
  }
  
  log_action(action, MSG_get_clock() - clock);
  XBT_INFO("read  worker %s%s is done",processid,index);
}
Exemplo n.º 3
0
static void action_close(const char *const *action) {
  const char *file_name = action[2];
  msg_file_t file;
  double clock = MSG_get_clock();

  file = get_file_descriptor(file_name);

  ACT_DEBUG("Entering Close: %s (filename: %s)", NAME, file_name);
  MSG_file_close(file);

  log_action(action, MSG_get_clock() - clock);
}
Exemplo n.º 4
0
static void simrelease(const char *const *action) {
  const char *processid = action[0];
  const char *file_name = action[2];
  const char *index = action[4];
  msg_file_t file;
  double clock = MSG_get_clock();       /* this "call" is free thanks to inlining */
  file = get_file_descriptor(file_name,index);
  ACT_DEBUG("Entering Close: %s (filename: %s)", NAME, file_name);
  MSG_file_close(file);
  log_action(action, MSG_get_clock() - clock);
  XBT_INFO("release worker %s%s is done",processid,index);
}
Exemplo n.º 5
0
static void simrelease(const char *const *action) {
  const char *processid = action[0];
  const char *file_name = action[2];
  const char *worktime = action[3];
  double sleeptime;
  const char *index = action[4];
  msg_file_t file;
  double clock = MSG_get_clock();       /* this "call" is free thanks to inlining */
  //Because the action release is too fast ,to catch up with the clock of the simulator, we let it to sleep for a while.
  sleeptime = atof(worktime);
  MSG_process_sleep(sleeptime);
  //close slow file
  file = get_file_descriptor("slow",file_name,index);
  ACT_DEBUG("Entering Close: %s (filename: %s)", NAME, file_name);
  MSG_file_close(file);
  //close fast file
  file = get_file_descriptor("fast",file_name,index);
  ACT_DEBUG("Entering Close: %s (filename: %s)", NAME, file_name);
  MSG_file_close(file);
 
  log_action(action, MSG_get_clock() - clock);
  XBT_INFO("release worker %s%s is done",processid,index);
}
Exemplo n.º 6
0
static void action_read(const char *const *action) {
  const char *file_name = action[2];
  const char *size_str = action[3];
  msg_file_t file = NULL;
  sg_size_t size = parse_size(size_str);

  double clock = MSG_get_clock();

  file = get_file_descriptor(file_name);

  ACT_DEBUG("Entering Read: %s (size: %llu)", NAME, size);
  MSG_file_read(file, size);

  log_action(action, MSG_get_clock() - clock);
}
Exemplo n.º 7
0
    ProtoFrameInputStream::ProtoFrameInputStream(const char* path) :
        FrameInputStream()
    {
        m_file = fopen(path, "rb");

        if (m_file == nullptr)
        {
            throw ResourceNotFoundException(path);
        }

        m_fileDescriptor = get_file_descriptor(m_file);

        m_fileSize = get_file_size(m_fileDescriptor);

        m_inputStream = astra::make_unique<FileInputStream>(m_fileDescriptor);
    }
Exemplo n.º 8
0
static void simread(const char *const *action) {
  const char *processid = action[0];
  const char *file_name = action[2];
  const char *index = action[4];
  const char *position_str =action[5];
  const char *size_str = action[6];
  msg_file_t file = NULL;
  sg_size_t size = parse_size(size_str);
  sg_offset_t position= parse_offset(position_str);
  double clock = MSG_get_clock();       /* this "call" is free thanks to inlining */
  file = get_file_descriptor(file_name,index);
  ACT_DEBUG("Entering Read: %s (size: %llu)", NAME, size);
  MSG_file_seek(file,position,SEEK_SET);
  MSG_file_read(file, size);
  log_action(action, MSG_get_clock() - clock);
  XBT_INFO("read  worker %s%s is done",processid,index);
}
Exemplo n.º 9
0
mapid_t mmap(int fd, void *addr) {
    struct thread *curr = thread_current();
    int i;

    if (addr == 0) {
        return -1;
    }

    // Check validity of fd
    if (fd == 0 || fd == 1) {
        return -1;
    }

    struct file_desc *d = get_file_descriptor(fd);

    if (d && d->file) {
        int flength = file_length(d->file);
        if (flength == 0) {
            return -1;
        }

        int num_pages = flength / PGSIZE + 1;

        if ((int) addr & (PGSIZE - 1) != 0) {
            return -1;
        }

        void *curr_addr = addr;
        for (i = 0; i < num_pages; i++) {
            if (pagedir_get_page(curr->pagedir, curr_addr) != NULL) {
                return -1;
            }
        }

        // We should be ready to actually map at this point.
        struct mapped_file *ms = palloc_get_page(0);
        ms->page = addr;
        ms->length = num_pages;
        if (list_empty(&(thread_current()->mapped_files))) {
            ms->id = 0;
        }
        else
        {
            ms->id = list_entry(list_back(&(thread_current()->mapped_files)),
                                struct mapped_file, elem)->id + 1;
        }

        curr_addr = addr;
        int offset = 0;
        // Alter the SPT, add entries for each page
        for (i = 0; i < num_pages; i++) {
            if (flength >= PGSIZE) {
                vm_install_mmap_spte(curr_addr, d->file, offset, PGSIZE, 0, true);
            }
            else {
                vm_install_mmap_spte(curr_addr, d->file, offset, flength,
                                     PGSIZE - flength, true);
            }
            curr_addr += PGSIZE;
            offset += PGSIZE;
        }

        list_push_back(&(thread_current()->mapped_files), &(ms->elem));
        return ms->id;
    }
Exemplo n.º 10
0
int main(int argc, char *argv[]) {
	// The memory region to which the file will be mapped
	void *file_memory;
	// The file descriptor of the file we will
	// map into our process's memory
	int file_descriptor;

	// Fetch command-line arguments
	struct Arguments args;
	parse_arguments(&args, argc, argv);
	file_descriptor = get_file_descriptor(args.size);

	/*
		Arguments:
		1: Where to map the file to in the process' address
			 space; NULL = let the OS find a region
		2: The size of the file in bytes
		3: The access rights, a bitwise OR of: PROT_READ, PROT_WRITE and PROT_EXEC
		4: Flags for the mapped memory, a bitwise OR of:
			 * MAP_FIXED: don't take the first argument as a hint, but really map
				 the file there; you must ensure page-alignment,
			 * MAP_PRIVATE: make a copy of the file if a write
				 occurs, i.e. the actual file will never change, only the *local* copy,
			 * MAP_SHARED: flush modified data to the underlying
				 file immediately, instead of buffering; necessary for IPC!.
				 Without MAP_SHARED, writes may be buffered by the OS.
			 * MAP_FILE: the default (zero) flag.
		5: The file descriptor to the opened file.
		6: The offset from the beginnning in the file, starting from which to map.
	*/
	// clang-format off
  file_memory = mmap(
		NULL,
		1 + args.size,
		PROT_READ | PROT_WRITE,
		MAP_SHARED,
		file_descriptor,
	  0
	 );
	// clang-format on

	if (file_memory < 0) {
		throw("Error mapping file!");
	}

	/*
		If you do not specify MAP_SHARED, but just MAP_FILE (the default),
		writes may be buffered by the OS. You can then flush the memory manually
		by calling msync(memory_address, memory_length, flags), where flags is the
		combination of:
		* MS_SYNC: Flush immediately, blocking until it's done.
		* MS_ASYNC: Schedule a flush, but the buffer may not necessarily have been
			flushed before the call to msync returns.
		* MS_INVALIDATE: Invalidate all other process' cached data, so the change
			will be visible to them.
		Usually one would use: MS_SYNC | MS_INVALIDATE, so:
		msync(file_memory, FILE_SIZE, MS_SYNC | MS_INVALIDATE);
	*/


	// Don't need the file descriptor anymore at this point
	if (close(file_descriptor) < 0) {
		throw("Error closing file!");
	}

	communicate(file_memory, &args);

	// Unmap the file from the process memory
	// Actually unncessary because the OS will do
	// this automatically when the process terminates
	if (munmap(file_memory, args.size) < 0) {
		throw("Error unmapping file!");
	}

	close(file_descriptor);

	return EXIT_SUCCESS;
}