Exemplo n.º 1
0
int main (int argc, char **argv)
{
	struct gengetopt_args_info opts;
	struct vfi_source *s;
	struct vfi_dev *dev;

	vfi_open(&dev,NULL,opts.timeout_arg);

	cmdline_parser_init(&opts);

	cmdline_parser(argc,argv,&opts);

	if (opts.file_given) {
		vfi_setup_file(dev,&s,fopen(opts.file_arg,"r"));
		process_commands(dev,s,&opts);
	}

	if (opts.inputs_num) {
		setup_inputs(dev,&s,&opts);
		process_commands(dev,s,&opts);
	}

	if (opts.interactive_given) {
		vfi_setup_file(dev,&s,stdin);
		process_commands(dev,s,&opts);
	}

	vfi_close(dev);

	return 0;
}
Exemplo n.º 2
0
int srvmgr_module_run(char *base_path, char *data, int authorized)
{
	char config_file[BUFSIZE];
	tTokenizer t;
	int ret;

	if (strncmp(data, MODULE_KEYWORD, strlen(MODULE_KEYWORD)) != 0)
		return -ENOTSUP;

	DPRINTF("[%s] Input data: '%s' ( user %s authorized )\n", MODULE_IDENTIFICATION,
		data, authorized ? "is" : "NOT");

	t = tokenize(data);
	if (t.numTokens == 0)
		return -EINVAL;

	snprintf(config_file, sizeof(config_file), "%s/manager.conf", base_path);
	if (access(config_file, R_OK) != 0) {
		DPRINTF("%s: Cannot read configuration file '%s'\n", __FUNCTION__,
			config_file);
		free_tokens(t);
		return -EINVAL;
	}

	ret = process_commands(config_file, authorized, t);
	free_tokens(t);

	return ret;
}
Exemplo n.º 3
0
void zmq::socket_base_t::in_event ()
{
    //  Process any commands from other threads/sockets that may be available
    //  at the moment. Ultimately, socket will be destroyed.
    process_commands (false, false);
    check_destroy ();
}
void get_command() {
    if ( pc.readable() ) {
        serial_char = pc.getc();

        if (serial_char == '\n' || serial_char == '\r' || serial_char == ':' || serial_count >= (MAX_CMD_SIZE - 1) ) {
            if (!serial_count) {
                return; //empty line
            }
            cmdbuffer[serial_count] = 0; //terminate string

            process_commands();

            comment_mode = false; //for new command
            serial_count = 0; //clear buffer
            //Serial.println("ok");
        } else {
            if (serial_char == ';') {
                comment_mode = true;
            }
            if (!comment_mode) {
                cmdbuffer[serial_count++] = serial_char;
            }
        }
    }


}
Exemplo n.º 5
0
/******************************************************************************
    rn42_task
*//**
    @brief Handles receiving data from the RN42 bluetooth module.
******************************************************************************/
void
rn42_task(void)
{
    static bool connected = false;
    bool current_status = rn42_connected();

    if (connected != current_status)
    {
        connected = current_status;

        if (connected)
        {
            LED_On(LED1);
        }
        else
        {
            LED_Off(LED1);
        }
    }

    if (connected)
    {
        process_commands();
    }
}
 DriverPriorityQueue() : q(regular_gt){
     std::string allowable[] = {"r","R",""};
     bool (*gt)(const std::string& a, const std::string& b);
     gt = (ics::prompt_string("Enter comparison for Priority Queue: r[egular] or R[everse]\n  regular means smaller values have higher priority","r",allowable) =="r" ? regular_gt : reverse_gt);
     q = PriorityQueueType(gt);
     process_commands("");
   };
