Exemplo n.º 1
0
LeaderNode::LeaderNode() {
   // Allocate space for data structures within this object.
   allocate();

   // TODO: Make this job to run specified later during runtime. For now this is
   // just a work around for testing.
   job_exec = "./job_layer";

   // Set tag counter to 0;
   next_job_num = 0;

   // Keep the system up until told otherwise.
   shutdown = false;

   // Update the stdin_delay time.
   get_timestamp(&stdin_delay); 

   // Set initial number of swing nodes to zero.
   num_swing_nodes = 0;

   // Determine where this node is in the system.
   orient();

   // TODO: REMOVE THIS (just for testing)
   create_test_job();

   // Handle all requests sent to this cache node.
   handle_requests();
}
Exemplo n.º 2
0
LeaderNode::LeaderNode(const std::string& job_name) {
   // Job to run
   job_exec = job_name;

   // Set tag counter to 0;
   next_job_num = 0;

   // Keep the system up until told otherwise.
   shutdown = false;

   // Update the stdin_delay time.
   get_timestamp(&stdin_delay); 

   // Set initial number of swing nodes to zero.
   num_swing_nodes = 0;

   // Determine where this node is in the system.
   orient();

   // Allocate space for data structures within this object.
   allocate();

   // TODO: REMOVE THIS (just for testing)
   create_test_job();

   // Handle all requests sent to this cache node.
   handle_requests();
}
Exemplo n.º 3
0
main(int argc, char *argv[])
{

    if(getuid() != 0)
	die("This program requires to be run as root.\n");

    parse_args(argc, argv);

    if(!no_daemon) daemonize();

    signal(SIGINT, sighandler);
    signal(SIGTERM, sighandler);
    signal(SIGQUIT, sighandler);
    
    uio_init();
    tcpsv_init();

    if(pthread_create(&hw_thread, NULL, hw_thread_entry, NULL) < 0)
	die("HW thread creation error\n");

    for(;;)
    {
	handle_requests();
	handle_streaming();
    }
}
Exemplo n.º 4
0
/*
 * main() - parse command line, create a socket, handle requests
 */
int main(int argc, char **argv) {
    /* for getopt */
    long opt;
    int  lru_size = 10;
    int  port     = 9000;

    check_team(argv[0]);

    /* parse the command-line options.  They are 'p' for port number,  */
    /* and 'l' for lru cache size.  'h' is also supported. */
    while ((opt = getopt(argc, argv, "hl:p:")) != -1) {
        switch(opt) {
        case 'h':
            help(argv[0]);
            break;
        case 'l':
            lru_size = atoi(argv[0]);
            break;
        case 'p':
            port = atoi(optarg);
            break;
        }
    }

    /* open a socket, and start handling requests */
    int fd = open_server_socket(port);
    handle_requests(fd, file_server, lru_size);

    exit(0);
}
Exemplo n.º 5
0
  virtual int svc (void)
  {
    ACE_thread_t tid = this->thr_mgr ()->thr_self ();
    // Set our identifier in TSS.
    this->tss_ctx_->set_attribute ("thread_id", &tid);

    while (handle_requests () > 0)
      ;

    return 0;
  }
Exemplo n.º 6
0
void *
handle_daemon (void *arg) {
    struct daemon           *d;
    struct daemon_request   *tmp;

    d    = (struct daemon *)arg;
    if (!d)
        goto out;

    sem_wait (&daemons_lock);
    daemons = daemon_add (daemons, d);
    sem_post (&daemons_lock);
    if (!daemons) {
        daemon_free (d);
        goto out;
    }

    log_success (log_file, "BEGIN   daemon %s", d->addr);
    handle_requests (d);
    log_success (log_file, "END     daemon %s", d->addr);

    sem_wait (&daemons_lock);
    daemons = daemon_remove (daemons, d);
    sem_post (&daemons_lock);

    /* Let's clean all remaining requests for this daemon */
    sem_wait (&d->req_lock);
    for (tmp = d->requests; tmp; tmp = tmp->next) {
        /* Either it's been assigned to a thread in the pool */
        if (tmp->assigned)
            pool_kill (tmp->pool, tmp->tid);
        /* Or it's still in the queue */
        else
            pool_flush_by_arg (tmp->pool, tmp);
        daemon_request_free (tmp);
    }
    sem_post (&d->req_lock);

    daemon_free (d);

out:
    sem_wait (&nb_daemons.lock);
    --nb_daemons.count;
    sem_post (&nb_daemons.lock);

    return NULL;
}
Exemplo n.º 7
0
static void *server(void *ptr)
{
	int ret;
	struct pollfd	pfd[2];

	pfd[0].fd = sock_fd;
	pfd[0].events = POLLIN|POLLPRI;

	pfd[1].fd = comm_fd;
	pfd[1].events = POLLIN|POLLPRI;

	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
	pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);

	for(;;) {
		ret = TEMP_FAILURE_RETRY(poll(pfd, 2, -1));

		if (ret == -1)
			break;

		if (pfd[0].revents & (POLLIN|POLLPRI)) {
			server_fd = TEMP_FAILURE_RETRY(accept(sock_fd, NULL, 0));
			if (server_fd < 0)
				fatal("accept (%s)", strerror(errno));

			MT_SEND_MSG(MT_NEW, main_pid, 0, 0, NULL);

			pthread_mutex_lock(&mutex);
			wait_client = 0;
			pthread_cond_signal(&cond);
			pthread_mutex_unlock(&mutex);

			handle_requests();
			close(server_fd);

			shm->connection_count++;
			shm->info.do_trace = 0;
			server_fd = -1;
		}

		if (pfd[1].revents & (POLLIN|POLLPRI))
			handle_comm();
	}
	return NULL;
}
Exemplo n.º 8
0
static void *accept_ui(void *unused)
{
    struct sockaddr_un addr;
    socklen_t addr_len;
    int conn;

    while (1) {
        addr_len = sizeof(addr);
        conn = accept(sock, (struct sockaddr *) &addr, &addr_len);
        if (conn < 0) {
            WARNING("accept() failed: %m");
            continue;
        }
        handle_requests(conn);
        if (close(conn))
            WARNING("can't close the connection: %m");
    }

    // should not reach here
    WARNING("accept_ui() exits (it should not happen)");
    unused = unused;
    return NULL;
}