Beispiel #1
0
void init(int argc, char **argv)
{
  int arg;
  char fname[256];

  for (arg = 1; arg < argc && argv[arg][0] == '-' && argv[arg][1] != '\0'; arg ++)
    switch (argv[arg][1]) {
      case 'r': set_real_time_priority();
		break;
    }

  if (arg + 2 != argc) {
    fprintf(stderr, "Usage: \"%s [-r] src-addr dest-addr\", where -r sets RT priority and addr is [tcp:|udp:]ip-addr:port or [file:]filename\n", argv[0]);
    exit(1);
  }

  sk_in  = create_fd(argv[arg], 0, &input_proto, source, sizeof source);
  for (int i=0; i<12; i++)
  { sprintf (fname, "%s_dip%02d.dip", argv[arg+1], i);
    dipole_fd[i] = create_fd (fname, 1, &output_proto, destination, sizeof destination);
  }

  setlinebuf(stdout);
  if_BGP_set_default_affinity();
}
Beispiel #2
0
void init(int argc, char **argv)
{
  if (argc != 3) {
    fprintf(stderr, "Usage: \"%s src-addr dest-addr\", where addr is [tcp:|udp:]ip-addr:port or [file:]filename\n", argv[0]);
    exit(1);
  }

  mmapFlatMemory();

  sk_in  = create_fd(argv[1], 0, &input_proto);
  sk_out = create_fd(argv[2], 1, &output_proto);

  setlinebuf(stdout);
}
Beispiel #3
0
int			handle_newconnection(t_selfd *fd, t_server *serv)
{
  t_net			*bind_sock;
  t_net			*nsock;
  t_selfd		*tmpfd;
  t_client		*client;

  CHECKREAD(fd);
  if (!ISREADABLE(fd))
    return (EXIT_FAILURE);
  bind_sock = (t_net*)fd->data;
  if (!(nsock = accept_connection(bind_sock)))
    return (EXIT_FAILURE);
  if ((!(client = malloc(sizeof(t_client))))
      || !(tmpfd = create_fd(nsock->socket, client, &handle_client)))
    {
      free(client);
      close_connection(nsock);
      return (EXIT_FAILURE);
    }
  nsock->peer = peer(nsock);
  client->sock = nsock;
  log_connection(nsock, "New connection from:");
  return (init_new_client(serv, tmpfd, client));
}
Beispiel #4
0
t_fd		*copy_fd(t_fd *list)
{
	t_fd *copy;

	copy = NULL;
	while (list)
	{
		copy = add_fd_elem(copy, create_fd(dup(list->fd), list->fd_pointe));
		list = list->next;
	}
	return (copy);
}
Beispiel #5
0
int sys_open(const char *filename, int file_flag, mode_t mode){
	bool create = false;
        if(filename == NULL || !(valid_address_check(curproc->p_addrspace, (vaddr_t)filename))){ //bad memory reference
                errno = EFAULT;
                return -1;
        }
		if(file_flag > 94 || file_flag % 4 == 3 || file_flag & O_APPEND){
			errno = EINVAL;
			return -1;
		}
		/*
       if(file_flag & O_APPEND){ //flags contained invalid values
                errno = EINVAL;
                return -1;
        }*/
	struct vnode* new_file;
	int ret;
	if (curproc->open_num < MAX_fd_table){	// fd table is available
		ret = vfs_open((char *)filename, file_flag, mode , &new_file);	// open file when table has free space
		curproc->open_num++;
		if (ret == 0){
			if ((file_flag & O_CREAT) && (file_flag & O_EXCL)){
				errno = EEXIST;
				return -1;
			}
		}
		else{
			create = true;
			if (file_flag & ~O_CREAT){
				errno = ENOENT;
				return -1;
			}
		}
	}
	else{	// if table is full
		if (create) errno = ENOSPC;
		else errno = EMFILE;
		return -1;
	}
        
        int file_handle = 3; //file handle is the index at which the fd is located
        
        while(curproc->fd_table[file_handle] != NULL) { //find empty slot in fd_table
                file_handle++;
        }
	struct fd* f = create_fd(file_flag, filename, new_file);
        add_fd(f,file_handle);

        return file_handle;  //index of the fd in the fd_fd_table
}
Beispiel #6
0
static int open_handler (const char *file) {
  if (file == NULL) {
    return -1;
  }

  struct inode *inode = filesys_open(file);
  if (inode == NULL) {
    return -1;
  }

  struct dir *sys_dir = NULL;
  struct file *sys_file = NULL;
  if (inode_is_dir(inode)) {
    sys_dir = dir_open(inode);
    if (sys_dir == NULL) {
      return -1;
    }
  } else {
    sys_file = file_open(inode);
    if (sys_file == NULL) {
      return -1;
    }
  }

  struct file_struct *fstruct = malloc(sizeof(struct file_struct));
  if (fstruct == NULL) {
    if (sys_file != NULL) {
      file_close(sys_file);
    } else {
      dir_close(sys_dir);
    }
    return -1;
  }

  list_push_back(&thread_current()->files, &fstruct->elem);
  fstruct->fd = create_fd();
  fstruct->sys_file = sys_file;
  fstruct->sys_dir = sys_dir;
  return fstruct->fd;
}