Exemplo n.º 7
0
int zmq::socket_base_t::term_endpoint (const char *addr_)
{
    //  Check whether the library haven't been shut down yet.
    if (unlikely (ctx_terminated)) {
        errno = ETERM;
        return -1;
    }

    //  Check whether endpoint address passed to the function is valid.
    if (unlikely (!addr_)) {
        errno = EINVAL;
        return -1;
    }

    //  Process pending commands, if any, since there could be pending unprocessed process_own()'s
    //  (from launch_child() for example) we're asked to terminate now.
    int rc = process_commands (0, false);
    if (unlikely (rc != 0))
        return -1;

    //  Find the endpoints range (if any) corresponding to the addr_ string.
    std::pair <endpoints_t::iterator, endpoints_t::iterator> range = endpoints.equal_range (std::string (addr_));
    if (range.first == range.second)
        return -1;

    for (endpoints_t::iterator it = range.first; it != range.second; ++it)
        term_child (it->second);
    endpoints.erase (range.first, range.second);
    return 0;
}
Exemplo n.º 8
0
int zmq::socket_base_t::term_endpoint (const char *addr_)
{
    //  Check whether the library haven't been shut down yet.
    if (unlikely (ctx_terminated)) {
        errno = ETERM;
        return -1;
    }

    //  Check whether endpoint address passed to the function is valid.
    if (unlikely (!addr_)) {
        errno = EINVAL;
        return -1;
    }

    //  Process pending commands, if any, since there could be pending unprocessed process_own()'s
    //  (from launch_child() for example) we're asked to terminate now.
    int rc = process_commands (0, false);
    if (unlikely (rc != 0))
        return -1;

    //  Parse addr_ string.
    std::string protocol;
    std::string address;
    if (parse_uri (addr_, protocol, address) || check_protocol (protocol))
        return -1;

    // Disconnect an inproc socket
    if (protocol == "inproc") {
        if (unregister_endpoint (std::string (addr_), this) == 0)
            return 0;
        std::pair <inprocs_t::iterator, inprocs_t::iterator> range = inprocs.equal_range (std::string (addr_));
        if (range.first == range.second) {
            errno = ENOENT;
            return -1;
        }

        for (inprocs_t::iterator it = range.first; it != range.second; ++it)
            it->second->terminate (true);
        inprocs.erase (range.first, range.second);
        return 0;
    }

    //  Find the endpoints range (if any) corresponding to the addr_ string.
    std::pair <endpoints_t::iterator, endpoints_t::iterator> range = endpoints.equal_range (std::string (addr_));
    if (range.first == range.second) {
        errno = ENOENT;
        return -1;
    }

    for (endpoints_t::iterator it = range.first; it != range.second; ++it) {
        //  If we have an associated pipe, terminate it.
        if (it->second.second != NULL)
            it->second.second->terminate (false);
        term_child (it->second.first);
    }
    endpoints.erase (range.first, range.second);
    return 0;
}
int zmq::socket_base_t::getsockopt (int option_, void *optval_,
                                    size_t *optvallen_)
{
    if (unlikely (ctx_terminated)) {
        errno = ETERM;
        return -1;
    }

    if (option_ == ZMQ_RCVMORE) {
        if (*optvallen_ < sizeof (int)) {
            errno = EINVAL;
            return -1;
        }
        *((int*) optval_) = rcvmore ? 1 : 0;
        *optvallen_ = sizeof (int);
        return 0;
    }

    if (option_ == ZMQ_FD) {
        if (*optvallen_ < sizeof (fd_t)) {
            errno = EINVAL;
            return -1;
        }
        *((fd_t*) optval_) = mailbox.get_fd ();
        *optvallen_ = sizeof (fd_t);
        return 0;
    }

    if (option_ == ZMQ_EVENTS) {
        if (*optvallen_ < sizeof (int)) {
            errno = EINVAL;
            return -1;
        }
        int rc = process_commands (0, false);
        if (rc != 0 && (errno == EINTR || errno == ETERM))
            return -1;
        errno_assert (rc == 0);
        *((int*) optval_) = 0;
        if (has_out ())
            *((int*) optval_) |= ZMQ_POLLOUT;
        if (has_in ())
            *((int*) optval_) |= ZMQ_POLLIN;
        *optvallen_ = sizeof (int);
        return 0;
    }

    if (option_ == ZMQ_LAST_ENDPOINT) {
        if (*optvallen_ < last_endpoint.size () + 1) {
            errno = EINVAL;
            return -1;
        }
        strcpy (static_cast <char *> (optval_), last_endpoint.c_str ());
        *optvallen_ = last_endpoint.size () + 1;
        return 0;
    }

    return options.getsockopt (option_, optval_, optvallen_);
}
Exemplo n.º 10
0
int zmq::socket_base_t::getsockopt (int option_, void *optval_,
    size_t *optvallen_)
{
    if (unlikely (ctx_terminated)) {
        errno = ETERM;
        return -1;
    }

    if (option_ == ZMQ_RCVLABEL) {
        if (*optvallen_ < sizeof (int)) {
            errno = EINVAL;
            return -1;
        }
        *((int*) optval_) = rcvlabel ? 1 : 0;
        *optvallen_ = sizeof (int);
        return 0;
    }

    if (option_ == ZMQ_RCVMORE) {
        if (*optvallen_ < sizeof (int)) {
            errno = EINVAL;
            return -1;
        }
        *((int*) optval_) = rcvmore ? 1 : 0;
        *optvallen_ = sizeof (int);
        return 0;
    }

    if (option_ == ZMQ_FD) {
        if (*optvallen_ < sizeof (fd_t)) {
            errno = EINVAL;
            return -1;
        }
        *((fd_t*) optval_) = mailbox.get_fd ();
        *optvallen_ = sizeof (fd_t);
        return 0;
    }

    if (option_ == ZMQ_EVENTS) {
        if (*optvallen_ < sizeof (int)) {
            errno = EINVAL;
            return -1;
        }
        int rc = process_commands (0, false);
        if (rc != 0 && (errno == EINTR || errno == ETERM))
            return -1;
        errno_assert (rc == 0);
        *((int*) optval_) = 0;
        if (has_out ())
            *((int*) optval_) |= ZMQ_POLLOUT;
        if (has_in ())
            *((int*) optval_) |= ZMQ_POLLIN;
        *optvallen_ = sizeof (int);
        return 0;
    }

    return options.getsockopt (option_, optval_, optvallen_);
}
void zmq::socket_base_t::in_event ()
{
    //  This function is invoked only once the socket is running in the context
    //  of the reaper thread. Process any commands from other threads/sockets
    //  that may be available at the moment. Ultimately, the socket will
    //  be destroyed.
    process_commands (0, false);
    check_destroy ();
}
Exemplo n.º 12
0
int zmq::socket_base_t::send (::zmq_msg_t *msg_, int flags_)
{
    //  Check whether the library haven't been shut down yet.
    if (unlikely (ctx_terminated)) {
        errno = ETERM;
        return -1;
    }

    //  Check whether message passed to the function is valid.
    if (unlikely ((msg_->flags | ZMQ_MSG_MASK) != 0xff)) {
        errno = EFAULT;
        return -1;
    }

    //  Process pending commands, if any.
    int rc = process_commands (false, true);
    if (unlikely (rc != 0))
        return -1;

    //  At this point we impose the MORE flag on the message.
    if (flags_ & ZMQ_SNDMORE)
        msg_->flags |= ZMQ_MSG_MORE;

    //  Try to send the message.
    rc = xsend (msg_, flags_);
    if (rc == 0)
        return 0;

    //  In case of non-blocking send we'll simply propagate
    //  the error - including EAGAIN - upwards.
    if (flags_ & ZMQ_NOBLOCK)
        return -1;

    //  Oops, we couldn't send the message. Wait for the next
    //  command, process it and try to send the message again.
    while (rc != 0) {
        if (errno != EAGAIN)
            return -1;
        if (unlikely (process_commands (true, false) != 0))
            return -1;
        rc = xsend (msg_, flags_);
    }
    return 0;
}
Exemplo n.º 13
0
void gcode_loop(void) {
    if (buflen < (BUFSIZE - 1))
        get_command();

    if (buflen) {
        process_commands();
        buflen = (buflen - 1);
        bufindr = (bufindr + 1) % BUFSIZE;
    }
}
Exemplo n.º 14
0
int main(int argc,char ** argv)
{
  daemon_init();
  for (;;)
  {
    process_commands();
    sleep(10);
  }
  return 0;
}
Exemplo n.º 15
0
/*************************M*A*I*N*************************/
int main(void) {
	turtle_t boo;
	pen_t pen;
	srand(time(NULL));

	set_ps_header(HEIGHT, WIDTH);
	process_commands(&boo, &pen);
	set_ps_display();

	return 0;
}
Exemplo n.º 16
0
int main(int argc, char *argv[])
{
	init();
	if(init_setting() != 0){
		print_errmsg("ERROR: SETTING init fail. \n");
		return 1;	
	}
	if(gc_init() != 0){
		print_errmsg("ERROR: G_CODE init fail. \n");
		return 1;
	}
	if (cm_init() == false)
	{
		print_errmsg("ERROR: USB-DEV init fail. \n");
		return 1;
	}
  
	if (cmd_init() == false)
	{
		print_errmsg("ERROR: G code init fail.\n");
		cm_close();
		return 1;
	}
	
	if (tp_init() == false)
	{
		print_errmsg("ERROR: Temperature library init fail. \n");
		cmd_close();
		cm_close();
		return 1;
	}

	plan_init();
	Config_ResetDefault();
	st_init();

	while(1) {
		LCD(10UL);
		getCommand(10UL);
		process_commands(50UL);
		stepper(1000L);
		manageHeater(10UL);
	}

	st_close();
	plan_close();
	tp_close();
	cmd_close();
	cm_close();
	//debug
	//sfp_close();
	return 0;
}
Exemplo n.º 17
0
int zmq::socket_base_t::send (::zmq_msg_t *msg_, int flags_)
{

	//LOGD() << "zmq::socket_base_t::send" << LOG_ENDL();

    if (unlikely (ctx_terminated)) {
        errno = ETERM;
        return -1;
    }

    //  Process pending commands, if any.
    int rc = process_commands (false, true);
    if (unlikely (rc != 0))
        return -1;

    //  At this point we impose the MORE flag on the message.
    if (flags_ & ZMQ_SNDMORE)
        msg_->flags |= ZMQ_MSG_MORE;

    //  Try to send the message.
    rc = xsend (msg_, flags_);
    if (rc == 0)
        return 0;

    //  In case of non-blocking send we'll simply propagate
    //  the error - including EAGAIN - upwards.
    if (flags_ & ZMQ_NOBLOCK)
        return -1;

    //  Oops, we couldn't send the message. Wait for the next
    //  command, process it and try to send the message again.
    while (rc != 0) {
        if (errno != EAGAIN)
            return -1;
        if (unlikely (process_commands (true, false) != 0))
            return -1;
        rc = xsend (msg_, flags_);
    }
    return 0;
}
Exemplo n.º 18
0
/*-------------------------------------------------
* And the primary command parser loop
*/
void loop()
{
  if(buflen < (BUFSIZE-1))
    get_command();

  if(buflen)
  {
    process_commands();
    buflen = (buflen-1);
    bufindr = (bufindr + 1)%BUFSIZE;
  } else {
	manage_inactivity();
  }
}
Exemplo n.º 19
0
static TIMER_CALLBACK( vsync_update )
{
	const device_config *laserdisc = device_list_first(machine->config->devicelist, LASERDISC);
	int vblank_scanline;
	attotime target;

	/* handle commands */
	if (!param)
		process_commands(laserdisc);

	/* set a timer to go off on the next VBLANK */
	vblank_scanline = video_screen_get_visible_area(machine->primary_screen)->max_y + 1;
	target = video_screen_get_time_until_pos(machine->primary_screen, vblank_scanline, 0);
	timer_set(machine, target, NULL, 0, vsync_update);
}
Exemplo n.º 20
0
int main(void) {
    enum CID cid;
    puts("Добропожаловать в программу базы кораблей!");
    db_ship();
    puts("вот команды, которые вам понадобятся для работы:");
    show_help();
    
    while (1) {
       putchar('>'); //fflush(stdout);
       cid = input();
        if (cid == EXIT)
              return 0;
       process_commands(cid);
}

}
Exemplo n.º 21
0
void zmq::socket_base_t::in_event ()
{
    //  This function is invoked only once the socket is running in the context
    //  of the reaper thread. Process any commands from other threads/sockets
    //  that may be available at the moment. Ultimately, the socket will
    //  be destroyed.
    ENTER_MUTEX ();

    //  If the socket is thread safe we need to unsignal the reaper signaler
    if (thread_safe)
        reaper_signaler->recv();

    process_commands (0, false);
    EXIT_MUTEX ();
    check_destroy ();
}
Exemplo n.º 22
0
void loop()
{
  unsigned long current_time = millis();

  if (current_time - last_time > 1000 || last_time == -1) {
    ledState = ledState == HIGH ? LOW : HIGH;
    digitalWrite(HEARTBEAT_LED, ledState);

    maintain_system(current_time);

    last_time = current_time;

    uptime += 1;
  }

  process_commands();
  delay(1);
}
Exemplo n.º 23
0
  void process_iterator_commands(StackType& s, std::string preface) {
    std::string allowable[] = {"<","e","*","+","i","c","*a","ea","f","q",""};
    StackType::Iterator i = s.begin();
    for (;;)
      try {
        std::cout << std::endl;
        std::cout << preface+"i = " << i.str() << std::endl;
        std::string i_command = ics::prompt_string(preface+
            "Enter iterator command(<[<]/e[rase]/*/+[+i]/i[++]/c[ommands]/*a[ll]/ea[ll]/f[or]/q[uit])","",allowable);
        if (i_command == "<")
          std::cout << preface +" << = " << i << std::endl;
        else if (i_command == "e")
          std::cout << preface+"  erase = " << i.erase() << std::endl;
        else if (i_command == "*")
          std::cout << preface+"  * = " << *i << std::endl;
        else if (i_command == "+")
          std::cout << preface+"  ++i returned = " << ++i << std::endl;
        else if (i_command == "i")
          std::cout << preface+"  i++ returned = " << i++ << std::endl;
        else if (i_command == "c")
          process_commands(preface);
        else if (i_command == "*a") {
          std::cout << preface+"  initially i = " << i << std::endl;
          for (; i != s.end(); ++i)
            std::cout << preface+"  *(all) = " << *i << std::endl;
          std::cout << preface+"  finally i = " << i << std::endl;
        }
        else if (i_command == "ea") {
          std::cout << preface+"  initially i = " << i << std::endl;
         for (; i != s.end(); ++i)
            std::cout << preface+"  erase(all) = " << i.erase() << std::endl;
          std::cout << preface+"  finally i = " << i << std::endl;
        }
        else if (i_command == "f") {
          for (auto v : s)
            std::cout << preface+"  *(all) = " << v << std::endl;
        }
        else if (i_command == "q")
          break;

      } catch (ics::IcsError& e) {
        std::cout << preface+"  " << e.what() << std::endl;
      }
  };
  void process_iterator_commands(SetType& s, std::string preface) {
    std::string allowable[] = {"<","e","*","+","+o","c","*a","ea","f","q",""};
    ics::Iterator<std::string>& i = s.abegin();
    for (;;)
      try {
        std::cout << "\n"+preface+"i = " << i.str() << std::endl;
        std::string i_command = ics::prompt_string(preface+
            "Enter iterator command(<[<]/e[rase]/*/+[+e]/+[+]o/c[ommands]/*a[ll]/ea[ll]/f[or]/q[uit])","",allowable);
        if (i_command == "<")
          std::cout << preface+"  << = " << i << std::endl;
        else if (i_command == "e")
          std::cout << preface+"  erase = " << i.erase() << std::endl;
        else if (i_command == "*")
          std::cout << preface+"  * = " << *i << std::endl;
        else if (i_command == "+")
          ++i;
        else if (i_command == "+o")
          i++;
        else if (i_command == "c")
          process_commands(preface);
        else if (i_command == "*a") {
          std::cout << preface+"  initially i = " << i << std::endl;
          for (; i != s.aend(); ++i)
            std::cout << preface+"  *(all) = " << *i << std::endl;
          std::cout << preface+"  finally i = " << i << std::endl;
        }
        else if (i_command == "ea") {
          std::cout << preface+"  initially i = " << i << std::endl;
         for (; i != s.aend(); ++i)
            std::cout << preface+"  erase(all) = " << i.erase() << std::endl;
          std::cout << preface+"  finally i = " << i << std::endl;
        }
        else if (i_command == "f") {
          for (auto v : s)
            std::cout << preface+"  *(all) = " << v << std::endl;
        }
        else if (i_command == "q")
          break;

      } catch (ics::IcsError& e) {
        std::cout << preface+"  " << e.what() << std::endl;
      }
  };
