예제 #1
0
파일: evcom.c 프로젝트: bernd/node
/**
 * If using SSL do consider setting
 *   gnutls_db_set_retrieve_function (stream->session, _);
 *   gnutls_db_set_remove_function (stream->session, _);
 *   gnutls_db_set_store_function (stream->session, _);
 *   gnutls_db_set_ptr (stream->session, _);
 */
void
evcom_stream_init (evcom_stream *stream)
{
  stream->flags = 0;
  stream->errorno = 0;
  stream->recvfd = -1;
  stream->sendfd = -1;

  // reader things
  ev_init(&stream->read_watcher, stream_event);
  stream->read_watcher.data = stream;
  stream->recv_action = NULL;

  // writer things
  ev_init(&stream->write_watcher, stream_event);
  stream->write_watcher.data = stream;
  evcom_queue_init(&stream->out);
  stream->send_action = NULL;

  // stream things
  stream->server = NULL;
#if EVCOM_HAVE_GNUTLS
  stream->gnutls_errorno = 0;
  stream->session = NULL;
#endif
  ev_timer_init(&stream->timeout_watcher, on_timeout, 0., 60.);
  stream->timeout_watcher.data = stream;

  stream->on_connect = NULL;
  stream->on_timeout = NULL;
  stream->on_read = NULL;
  stream->on_drain = NULL;
  stream->on_close = NULL;
}
예제 #2
0
파일: ebb.c 프로젝트: liuliu/libebb
/**
 * Initialize an ebb_connection structure. After calling this function you
 * must setup callbacks for the different actions the server can take. See
 * server.h for which callbacks are availible. 
 * 
 * This should be called immediately after allocating space for a new
 * ebb_connection structure. Most likely, this will only be called within
 * the ebb_server->new_connection callback which you supply. 
 *
 * If using SSL do consider setting
 *   gnutls_db_set_retrieve_function (connection->session, _);
 *   gnutls_db_set_remove_function (connection->session, _);
 *   gnutls_db_set_store_function (connection->session, _);
 *   gnutls_db_set_ptr (connection->session, _);
 * To provide a better means of storing SSL session caches. libebb provides
 * only a simple default implementation. 
 *
 * @param connection the connection to initialize
 * @param timeout    the timeout in seconds
 */
void 
ebb_connection_init(ebb_connection *connection)
{
  connection->fd = -1;
  connection->server = NULL;
  connection->ip = NULL;
  connection->open = 0;

  ebb_request_parser_init( &connection->parser );
  connection->parser.data = connection;
  connection->parser.new_request = new_request_wrapper;
  
  ev_init (&connection->write_watcher, on_writable);
  connection->write_watcher.data = connection;
  connection->to_write = NULL;

  ev_init(&connection->read_watcher, on_readable);
  connection->read_watcher.data = connection;

  ev_timer_init(&connection->goodbye_watcher, on_goodbye, 0., 0.);
  connection->goodbye_watcher.data = connection;  

  ev_timer_init(&connection->timeout_watcher, on_timeout, EBB_DEFAULT_TIMEOUT, 0.);
  connection->timeout_watcher.data = connection;  

  connection->new_buf = NULL;
  connection->new_request = NULL;
  connection->on_timeout = NULL;
  connection->on_close = NULL;
  connection->data = NULL;
}
예제 #3
0
파일: stream.c 프로젝트: Andypro1/node
void uv__stream_init(uv_loop_t* loop,
                     uv_stream_t* stream,
                     uv_handle_type type) {
  uv__handle_init(loop, (uv_handle_t*)stream, type);
  loop->counters.stream_init++;

  stream->alloc_cb = NULL;
  stream->close_cb = NULL;
  stream->connection_cb = NULL;
  stream->connect_req = NULL;
  stream->accepted_fd = -1;
  stream->fd = -1;
  stream->delayed_error = 0;
  stream->blocking = 0;
  ngx_queue_init(&stream->write_queue);
  ngx_queue_init(&stream->write_completed_queue);
  stream->write_queue_size = 0;

  ev_init(&stream->read_watcher, uv__stream_io);
  stream->read_watcher.data = stream;

  ev_init(&stream->write_watcher, uv__stream_io);
  stream->write_watcher.data = stream;

  assert(ngx_queue_empty(&stream->write_queue));
  assert(ngx_queue_empty(&stream->write_completed_queue));
  assert(stream->write_queue_size == 0);
}
예제 #4
0
파일: loop.c 프로젝트: linehan/barnacle
/**
 * enter_event_loop -- begin execution of the game loop
 * 
 * After initialization and set-up, this is where the flow of control will
 * reside for the vast majority of the process lifetime. It will only be
 * exited in order to handle a termination signal, or as a response to a
 * user's "quit" command.
 */