void ipaugenblick_main_loop()
{
    struct rte_mbuf *mbuf;
    uint8_t ports_to_poll[1] = { 0 };
    int drv_poll_interval = get_max_drv_poll_interval_in_micros(0);
    app_glue_init_poll_intervals(drv_poll_interval/(2*MAX_PKT_BURST),
                                 100 /*timer_poll_interval*/,
                                 drv_poll_interval/(10*MAX_PKT_BURST),
                                drv_poll_interval/(60*MAX_PKT_BURST));
    
    ipaugenblick_service_api_init(COMMAND_POOL_SIZE,DATA_RINGS_SIZE,DATA_RINGS_SIZE);
    TAILQ_INIT(&buffers_available_notification_socket_list_head);
    TAILQ_INIT(&ipaugenblick_clients_list_head);
    init_systick(rte_lcore_id());
    ipaugenblick_log(IPAUGENBLICK_LOG_INFO,"IPAugenblick service initialized\n");
    while(1) {
        process_commands();
	app_glue_periodic(1,ports_to_poll,1);
        while(!TAILQ_EMPTY(&buffers_available_notification_socket_list_head)) {
            if(get_buffer_count() > 0) {
                struct socket *sock = TAILQ_FIRST(&buffers_available_notification_socket_list_head);
                socket_satelite_data_t *socket_data = get_user_data(sock);
		if(socket_data->socket->type == SOCK_DGRAM)
		   	user_set_socket_tx_space(&g_ipaugenblick_sockets[socket_data->ringset_idx].tx_space,sk_stream_wspace(socket_data->socket->sk));
		//printf("%s %d %d %d %d\n",__FILE__,__LINE__,socket_data->ringset_idx,g_ipaugenblick_sockets[socket_data->ringset_idx].tx_space,sk_stream_wspace(socket_data->socket->sk));
                if(!ipaugenblick_mark_writable(socket_data)) { 
                    sock->buffers_available_notification_queue_present = 0;
                    TAILQ_REMOVE(&buffers_available_notification_socket_list_head,sock,buffers_available_notification_queue_entry); 
                }
                else {
                    break;
                }
            }
            else {
                break;
            }
        }
    }
}
Exemplo n.º 26
0
void PixelPipeline::worker_main(int core)
{
#if defined(WIN32) && defined(PROFILE_PIPELINE)
	SetThreadIdealProcessor(GetCurrentThread(), core);
	SetThreadAffinityMask(GetCurrentThread(), 1 << core);
	unsigned __int64 ticks_waiting = 0;
	unsigned __int64 ticks_working = 0;
#endif
	PixelThreadContext context(core, active_cores);
	while (true)
	{
#if defined(WIN32) && defined(PROFILE_PIPELINE)
		unsigned __int64 wait_start_time = __rdtsc();
#endif
		int wakeup_reason = Event::wait(event_more_commands[core], event_stop);
		if (wakeup_reason != 0)
			break;
		event_more_commands[core].reset();
#if defined(WIN32) && defined(PROFILE_PIPELINE)
		unsigned __int64 wait_end_time = __rdtsc();
		ticks_waiting += wait_end_time-wait_start_time;
#endif
		process_commands(&context);
#if defined(WIN32) && defined(PROFILE_PIPELINE)
		unsigned __int64 commands_end_time = __rdtsc();
		ticks_working += commands_end_time-wait_end_time;
#endif
	}
#if defined(WIN32) && defined(PROFILE_PIPELINE)
	MessageBoxA(
		0,
		cl_format("Pipeline core %1 spent %2 percent of its time waiting for commands",
		core,
		(int)(ticks_waiting*100/(ticks_working+ticks_waiting))).c_str(),
		"DEBUG", MB_OK);
#endif
}
Exemplo n.º 27
0
static int
on_incoming_data(int fd, const char *data, size_t len) {
  size_t to_copy = (len > rbufsize) ? rbufsize : len;
  memcpy(rbuf, data, to_copy);
  rbuf += to_copy;
  rbufsize -= to_copy;

  const char *request_end;
  for (request_end = request_buffer; request_end < rbuf; request_end++) {
      if (*request_end == '\0') break;
  }

  if (*request_end != '\0') {
    // drop the connection if we filled the buffer but
    // haven't seen a request, and keep going otherwise.
    return rbufsize > 0;
  }

  char *request = strndup(request_buffer, request_end - request_buffer);
  rbuf = request_buffer;
  rbufsize = REQUEST_BUFFER_SIZE;

  struct timeval  before;
  struct timeval  after;
  gettimeofday(&before, NULL);
  char *response = process_commands(client, request);
  gettimeofday(&after, NULL);

  double time_in_mill = 
    (after.tv_sec-before.tv_sec) * 1000.0 + (after.tv_usec-before.tv_usec) / 1000.0 ;
  fprintf(stdout,"Time spent with request '%s': %.3f ms\n",request,time_in_mill);

  send(fd, response, strlen(response) + 1 /* send \0 as well */, 0);
  free(request);
  free(response);
  return 1;
}
Exemplo n.º 28
0
void ldplayer_state::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
{
	switch (id)
	{
		case TIMER_ID_VSYNC_UPDATE:
		{
			// handle commands
			if (param == 0)
				process_commands();

			// set a timer to go off on the next VBLANK
			int vblank_scanline = machine().primary_screen->visible_area().max_y + 1;
			attotime target = machine().primary_screen->time_until_pos(vblank_scanline);
			timer_set(target, TIMER_ID_VSYNC_UPDATE);
			break;
		}

		case TIMER_ID_AUTOPLAY:
			// start playing
			execute_command(CMD_PLAY);
			m_playing = true;
			break;
	}
}
int zmq::socket_base_t::recv (msg_t *msg_, int flags_)
{
    //  Check whether the library haven't been shut down yet.
    if (unlikely (ctx_terminated)) {
        errno = ETERM;
        return -1;
    }

    //  Check whether message passed to the function is valid.
    if (unlikely (!msg_ || !msg_->check ())) {
        errno = EFAULT;
        return -1;
    }

    //  Once every inbound_poll_rate messages check for signals and process
    //  incoming commands. This happens only if we are not polling altogether
    //  because there are messages available all the time. If poll occurs,
    //  ticks is set to zero and thus we avoid this code.
    //
    //  Note that 'recv' uses different command throttling algorithm (the one
    //  described above) from the one used by 'send'. This is because counting
    //  ticks is more efficient than doing RDTSC all the time.
    if (++ticks == inbound_poll_rate) {
        if (unlikely (process_commands (0, false) != 0))
            return -1;
        ticks = 0;
    }

    //  Get the message.
    int rc = xrecv (msg_);
    if (unlikely (rc != 0 && errno != EAGAIN))
        return -1;

    //  If we have the message, return immediately.
    if (rc == 0) {
        if (file_desc != retired_fd)
            msg_->set_fd(file_desc);
        extract_flags (msg_);
        return 0;
    }

    //  If the message cannot be fetched immediately, there are two scenarios.
    //  For non-blocking recv, commands are processed in case there's an
    //  activate_reader command already waiting int a command pipe.
    //  If it's not, return EAGAIN.
    if (flags_ & ZMQ_DONTWAIT || options.rcvtimeo == 0) {
        if (unlikely (process_commands (0, false) != 0))
            return -1;
        ticks = 0;

        rc = xrecv (msg_);
        if (rc < 0)
            return rc;
        if (file_desc != retired_fd)
            msg_->set_fd(file_desc);
        extract_flags (msg_);
        return 0;
    }

    //  Compute the time when the timeout should occur.
    //  If the timeout is infinite, don't care.
    int timeout = options.rcvtimeo;
    uint64_t end = timeout < 0 ? 0 : (clock.now_ms () + timeout);

    //  In blocking scenario, commands are processed over and over again until
    //  we are able to fetch a message.
    bool block = (ticks != 0);
    while (true) {
        if (unlikely (process_commands (block ? timeout : 0, false) != 0))
            return -1;
        rc = xrecv (msg_);
        if (rc == 0) {
            ticks = 0;
            break;
        }
        if (unlikely (errno != EAGAIN))
            return -1;
        block = true;
        if (timeout > 0) {
            timeout = (int) (end - clock.now_ms ());
            if (timeout <= 0) {
                errno = EAGAIN;
                return -1;
            }
        }
    }

    if (file_desc != retired_fd)
        msg_->set_fd(file_desc);
    extract_flags (msg_);
    return 0;
}
int zmq::socket_base_t::send (msg_t *msg_, int flags_)
{
    //  Check whether the library haven't been shut down yet.
    if (unlikely (ctx_terminated)) {
        errno = ETERM;
        return -1;
    }

    //  Check whether message passed to the function is valid.
    if (unlikely (!msg_ || !msg_->check ())) {
        errno = EFAULT;
        return -1;
    }

    //  Process pending commands, if any.
    int rc = process_commands (0, true);
    if (unlikely (rc != 0))
        return -1;

    //  Clear any user-visible flags that are set on the message.
    msg_->reset_flags (msg_t::more);

    //  At this point we impose the flags on the message.
    if (flags_ & ZMQ_SNDMORE)
        msg_->set_flags (msg_t::more);

    //  Try to send the message.
    rc = xsend (msg_);
    if (rc == 0)
        return 0;
    if (unlikely (errno != EAGAIN))
        return -1;

    //  In case of non-blocking send we'll simply propagate
    //  the error - including EAGAIN - up the stack.
    if (flags_ & ZMQ_DONTWAIT || options.sndtimeo == 0)
        return -1;

    //  Compute the time when the timeout should occur.
    //  If the timeout is infinite, don't care.
    int timeout = options.sndtimeo;
    uint64_t end = timeout < 0 ? 0 : (clock.now_ms () + timeout);

    //  Oops, we couldn't send the message. Wait for the next
    //  command, process it and try to send the message again.
    //  If timeout is reached in the meantime, return EAGAIN.
    while (true) {
        if (unlikely (process_commands (timeout, false) != 0))
            return -1;
        rc = xsend (msg_);
        if (rc == 0)
            break;
        if (unlikely (errno != EAGAIN))
            return -1;
        if (timeout > 0) {
            timeout = (int) (end - clock.now_ms ());
            if (timeout <= 0) {
                errno = EAGAIN;
                return -1;
            }
        }
    }
    return 0;
}