void enter_event_loop(void)
{
        #define REPEAT_PERIOD  0.025f
        #define ANIMATE_PERIOD 3.5f
        #define FLOW_PERIOD    0.08f

        struct ev_loop *readloop = EV_DEFAULT;
        struct ev_loop *execloop = EV_DEFAULT;

        ev_io    read;    // stdin is readable
        ev_timer render;  // things which must occur once per tick ("atomic") 
        ev_timer flow;    // water and weather effects, some physics 
        ev_timer animate; // long-period animations of the map window 

        ev_io_init(&read, &iolisten_cb, 0, EV_READ);
        ev_init(&render, &render_cb);
        ev_init(&animate, &animate_cb);
        ev_init(&flow, &flow_cb);

        render.repeat  = REPEAT_PERIOD;
        animate.repeat = ANIMATE_PERIOD;
        flow.repeat    = FLOW_PERIOD;

        ev_timer_again(execloop, &render);
        ev_timer_again(execloop, &animate);
        ev_timer_again(execloop, &flow);

        loop_test(true);

        ev_io_start(readloop, &read);
        ev_run(execloop, 0);
}
예제 #5
0
파일: uv-unix.c 프로젝트: markuskopf/node
int uv_tcp_init(uv_tcp_t* tcp) {
  uv__handle_init((uv_handle_t*)tcp, UV_TCP);
  uv_counters()->tcp_init++;

  tcp->alloc_cb = NULL;
  tcp->connect_req = NULL;
  tcp->accepted_fd = -1;
  tcp->fd = -1;
  tcp->delayed_error = 0;
  ngx_queue_init(&tcp->write_queue);
  ngx_queue_init(&tcp->write_completed_queue);
  tcp->write_queue_size = 0;

  ev_init(&tcp->read_watcher, uv__tcp_io);
  tcp->read_watcher.data = tcp;

  ev_init(&tcp->write_watcher, uv__tcp_io);
  tcp->write_watcher.data = tcp;

  assert(ngx_queue_empty(&tcp->write_queue));
  assert(ngx_queue_empty(&tcp->write_completed_queue));
  assert(tcp->write_queue_size == 0);

  return 0;
}
예제 #6
0
파일: ev_iochannel.c 프로젝트: acg/evtest
int ev_iochannel_init
(
  ev_iochannel_t *self,
  struct ev_loop *loop,
  void *ctx,
  int rfd,
  char *rbuf,
  size_t rsize,
  int wfd,
  char *wbuf,
  size_t wsize
)
{
  memset( self, 0, sizeof *self );

  self->loop = loop;
  self->ctx = ctx;

  iobuf_init( &self->rio );
  iobuf_init( &self->wio );

  self->rio.fd = rfd;
  self->rio.buf = rbuf;
  self->rio.size = rsize;
  self->rio.len = 0;
  self->rio.eof = 0;
  self->rio.ctx = self;
  self->rio.on_full = on_rio_full;
  self->rio.on_nonfull = on_rio_nonfull;
  self->rio.on_eof = on_rio_eof;
  self->rio.on_data = on_rio_data;

  self->wio.fd = wfd;
  self->wio.buf = wbuf;
  self->wio.size = wsize;
  self->wio.len = 0;
  self->wio.eof = 0;
  self->wio.ctx = self;
  self->wio.on_empty = on_wio_empty;
  self->wio.on_nonempty = on_wio_nonempty;

  self->ev_rio.io = &self->rio;
  self->ev_wio.io = &self->wio;

  ev_init( (ev_io*)&self->ev_rio, ev_iobuf_reader );
  ev_io_set( (ev_io*)&self->ev_rio, rfd, EV_READ );

  ev_init( (ev_io*)&self->ev_wio, ev_iobuf_writer );
  ev_io_set( (ev_io*)&self->ev_wio, wfd, EV_WRITE );

  return 0;
}
예제 #7
0
파일: sr.c 프로젝트: ssinghi/minix
void sr_init()
{
	int i;

	for (i=0; i<FD_NR; i++)
	{
		sr_fd_table[i].srf_flags= SFF_FREE;
		ev_init(&sr_fd_table[i].srf_ioctl_ev);
		ev_init(&sr_fd_table[i].srf_read_ev);
		ev_init(&sr_fd_table[i].srf_write_ev);
	}
	repl_queue= NULL;
}
예제 #8
0
static void
echo_accept_cb(struct ev_loop *loop, ev_uinet *w, int revents)
{
	struct uinet_demo_echo *echo = w->data;
	struct uinet_socket *newso = NULL;
	struct ev_uinet_ctx *soctx = NULL;
	struct echo_connection *conn = NULL;
	int error;

	if (0 != (error = uinet_soaccept(w->so, NULL, &newso))) {
		printf("%s: Accept failed (%d)\n", echo->cfg.name, error);
	} else {
		if (echo->cfg.verbose)
			printf("%s: Accept succeeded\n", echo->cfg.name);
		
		soctx = ev_uinet_attach(newso);
		if (NULL == soctx) {
			printf("%s: Failed to alloc libev context for new connection\n",
			       echo->cfg.name);
			goto fail;
		}

		conn = malloc(sizeof(*conn));
		if (NULL == conn) {
			printf("%s: Failed to alloc new connection context\n",
			       echo->cfg.name);
			goto fail;
		}
		conn->echo = echo;
		conn->id = echo->next_id++;
		conn->verbose = echo->cfg.verbose;

		ev_init(&conn->connected_watcher, echo_connected_cb);
		ev_uinet_set(&conn->connected_watcher, soctx, EV_WRITE);
		conn->connected_watcher.data = conn;
		if (conn->verbose || (echo->cfg.copy_mode & UINET_IP_COPY_MODE_MAYBE))
			ev_uinet_start(loop, &conn->connected_watcher);

		ev_init(&conn->watcher, echo_cb);
		ev_uinet_set(&conn->watcher, soctx, EV_READ);
		conn->watcher.data = conn;
		ev_uinet_start(loop, &conn->watcher);
	}

	return;

fail:
	if (conn) free(conn);
	if (soctx) ev_uinet_detach(soctx);
	if (newso) uinet_soclose(newso);
}
예제 #9
0
static void buffered_socket_connect_cb(int revents, void *arg)
{
    struct BufferedSocket *buffsock = (struct BufferedSocket *)arg;
    int error;
    socklen_t errsz = sizeof(error);
    
    if (revents & EV_TIMEOUT) {
        _DEBUG("%s: connection timeout for \"%s:%d\" on %d\n",
            __FUNCTION__, buffsock->address, buffsock->port, buffsock->fd);
        
        buffered_socket_close(buffsock);
        return;
    }
    
    if (getsockopt(buffsock->fd, SOL_SOCKET, SO_ERROR, (void *)&error, &errsz) == -1) {
        _DEBUG("%s: getsockopt failed for \"%s:%d\" on %d\n",
               __FUNCTION__, buffsock->address, buffsock->port, buffsock->fd);
        buffered_socket_close(buffsock);
        return;
    }
    
    if (error) {
        _DEBUG("%s: \"%s\" for \"%s:%d\" on %d\n",
               __FUNCTION__, strerror(error), buffsock->address, buffsock->port, buffsock->fd);
        buffered_socket_close(buffsock);
        return;
    }
    
    _DEBUG("%s: connected to \"%s:%d\" on %d\n",
           __FUNCTION__, buffsock->address, buffsock->port, buffsock->fd);
           
    buffsock->state = BS_CONNECTED;
    
    // setup the read io watcher
    buffsock->read_ev.data = buffsock;
    ev_init(&buffsock->read_ev, buffered_socket_read_cb);
    ev_io_set(&buffsock->read_ev, buffsock->fd, EV_READ);
    
    // setup the write io watcher
    buffsock->write_ev.data = buffsock;
    ev_init(&buffsock->write_ev, buffered_socket_write_cb);
    ev_io_set(&buffsock->write_ev, buffsock->fd, EV_WRITE);
    
    // kick off the read events
    ev_io_start(buffsock->loop, &buffsock->read_ev);
    
    if (buffsock->connect_callback) {
        (*buffsock->connect_callback)(buffsock, buffsock->cbarg);
    }
}
예제 #10
0
파일: xbindjoy.c 프로젝트: saulrh/XBindJoy
// /////////////////////////////////////////////////////////////////////////////
// main loop
SCM joystick_loop(SCM jsdevice) {
	/* open the joystick device */
	/* we're only waiting on one joystick at a time for now, so we're going to use a single
	 * variable. TODO: handle multiple joysticks. */
	char* jsdevice_c = scm_to_locale_string(jsdevice);
	jsfd = open(jsdevice_c, O_RDONLY);

	// check to make sure our joystick is real
	if (jsfd < 0) {
		printf("Could not open device %s: %s\n", jsdevice_c, strerror(errno));
		return SCM_BOOL_F;
	}

	// clean up the filename string.
	free(jsdevice_c);
	
	// set up event loop
	struct ev_loop* loop = ev_default_loop(0);

	// set up and run watchers
	
	// file watcher waiting for new events from the joystick. this is where joystick data gets into
	// xbindjoy and where procedures bound to buttons are called from.
	ev_io js_watcher;
	ev_init(&js_watcher, js_callback);
	ev_io_set(&js_watcher, jsfd, EV_READ);
	ev_io_start(loop, &js_watcher);
    
	// timer watcher that pings at a regular (30hz-ish) rate. this is where procedures bound to
	// axes are called from.
	ev_timer timer_watcher;
	ev_init(&timer_watcher, timer_callback);
	ev_timer_set(&timer_watcher, 0.0, target_timing);
	ev_timer_start(loop, &timer_watcher);
	clock_gettime(CLOCK_MONOTONIC, &last_time);

	// signal watcher. safely clean up and exit on SIGINT.
	ev_signal sigint_watcher;
	ev_signal_init(&sigint_watcher, sigint_callback, SIGINT);
	ev_signal_start(loop, &sigint_watcher);

	// run the event loop and wait for events to start coming in
	ev_run(loop, 0);

	// close file descriptors.
	close(jsfd);
	
	// return success
	return SCM_BOOL_T;
}
예제 #11
0
static struct passive_connection *
create_conn(struct uinet_demo_passive *passive, struct uinet_socket *so, int server)
{
	struct passive_connection *conn = NULL;
	struct ev_uinet_ctx *soctx = NULL;
	struct uinet_sockaddr_in *sin1, *sin2;
	char buf1[32], buf2[32];

	conn = calloc(1, sizeof(*conn));
	if (NULL == conn) {
		printf("%s: Failed to alloc connection context for new connection\n",
			passive->cfg.name);
		goto fail;
	}

	soctx = ev_uinet_attach(so);
	if (NULL == soctx) {
		printf("%s: Failed to alloc libev context for new connection socket\n",
			passive->cfg.name);
		goto fail;
	}

	uinet_sogetsockaddr(so, (struct uinet_sockaddr **)&sin1);
	uinet_sogetpeeraddr(so, (struct uinet_sockaddr **)&sin2);
	snprintf(conn->label, sizeof(conn->label), "%s (%s:%u <- %s:%u)",
		 server ? "SERVER" : "CLIENT",
		 uinet_inet_ntoa(sin1->sin_addr, buf1, sizeof(buf1)), ntohs(sin1->sin_port),
		 uinet_inet_ntoa(sin2->sin_addr, buf2, sizeof(buf2)), ntohs(sin2->sin_port));
	uinet_free_sockaddr((struct uinet_sockaddr *)sin1);
	uinet_free_sockaddr((struct uinet_sockaddr *)sin2);

	conn->verbose = passive->cfg.verbose;
	conn->server = passive;

	ev_init(&conn->watcher, passive_receive_cb);
	ev_uinet_set(&conn->watcher, soctx, EV_READ);
	conn->watcher.data = conn;

	ev_init(&conn->connected_watcher, passive_connected_cb);
	ev_uinet_set(&conn->connected_watcher, soctx, EV_WRITE);
	conn->connected_watcher.data = conn;

	return (conn);

fail:
	if (conn) free(conn);
	if (soctx) ev_uinet_detach(soctx);

	return (NULL);
}
예제 #12
0
파일: main.cpp 프로젝트: Fodin/http_server
pid_t create_worker()
{
    int sp[2];
    if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sp) == -1)
    {
        printf("socketpair error, %s\n", strerror(errno));
        exit(1);
    }

    // get default loop
    struct ev_loop* loop = EV_DEFAULT;

    auto pid = fork();

    if (pid)
    {
        // parent, use socket 0
        close(sp[1]);

        // save worker socket and set free status
        workers.insert(std::pair<int, bool>(sp[0], true));

        // to detect the worker finished work with a socket
        struct ev_io* half_watcher = new ev_io;
        ev_init(half_watcher, set_worker_free);
        ev_io_set(half_watcher, sp[0], EV_READ);
        ev_io_start(loop, half_watcher);

    }
    else
    {
        // child, use socket 1
        close(sp[0]);

        // we use EVFLAG_FORKCHECK instead of
        // ev_default_fork();

        // create watcher for paired socket
        struct ev_io worker_watcher;
        ev_init(&worker_watcher, do_work);
        ev_io_set(&worker_watcher, sp[1], EV_READ);
        ev_io_start(loop, &worker_watcher);


        // wait for events, run loop in a child
        ev_loop(loop, 0);
    }

    return pid;
}
예제 #13
0
파일: input.c 프로젝트: lionzeye/multirom
static void *input_thread_work(void *cookie)
{
    ev_init();
    struct input_event ev;

    memset(mt_events, 0, sizeof(mt_events));

    key_itr = 10;
    mt_slot = 0;

    int res;
    while(input_run)
    {
        while(ev_get(&ev, 1) == 0)
        {
            switch(ev.type)
            {
                case EV_KEY:
                    handle_key_event(&ev);
                    break;
                case EV_ABS:
                    handle_abs_event(&ev);
                    break;
                case EV_SYN:
                    handle_syn_event(&ev);
                    break;
            }
        }
        usleep(10000);
    }
    ev_exit();
    pthread_exit(NULL);
    return NULL;
}
예제 #14
0
void ui_init(void)
{
    gr_init();
    ev_init();

    text_col = text_row = 0;
    text_rows = gr_fb_height() / CHAR_HEIGHT;
    if (text_rows > MAX_ROWS) text_rows = MAX_ROWS;
    text_top = 1;

    text_cols = gr_fb_width() / CHAR_WIDTH;
    if (text_cols > MAX_COLS - 1) text_cols = MAX_COLS - 1;

    int i;
    for (i = 0; BITMAPS[i].name != NULL; ++i) {
        int result = res_create_surface(BITMAPS[i].name, BITMAPS[i].surface);
        if (result < 0) {
            if (result == -2) {
                LOGI("Bitmap %s missing header\n", BITMAPS[i].name);
            } else {
                LOGE("Missing bitmap %s\n(Code %d)\n", BITMAPS[i].name, result);
            }
            *BITMAPS[i].surface = NULL;
        }
    }

    pthread_t t;
    pthread_create(&t, NULL, progress_thread, NULL);
    pthread_create(&t, NULL, input_thread, NULL);
}
예제 #15
0
파일: pyext.c 프로젝트: pzread/sdup
static PyObject* pyext_epoll_create(PyObject *self,PyObject *args){
    int ret;

    struct pyep_data *pyep;
    khiter_t hit;

    if((pyep = malloc(sizeof(*pyep))) == NULL){
        return PyErr_NoMemory();
    }

    if(ev_init(&pyep->evdata)){
        PyErr_SetString(PyExc_SystemError,"epoll initialize failed");
        goto err;
    }

    pyep->evhdr_ht = kh_init(ptr);

    hit = kh_put(ptr,pyep_ht,pyep->evdata.epfd,&ret);
    kh_value(pyep_ht,hit) = pyep;

    return PyLong_FromLong(pyep->evdata.epfd);

err:

    if(pyep != NULL){
        free(pyep);
    }

    return NULL;
}
예제 #16
0
int
msopen(dev_t dev, int flags, int mode, struct lwp *l)
{
	struct ms_softc *ms;

	ms = device_lookup_private(&ms_cd, minor(dev));
	if (ms == NULL)
		return ENXIO;

	/* This is an exclusive open device. */
	if (ms->ms_events.ev_io)
		return EBUSY;

	if (ms->ms_deviopen) {
		int err;
		err = (*ms->ms_deviopen)(ms->ms_dev, flags);
		if (err)
			return err;
	}
	ms->ms_events.ev_io = l->l_proc;
	ev_init(&ms->ms_events);	/* may cause sleep */

	ms->ms_ready = 1;		/* start accepting events */
	return 0;
}
void RecoveryUI::Init() {
    char path[255];
    ev_init(input_callback, NULL);
    pthread_create(&input_t, NULL, input_thread, NULL);


    get_item_out_t *pitem;
    pitem =get_sub_item(GET_ITEM_MAINKEY,LED_SCRIPT_GPIO);
    dump_subkey(pitem);
    if(pitem!=NULL&&pitem->str!=NULL){
        snprintf(path,sizeof(path),"/sys/class/gpio_sw/%s/data",pitem->str);
        if(!open_gpio(path))
            pthread_create(&input_t, NULL, gpio_thread, NULL);
    }

    pitem = get_sub_item(GET_ITEM_MAINKEY,LED_SCRIPT_NORMAL);
    dump_subkey(pitem);
    if(pitem!=NULL&&pitem->item.val!=0){
        LED_NORMAL = pitem->item.val;
        printf("-----LED_NORMAL=%d------\n",LED_NORMAL);
    }
    pitem = get_sub_item(GET_ITEM_MAINKEY,LED_SCRIPT_ERROR);
    dump_subkey(pitem);
    if(pitem!=NULL&&pitem->item.val!=0){
        LED_ERROR = pitem->item.val;
        printf("-----LED_ERROR=%d------\n",LED_ERROR);
    }
}
int main(int argc, char *argv[])
{
    SaAisErrorT rc = SA_AIS_OK;

    /* Connect to the SAF cluster */
    initializeAmf();

    /* Do the application specific initialization here. */
    /* Set up console redirection for demo purposes */
    (void)ev_init(argc, argv, (ClCharT*)appName.value);

    /* Block on AMF dispatch file descriptor for callbacks.
       When this function returns its time to quit. */
    dispatchLoop();
    
    /* Do the application specific finalization here. */

    /* Now finalize my connection with the SAF cluster */
    if((rc = saAmfFinalize(amfHandle)) != SA_AIS_OK)
      clprintf (CL_LOG_SEV_ERROR, "AMF finalization error[0x%X]", rc);
    else
      clprintf (CL_LOG_SEV_INFO, "AMF Finalized");   

    return 0;
}
예제 #19
0
파일: ms.c 프로젝트: lacombar/netbsd-alc
int
msopen(dev_t dev, int flags, int mode, struct lwp *l)
{
	struct ms_softc *sc;
	struct ms_port *ms;
	int unit, port;

	unit = MS_UNIT(dev);
	sc = (struct ms_softc *)getsoftc(ms_cd, unit);

	if (sc == NULL)
		return(EXDEV);

	port = MS_PORT(dev);
	ms = &sc->sc_ports[port];

	if (ms->ms_events.ev_io)
		return(EBUSY);

#if NWSMOUSE > 0
	/* don't allow opening when sending events to wsmouse */
	if (ms->ms_wsenabled)
		return EBUSY;
#endif
	/* initialize potgo bits for mouse mode */
	custom.potgo = custom.potgor | (0xf00 << (port * 4));

	ms->ms_events.ev_io = l->l_proc;
	ev_init(&ms->ms_events);	/* may cause sleep */
	ms_enable(ms);
	return(0);
}
예제 #20
0
파일: k9.c 프로젝트: hpersh/k9
void
k9_mutex_init(struct k9_mutex * const m, char *id)
{
  ev_init(m->base, K9_OBJ_MAGIC_MUTEX, id);

  m->owner = 0;
}
예제 #21
0
파일: immectl.c 프로젝트: fstd/imme
static void
init(int *argc, char ***argv)
{
	process_args(argc, argv);

	if (!ev_init())
		C("failed to initialize eval/dispatch");
	
	if (s_sercommd) {
		if (!s_dev)
			s_dev = strdup(DEF_TRG);

		if (!s_baud)
			s_baud = DEF_PORT;

		if (!sc_init_tcp(s_dev, (uint16_t)s_baud))
			C("failed to initialize sercomm (trg: '%s', port: %d)",
			    s_dev, s_baud);
	} else {
		if (!s_dev)
			s_dev = strdup(DEF_DEV);

		if (!s_baud)
			s_baud = DEF_BAUD;

		if (!sc_init(s_dev, s_baud))
			C("failed to initialize sercomm (dev: '%s', baud: %d)",
			    s_dev, s_baud);
	}

	if (*argc)
		s_stdin = false;
}
예제 #22
0
int
msopen(dev_t dev, int flags, int mode, struct lwp *l)
{
	u_char		report_ms_joy[] = { 0x14, 0x08 };
	struct ms_softc	*ms;
	int		unit;

	unit = minor(dev);
	ms   = &ms_softc[unit];

	if (unit >= NMOUSE)
		return(EXDEV);

	if (ms->ms_events.ev_io)
		return(EBUSY);

	ms->ms_events.ev_io = l->l_proc;
	ms->ms_dx = ms->ms_dy = 0;
	ms->ms_buttons = 0;
	ms->ms_bq[0].id = ms->ms_bq[1].id = 0;
	ms->ms_bq_idx = 0;
	ev_init(&ms->ms_events);	/* may cause sleep */

	/*
	 * Enable mouse reporting.
	 */
	kbd_write(report_ms_joy, sizeof(report_ms_joy));
	return(0);
}
예제 #23
0
파일: uv-unix.c 프로젝트: markuskopf/node
/* TODO: share this with windows? */
int uv_ares_init_options(ares_channel *channelptr,
                         struct ares_options *options,
                         int optmask) {
  int rc;

  /* only allow single init at a time */
  if (ares_data.channel != NULL) {
    uv_err_new_artificial(NULL, UV_EALREADY);
    return -1;
  }

  /* set our callback as an option */
  options->sock_state_cb = uv__ares_sockstate_cb;
  options->sock_state_cb_data = &ares_data;
  optmask |= ARES_OPT_SOCK_STATE_CB;

  /* We do the call to ares_init_option for caller. */
  rc = ares_init_options(channelptr, options, optmask);

  /* if success, save channel */
  if (rc == ARES_SUCCESS) {
    ares_data.channel = *channelptr;
  }

  /*
   * Initialize the timeout timer. The timer won't be started until the
   * first socket is opened.
   */
  ev_init(&ares_data.timer, uv__ares_timeout);
  ares_data.timer.repeat = 1.0;

  return rc;
}
예제 #24
0
파일: icmp.c 프로젝트: AgamAgarwal/minix
void icmp_init()
{
	int i;
	icmp_port_t *icmp_port;

	assert (BUF_S >= sizeof (nwio_ipopt_t));

	for (i= 0, icmp_port= icmp_port_table; i<ip_conf_nr; i++, icmp_port++)
	{
		icmp_port->icp_flags= ICPF_EMPTY;
		icmp_port->icp_state= ICPS_BEGIN;
		icmp_port->icp_ipport= i;
		icmp_port->icp_rate_count= 0;
		icmp_port->icp_rate_report= ICMP_MAX_RATE;
		icmp_port->icp_rate_lasttime= 0;
		ev_init(&icmp_port->icp_event);
	}

#ifndef BUF_CONSISTENCY_CHECK
	bf_logon(icmp_buffree);
#else
	bf_logon(icmp_buffree, icmp_bufcheck);
#endif

	for (i= 0, icmp_port= icmp_port_table; i<ip_conf_nr; i++, icmp_port++)
	{
		icmp_main (icmp_port);
	}
}
예제 #25
0
파일: impl.cpp 프로젝트: slon/raptor
scheduler_impl_t::wait_result_t scheduler_impl_t::wait_queue(spinlock_t* queue_lock, duration_t* timeout) {
	ev_timer timer_timeout;

	watcher_data_t watcher_data(FIBER_IMPL);
	deferred_unlock_t deferred(queue_lock);

	ev_tstamp start_wait;
	if(timeout) {
		start_wait = ev_now(ev_loop_);
		ev_init((ev_watcher*)&timer_timeout, switch_to_cb);
		ev_timer_set(&timer_timeout, timeout->count(), 0.0);
		ev_timer_start(ev_loop_, &timer_timeout);
		timer_timeout.data = &watcher_data;
	}

	FIBER_IMPL->yield(&deferred);

	unlink_activate(FIBER_IMPL);

	if(timeout) {
		*timeout -= duration_t(ev_now(ev_loop_) - start_wait);
		ev_timer_stop(ev_loop_, &timer_timeout);
	}

	if(timeout && (watcher_data.events & EV_TIMER)) {
		return TIMEDOUT;
	} else {
		return READY;
	}
}
예제 #26
0
파일: selector.c 프로젝트: emosei/chef
/* Create the libev event loop and incoming event buffer */
static VALUE NIO_Selector_allocate(VALUE klass)
{
    struct NIO_Selector *selector;
    int fds[2];

    /* Use a pipe to implement the wakeup mechanism. I know libev provides
       async watchers that implement this same behavior, but I'm getting
       segvs trying to use that between threads, despite claims of thread
       safety. Pipes are nice and safe to use between threads.

       Note that Java NIO uses this same mechanism */
    if(pipe(fds) < 0) {
        rb_sys_fail("pipe");
    }

    if(fcntl(fds[0], F_SETFL, O_NONBLOCK) < 0) {
        rb_sys_fail("fcntl");
    }

    selector = (struct NIO_Selector *)xmalloc(sizeof(struct NIO_Selector));
    selector->ev_loop = ev_loop_new(0);
    ev_init(&selector->timer, NIO_Selector_timeout_callback);

    selector->wakeup_reader = fds[0];
    selector->wakeup_writer = fds[1];

    ev_io_init(&selector->wakeup, NIO_Selector_wakeup_callback, selector->wakeup_reader, EV_READ);
    selector->wakeup.data = (void *)selector;
    ev_io_start(selector->ev_loop, &selector->wakeup);

    selector->closed = selector->selecting = selector->ready_count = 0;
    selector->ready_array = Qnil;

    return Data_Wrap_Struct(klass, NIO_Selector_mark, NIO_Selector_free, selector);
}
예제 #27
0
파일: k9.c 프로젝트: hpersh/k9
void
k9_sem_init(struct k9_sem * const s, char *id, int cnt)
{
  ev_init(s->base, K9_OBJ_MAGIC_SEM, id);

  s->cnt = cnt;
}
예제 #28
0
static int lcb_io_update_event(struct lcb_io_opt_st *iops,
                               lcb_socket_t sock,
                               void *event,
                               short flags,
                               void *cb_data,
                               void (*handler)(lcb_socket_t sock,
                                               short which,
                                               void *cb_data))
{
    struct libev_cookie *io_cookie = iops->v.v2.cookie;
    struct libev_event *evt = event;
    int events = EV_NONE;

    if (flags & LCB_READ_EVENT) {
        events |= EV_READ;
    }
    if (flags & LCB_WRITE_EVENT) {
        events |= EV_WRITE;
    }

    if (events == evt->ev.io.events && handler == evt->handler) {
        /* no change! */
        return 0;
    }

    ev_io_stop(io_cookie->loop, &evt->ev.io);
    evt->data = cb_data;
    evt->handler = handler;
    ev_init(&evt->ev.io, handler_thunk);
    ev_io_set(&evt->ev.io, sock, events);
    ev_io_stop(io_cookie->loop, &evt->ev.io);
    ev_io_start(io_cookie->loop, &evt->ev.io);

    return 0;
}
예제 #29
0
파일: miniui.c 프로젝트: LuckJC/pro-mk
void ui_init(void)
{
    char resPath[256];

    gr_init();
    ev_init();

    text_col = text_row = 0;
    // text_rows = CUST_LCD_AVAIL_HEIGHT / CHAR_HEIGHT;
    // text_rows = CUST_LCD_AVAIL_HEIGHT % CHAR_HEIGHT ? text_rows - 1 : text_rows;
    text_rows = gr_fb_height() / CHAR_HEIGHT;
    text_rows = gr_fb_height()  % CHAR_HEIGHT ? text_rows - 1 : text_rows;


    if (text_rows > MAX_ROWS) text_rows = MAX_ROWS;
    text_top = 1;

    // text_cols = CUST_LCD_AVAIL_WIDTH / CHAR_WIDTH;
    text_cols = gr_fb_width() / CHAR_WIDTH;

    if (text_cols > MAX_COLS - 1) text_cols = MAX_COLS - 1;

    LOGD(TAG "CUST_LCD_AVAIL_HEIGHT=%d, CUST_LCD_AVAIL_WIDTH=%d\n",
        gr_fb_height(), gr_fb_width());
    LOGD(TAG "CUST_KEY_CONFIRM=%d, CUST_KEY_BACK=%d\n", 
        CUST_KEY_CONFIRM, CUST_KEY_BACK);
    LOGD(TAG "TEXT_ROWS=%d, TEXT_COLS=%d\n", text_rows, text_cols);

    pthread_t t;
    pthread_create(&t, NULL, input_thread, NULL);
}
예제 #30
0
struct BufferedSocket *new_buffered_socket(struct ev_loop *loop, const char *address, int port,
        void (*connect_callback)(struct BufferedSocket *buffsock, void *arg),
        void (*close_callback)(struct BufferedSocket *buffsock, void *arg),
        void (*read_callback)(struct BufferedSocket *buffsock, struct Buffer *buf, void *arg),
        void (*write_callback)(struct BufferedSocket *buffsock, void *arg),
        void (*error_callback)(struct BufferedSocket *buffsock, void *arg),
        void *cbarg)
{
    struct BufferedSocket *buffsock;
    
    buffsock = malloc(sizeof(struct BufferedSocket));
    buffsock->address = strdup(address);
    buffsock->port = port;
    buffsock->read_buf = new_buffer(1024 * 16, 1024 * 16);
    buffsock->write_buf = new_buffer(1024 * 16, 1024 * 16);
    buffsock->fd = -1;
    buffsock->state = BS_INIT;
    buffsock->connect_callback = connect_callback;
    buffsock->close_callback = close_callback;
    buffsock->read_callback = read_callback;
    buffsock->write_callback = write_callback;
    buffsock->error_callback = error_callback;
    buffsock->cbarg = cbarg;
    buffsock->read_bytes_n = 0;
    buffsock->read_bytes_callback = NULL;
    buffsock->read_bytes_arg = NULL;
    buffsock->loop = loop;
    
    ev_init(&buffsock->read_bytes_timer_ev, buffered_socket_read_bytes_cb);
    buffsock->read_bytes_timer_ev.data = buffsock;
    ev_timer_set(&buffsock->read_bytes_timer_ev, 0., 0.);
    
    return buffsock;
}