Esempio n. 1
0
File: main.c Progetto: 0x1abin/FMCU
int main(int argc, char **argv)
{
    printf("libuev..\r\n");
    
    xloop = uv_default_loop();
//    uv_loop_init(&xloop);

	uv_watch_init(xloop, &watch1);
	uv_watch_start(&watch1, watch1_func, get_state, 5010);
    
	uv_timer_init(xloop, &timer1);
	uv_timer_start(&timer1, time1_func, 1000, 1000);
	
	uv_timer_init(xloop, &timer2);
	uv_timer_start(&timer2, time2_func, 5011, 0);
	
//	uv_timer_init(xloop, &timer3);
// 	uv_timer_start(&timer3, time3_func, 0, 5000);
	
// 	uv_timer_init(xloop, &timer4);
// 	uv_timer_start(&timer4, time4_func, 5000, 0);

    uv_run(xloop);

}
Esempio n. 2
0
static void poll_cb(uv_fs_poll_t* handle,
                    int status,
                    const uv_stat_t* prev,
                    const uv_stat_t* curr) {
  uv_stat_t zero_statbuf;

  memset(&zero_statbuf, 0, sizeof(zero_statbuf));

  ASSERT(handle == &poll_handle);
  ASSERT(1 == uv_is_active((uv_handle_t*) handle));
  ASSERT(prev != NULL);
  ASSERT(curr != NULL);

  switch (poll_cb_called++) {
  case 0:
    ASSERT(status == UV_ENOENT);
    ASSERT(0 == memcmp(prev, &zero_statbuf, sizeof(zero_statbuf)));
    ASSERT(0 == memcmp(curr, &zero_statbuf, sizeof(zero_statbuf)));
    touch_file(FIXTURE);
    break;

  case 1:
    ASSERT(status == 0);
    ASSERT(0 == memcmp(prev, &zero_statbuf, sizeof(zero_statbuf)));
    ASSERT(0 != memcmp(curr, &zero_statbuf, sizeof(zero_statbuf)));
    ASSERT(0 == uv_timer_start(&timer_handle, timer_cb, 20, 0));
    break;

  case 2:
    ASSERT(status == 0);
    ASSERT(0 != memcmp(prev, &zero_statbuf, sizeof(zero_statbuf)));
    ASSERT(0 != memcmp(curr, &zero_statbuf, sizeof(zero_statbuf)));
    ASSERT(0 == uv_timer_start(&timer_handle, timer_cb, 200, 0));
    break;

  case 3:
    ASSERT(status == 0);
    ASSERT(0 != memcmp(prev, &zero_statbuf, sizeof(zero_statbuf)));
    ASSERT(0 != memcmp(curr, &zero_statbuf, sizeof(zero_statbuf)));
    remove(FIXTURE);
    break;

  case 4:
    ASSERT(status == UV_ENOENT);
    ASSERT(0 != memcmp(prev, &zero_statbuf, sizeof(zero_statbuf)));
    ASSERT(0 == memcmp(curr, &zero_statbuf, sizeof(zero_statbuf)));
    uv_close((uv_handle_t*)handle, close_cb);
    break;

  default:
    ASSERT(0);
  }
}
Esempio n. 3
0
void Initialize()
{
	uv_timer_init(uv_default_loop(), &G_ThreadTimer);

	G_pGateCore = new class CGateCore();

	if (G_pGateCore->bInit() == false) {
		std::fprintf(stderr, "ERROR: Init fail!\n");
		std::exit(1);
		return;	
	}

	G_pListenSock = new class XSocket(300);
	if (!G_pListenSock->bListen(G_pGateCore->m_cGateServerAddr, G_pGateCore->m_iGateServerPort, WM_USER_ACCEPT))
	{
		OnDestroy();
		std::exit(1);
		return;
	}

	// 서버 검사용 타이머 시작 
	uv_timer_init(uv_default_loop(), &G_mmTimer0);
	uv_timer_start(&G_mmTimer0, &_TimerFunc, 0, 3000);
	PutLogList("(!) Gate Server Listening...");
}
Esempio n. 4
0
static void timer_prepare_cb(uv_prepare_t *handle)
{
  TimerData *data = handle->data;
  assert(data->ms > 0);
  uv_timer_start(data->timer, timer_cb, (uint32_t)data->ms, 0);
  uv_prepare_stop(handle);
}
Esempio n. 5
0
static int event_sched(lua_State *L, unsigned timeout, unsigned repeat)
{
    uv_timer_t *timer = malloc(sizeof(*timer));
    if (!timer) {
        format_error(L, "out of memory");
        lua_error(L);
    }

    /* Start timer with the reference */
    uv_loop_t *loop = uv_default_loop();
    uv_timer_init(loop, timer);
    int ret = uv_timer_start(timer, event_callback, timeout, repeat);
    if (ret != 0) {
        free(timer);
        format_error(L, "couldn't start the event");
        lua_error(L);
    }

    /* Save callback and timer in registry */
    lua_newtable(L);
    lua_pushvalue(L, 2);
    lua_rawseti(L, -2, 1);
    lua_pushlightuserdata(L, timer);
    lua_rawseti(L, -2, 2);
    int ref = luaL_ref(L, LUA_REGISTRYINDEX);

    /* Save reference to the timer */
    timer->data = (void *) (intptr_t)ref;
    lua_pushinteger(L, ref);
    return 1;
}
Esempio n. 6
0
void
reset_timer(struct remote_context *remote) {
    if (remote->timer != NULL) {
        remote->timer->data = remote;
        uv_timer_start(remote->timer, remote_timer_expire, remote->idle_timeout, 0);
    }
}
Esempio n. 7
0
int loq_timer(lua_State *L)
{
  int time = luaL_checkinteger(L, 1);
  int r = 0;
  
  uv_loop_t* loop = uv_default_loop();
  
  // Create a timer callback and fill it up with what we need.
  loq_timer_t *timer = (loq_timer_t*)loq_malloc(sizeof(loq_timer_t));
  r = uv_timer_init(loop, &timer->handle);
  if(r) {
    loq_free(timer);
    uv_err_t err = loop->last_err;
    return luaL_error(L, uv_strerror(err));
  }
  timer->L = L;
  timer->handle.data = timer;
  
  // Stash the callback in lua.
  lua_pushlightuserdata(L, timer);
  lua_pushvalue(L, 2);
  lua_rawset(L, LUA_REGISTRYINDEX);
  
  // Tell uv we want the timer to start
  r = uv_timer_start(&timer->handle, timer_cb, time, 0);
  if(r) {
    uv_close((uv_handle_t*)&timer->handle, timer_close_cb);
    uv_err_t err = loop->last_err;
    return luaL_error(L, uv_strerror(err));
  }
  
  return 0;
}
Esempio n. 8
0
static void eof_timer_start(uv_pipe_t* pipe) {
  assert(pipe->flags & UV_HANDLE_CONNECTION);

  if (pipe->eof_timer != NULL) {
    uv_timer_start(pipe->eof_timer, eof_timer_cb, eof_timeout, 0);
  }
}
Esempio n. 9
0
File: temp.c Progetto: josl/urbit
/* u3_temp_io_poll(): update temp IO state.
*/
void
u3_temp_io_poll(void)
{
  u3_temp* teh_u = &u3_Host.teh_u;
  u3_noun  wen   = u3v_keep(u3nt(u3_blip, c3__temp, u3_nul));

  if ( (u3_nul != wen) &&
       (c3y == u3du(wen)) &&
       (c3y == u3ud(u3t(wen))) )
  {
    c3_d gap_d = u3_time_gap_ms(u3k(u3A->now), u3k(u3t(wen)));

#if 0
    fprintf(stderr, "gap_d %llu, plus %llu\r\n", 
        gap_d, gap_d + (c3_d)teh_u->run_w);
#endif
    gap_d += teh_u->run_w;

    if ( c3y == teh_u->alm ) {
      uv_timer_stop(&teh_u->tim_u);
    }
    else teh_u->alm = c3y;

    uv_timer_start(&teh_u->tim_u, _temp_time_cb, gap_d, 0);
  }
  else {
    if ( c3y == teh_u->alm ) {
      uv_timer_stop(&teh_u->tim_u);
    }
    teh_u->alm = c3n;
  }
  u3z(wen);
}
Esempio n. 10
0
static void connect_timer_reset_(wsn_client_ctx_t *client)
{
  uv_timer_start(&client->timer_handle,
                 on_connect_timer_expire_,
                 (unsigned int)client->connect_timeout,
                 0);
}
Esempio n. 11
0
void TCPClient::AfterConnect(uv_connect_t* handle, int status)
{
    TcpClientCtx* theclass = (TcpClientCtx*)handle->handle->data;
    TCPClient* parent = (TCPClient*)theclass->parent_server;
    if (status) {
        parent->connectstatus_ = CONNECT_ERROR;
        parent->errmsg_ = GetUVError(status);
        LOG(ERROR)<<"client(" << parent << ") connect error:" << parent->errmsg_;
        fprintf(stdout, "connect error:%s\n", parent->errmsg_.c_str());
        if (parent->isreconnecting_) {//reconnect failure, restart timer to trigger reconnect.
            uv_timer_stop(&parent->reconnect_timer_);
            parent->repeat_time_ *= 2;
            uv_timer_start(&parent->reconnect_timer_, TCPClient::ReconnectTimer, parent->repeat_time_, parent->repeat_time_);
        }
        return;
    }

    int iret = uv_read_start(handle->handle, AllocBufferForRecv, AfterRecv);
    if (iret) {
        parent->errmsg_ = GetUVError(status);
        LOG(ERROR)<<"client(" << parent << ") uv_read_start error:" << parent->errmsg_;
        fprintf(stdout, "uv_read_start error:%s\n", parent->errmsg_.c_str());
        parent->connectstatus_ = CONNECT_ERROR;
    } else {
        parent->connectstatus_ = CONNECT_FINISH;
        LOG(INFO) << "client(" << parent << ")run";
    }
    if (parent->isreconnecting_) {
        fprintf(stdout, "reconnect succeed\n");
        parent->StopReconnect();//reconnect succeed.
        if (parent->reconnectcb_) {
            parent->reconnectcb_(NET_EVENT_TYPE_RECONNECT, parent->reconnect_userdata_);
        }
    }
}
Esempio n. 12
0
void main(int argc, char** argv)
{
    loop = uv_default_loop();
    if(argc > 1)
    {
        bench = atoi(argv[1]);
    }
    if(argc > 2)
    {
        interval = atoi(argv[2]); // Seconds
    }

    // init log client
    melo_log_init(&mlog, loop, "127.0.0.1", 8004, "xlog-test");

    // some small tests
    test_shorten_path();
    test_serialize_log();

    // start a timer
    uv_timer_t timer;

    uv_timer_init(loop, &timer);
    uv_timer_start(&timer, on_timer, 0, interval/*seconds*/ * 1000);

    uv_run(loop, UV_RUN_DEFAULT);
}
Esempio n. 13
0
static void fs_event_unlink_files_in_subdir(uv_timer_t* handle) {
  int r;
  int i;

  /* NOTE: handle might be NULL if invoked not as timer callback */
  if (handle == NULL) {
    /* Unlink all files */
    for (i = 0; i < 16; i++) {
      r = remove(fs_event_get_filename_in_subdir(i));
      if (handle != NULL)
        ASSERT(r == 0);
    }
  } else {
    /* Make sure we're not attempting to remove files we do not intend */
    ASSERT(fs_event_removed < fs_event_file_count);

    /* Remove the file */
    ASSERT(0 == remove(fs_event_get_filename_in_subdir(fs_event_removed)));

    if (++fs_event_removed < fs_event_file_count) {
      /* Remove another file on a different event loop tick.  We do it this way
       * to avoid fs events coalescing into one fs event. */
      ASSERT(0 == uv_timer_start(&timer, fs_event_unlink_files_in_subdir, 1, 0));
    }
  }
}
Esempio n. 14
0
void curl_perform(uv_poll_t *si, int status, int events) {
	int running_handles;
	int flags = 0;

	Socket_Info *s = (Socket_Info *) si->data;
	Mathilda *m = (Mathilda *) s->m;

	uv_timer_stop(&m->timeout);

	if(status < 0) {
		flags = CURL_CSELECT_ERR;
	}

	if(!status && events & UV_READABLE) {
		flags |= CURL_CSELECT_IN;
	}

	if(!status && events & UV_WRITABLE) {
		flags |= CURL_CSELECT_OUT;
	}

	curl_multi_socket_action(m->multi_handle, s->sock_fd, flags, &running_handles);
	check_multi_info(m);

	uv_timer_start(&m->timeout, (uv_timer_cb) on_timeout, 0, 0);
}
Esempio n. 15
0
File: unix.c Progetto: esaul/urbit
/* u2_unix_io_poll(): update unix IO state.
*/
void
u2_unix_io_poll(void)
{
  u2_unix* unx_u = &u2_Host.unx_u;
  u2_noun  wen = u2_reck_keep(u2A, u2nt(u2_blip, c3__clay, u2_nul));

  if ( (u2_nul != wen) &&
       (u2_yes == u2du(wen)) &&
       (u2_yes == u2ud(u2t(wen))) )
  {
    c3_d gap_d = u2_time_gap_ms(u2k(u2A->now), u2k(u2t(wen)));

    if ( u2_yes == unx_u->alm ) {
      uv_timer_stop(&unx_u->tim_u);
    }
    else unx_u->alm = u2_yes;

    if ( gap_d < 1000 ) { gap_d = 1000; }   // band-aid on an unknown clay timer bug
    uv_timer_start(&unx_u->tim_u, _unix_time_cb, gap_d, 0);
  }
  else {
    if ( u2_yes == unx_u->alm ) {
      uv_timer_stop(&unx_u->tim_u);
    }
    unx_u->alm = u2_no;
  }
  u2z(wen);
}
Esempio n. 16
0
void start_timeout(CURLM *multi, long timeout_ms, void *userp)
{
  if (timeout_ms <= 0)
    timeout_ms = 1; /* 0 means directly call socket_action, but we'll do it in
                       a bit */
  uv_timer_start(&timeout, on_timeout, timeout_ms, 0);
}
Esempio n. 17
0
void http_request_cache_configure_listener(uv_loop_t* loop, uv_async_t* handle)
{
    uv_timer_t* cache_invalidation_timer = malloc(sizeof(uv_timer_t));
    uv_timer_init(loop, cache_invalidation_timer);
    uv_timer_start(cache_invalidation_timer, http_request_cache_timer, 500, 500);
    uv_unref((uv_handle_t*) cache_invalidation_timer);
}
Esempio n. 18
0
static void tcp_recv(uv_stream_t *handle, ssize_t nread, const uv_buf_t *buf)
{
	uv_loop_t *loop = handle->loop;
	struct session *s = handle->data;
	struct worker_ctx *worker = loop->data;
	/* TCP pipelining is rather complicated and requires cooperation from the worker
	 * so the whole message reassembly and demuxing logic is inside worker */
	int ret = 0;
	if (s->has_tls) {
		ret = tls_process(worker, handle, (const uint8_t *)buf->base, nread);
	} else {
		ret = worker_process_tcp(worker, handle, (const uint8_t *)buf->base, nread);
	}
	if (ret < 0) {
		worker_end_tcp(worker, (uv_handle_t *)handle);
		/* Exceeded per-connection quota for outstanding requests
		 * stop reading from stream and close after last message is processed. */
		if (!s->outgoing && !uv_is_closing((uv_handle_t *)&s->timeout)) {
			uv_timer_stop(&s->timeout);
			if (s->tasks.len == 0) {
				uv_close((uv_handle_t *)&s->timeout, tcp_timeout);
			} else { /* If there are tasks running, defer until they finish. */
				uv_timer_start(&s->timeout, tcp_timeout_trigger, 1, KR_CONN_RTT_MAX/2);
			}
		}
	/* Connection spawned more than one request, reset its deadline for next query. */
	} else if (ret > 0 && !s->outgoing) {
		uv_timer_again(&s->timeout);
	}
	mp_flush(worker->pkt_pool.ctx);
}
Esempio n. 19
0
/// Terminates a job. This is a non-blocking operation, but if the job exists
/// it's guaranteed to succeed(SIGKILL will eventually be sent)
///
/// @param job The Job instance
void job_stop(Job *job)
{
  if (job->stopped_time) {
    return;
  }

  job->stopped_time = os_hrtime();
  if (job->opts.pty) {
    // close all streams for pty jobs to send SIGHUP to the process
    job_close_streams(job);
    pty_process_close_master(job);
  } else {
    // Close the job's stdin. If the job doesn't close its own stdout/stderr,
    // they will be closed when the job exits(possibly due to being terminated
    // after a timeout)
    close_job_in(job);
  }

  if (!stop_requests++) {
    // When there's at least one stop request pending, start a timer that
    // will periodically check if a signal should be send to a to the job
    DLOG("Starting job kill timer");
    uv_timer_start(&job_stop_timer, job_stop_timer_cb, 100, 100);
  }
}
Esempio n. 20
0
static void _tcp_accept(uv_stream_t *master, int status, bool tls)
{
	if (status != 0) {
		return;
	}
	uv_stream_t *client = handle_alloc(master->loop);
	if (!client) {
		return;
	}
	memset(client, 0, sizeof(*client));
	io_create(master->loop, (uv_handle_t *)client, SOCK_STREAM);
	if (uv_accept(master, client) != 0) {
		uv_close((uv_handle_t *)client, io_free);
		return;
	}

	/* Set deadlines for TCP connection and start reading.
	 * It will re-check every half of a request time limit if the connection
	 * is idle and should be terminated, this is an educated guess. */
	struct session *session = client->data;
	session->has_tls = tls;
	if (tls && !session->tls_ctx) {
		session->tls_ctx = tls_new(master->loop->data);
	}
	uv_timer_t *timer = &session->timeout;
	uv_timer_init(master->loop, timer);
	timer->data = client;
	uv_timer_start(timer, tcp_timeout_trigger, KR_CONN_RTT_MAX/2, KR_CONN_RTT_MAX/2);
	io_start_read((uv_handle_t *)client);
}
void SyncWorker::start()
{
    uv_timer_start( &this->timer_ , 
                    SyncWorker::uv_process_timer_tick_callback , 
                    0 , 
                    this->loop_time_ );
}
Esempio n. 22
0
static void(timer_start)(void* t, unsigned int ms)
{
   struct LwqqAsyncTimer_* t_ = (struct LwqqAsyncTimer_*)t;
   t_->h.data = t;
   uv_timer_init(loop, &t_->h);
   uv_timer_start(&t_->h, timer_cb_wrap, ms / 10, ms / 10);
}
Esempio n. 23
0
static void connect_cb(uv_connect_t* req, int status) {
  ASSERT(0 == status);
  ASSERT(0 == uv_timer_start(&timer_handle, timer_cb, 50, 0));
  ASSERT(0 == uv_read_start((uv_stream_t*) &tcp_handle,
                            (uv_alloc_cb) fail_cb,
                            (uv_read_cb) fail_cb));
}
Esempio n. 24
0
Network::Network(const Options *options) :
    m_options(options),
    m_donate(nullptr)
{
    srand(time(0) ^ (uintptr_t) this);

    Workers::setListener(this);

    const std::vector<Url*> &pools = options->pools();

#ifndef XMRIG_NO_TLS
    ssl_init();
#endif

    if (pools.size() > 1) {
        m_strategy = new FailoverStrategy(pools, Platform::userAgent(), this);
    }
    else {
        m_strategy = new SinglePoolStrategy(pools.front(), Platform::userAgent(), this);
    }

    if (m_options->donateLevel() > 0) {
        m_donate = new DonateStrategy(Platform::userAgent(), this);
    }

    m_timer.data = this;
    uv_timer_init(uv_default_loop(), &m_timer);

    uv_timer_start(&m_timer, Network::onTick, kTickInterval, kTickInterval);
}
Esempio n. 25
0
void loop_poll_events(Loop *loop, int ms)
{
  if (loop->recursive++) {
    abort();  // Should not re-enter uv_run
  }

  uv_run_mode mode = UV_RUN_ONCE;

  if (ms > 0) {
    // Use a repeating timeout of ms milliseconds to make sure
    // we do not block indefinitely for I/O.
    uv_timer_start(&loop->poll_timer, timer_cb, (uint64_t)ms, (uint64_t)ms);
  } else if (ms == 0) {
    // For ms == 0, we need to do a non-blocking event poll by
    // setting the run mode to UV_RUN_NOWAIT.
    mode = UV_RUN_NOWAIT;
  }

  uv_run(&loop->uv, mode);

  if (ms > 0) {
    uv_timer_stop(&loop->poll_timer);
  }

  loop->recursive--;  // Can re-enter uv_run now
  multiqueue_process_events(loop->fast_events);
}
Esempio n. 26
0
/**
 * When receive connect_frontend command from frontend, change client status that
 * the account and password are stored to property, and start timer.
 * @param client Frontend that passed this request.
 * @param param Parameter contain account, password, frontend type.
 */
void FrontendConnector::recv_connect_frontend(uv_pipe_t& client, picojson::object& param) {
  const std::string& type = param.at("type").get<std::string>();
  const std::string& account  = param.at("account").get<std::string>();
  const std::string& password = param.at("password").get<std::string>();
  FrontendProperty& property = properties.at(&client);

  assert(property.status == PipeStatus::SETUP);
  assert(!account.empty() && !password.empty());

  if (type == "gui") {
    property.type = FrontendType::GUI;

  } else if (type == "cui") {
    property.type = FrontendType::CUI;

  } else {
    /// @todo error
    assert(false);
  }

  property.account  = account;
  property.password = password;

  if (!connect_timer_enable) {
    uv_timer_start(&connect_timer, on_connect_timer, 0, 1000);
    connect_timer_enable = true;
  }
}
Esempio n. 27
0
void HTTPRequest::retryHTTPRequest(std::unique_ptr<Response> &&res, uint64_t timeout) {
    assert(uv_thread_self() == thread_id);
    assert(!backoff_timer);
    backoff_timer = new uv_timer_t();
    uv_timer_init(loop, backoff_timer);
    backoff_timer->data = new RetryBaton(this, std::move(res));

#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10
    uv_timer_start(backoff_timer, [](uv_timer_t *timer, int) {
#else
    uv_timer_start(backoff_timer, [](uv_timer_t *timer) {
#endif
        std::unique_ptr<RetryBaton> pair { static_cast<RetryBaton *>(timer->data) };
        pair->first->startHTTPRequest(std::move(pair->second));
        pair->first->backoff_timer = nullptr;
        uv_timer_stop(timer);
        uv_close((uv_handle_t *)timer, [](uv_handle_t *handle) { delete (uv_timer_t *)handle; });
    }, timeout, 0);
}

void HTTPRequest::removeHTTPBaton() {
    assert(uv_thread_self() == thread_id);
    if (http_baton) {
        http_baton->request = nullptr;
        HTTPRequestBaton::stop(http_baton);
        http_baton.reset();
    }
}
Esempio n. 28
0
grpc_error *grpc_pollset_work(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
                              grpc_pollset_worker **worker_hdl,
                              gpr_timespec now, gpr_timespec deadline) {
  uint64_t timeout;
  GRPC_UV_ASSERT_SAME_THREAD();
  gpr_mu_unlock(&grpc_polling_mu);
  if (grpc_pollset_work_run_loop) {
    if (gpr_time_cmp(deadline, now) >= 0) {
      timeout = (uint64_t)gpr_time_to_millis(gpr_time_sub(deadline, now));
    } else {
      timeout = 0;
    }
    /* We special-case timeout=0 so that we don't bother with the timer when
       the loop won't block anyway */
    if (timeout > 0) {
      uv_timer_start(&pollset->timer, timer_run_cb, timeout, 0);
      /* Run until there is some I/O activity or the timer triggers. It doesn't
         matter which happens */
      uv_run(uv_default_loop(), UV_RUN_ONCE);
      uv_timer_stop(&pollset->timer);
    } else {
      uv_run(uv_default_loop(), UV_RUN_NOWAIT);
    }
  }
  if (!grpc_closure_list_empty(exec_ctx->closure_list)) {
    grpc_exec_ctx_flush(exec_ctx);
  }
  gpr_mu_lock(&grpc_polling_mu);
  return GRPC_ERROR_NONE;
}
Esempio n. 29
0
/* u2_unix_io_poll(): update unix IO state.
*/
void
u2_unix_io_poll(void)
{
  u2_unix* unx_u = &u2_Host.unx_u;
  u2_noun  wen = u2_reck_keep(u2A, u2nt(c3__gold, c3__clay, u2_nul));
 
  if ( (u2_nul != wen) && 
       (u2_yes == u2du(wen)) &&
       (u2_yes == u2ud(u2t(wen))) )
  {
    c3_d gap_d = u2_time_gap_ms(u2k(u2A->now), u2k(u2t(wen)));

    if ( u2_yes == unx_u->alm ) {
      uv_timer_stop(&unx_u->tim_u);
    }
    else unx_u->alm = u2_yes;

    uv_timer_start(&unx_u->tim_u, _unix_time_cb, gap_d, 0);
  }
  else {
    if ( u2_yes == unx_u->alm ) {
      uv_timer_stop(&unx_u->tim_u);
    }
    unx_u->alm = u2_no;
  }
  u2z(wen);
}
Esempio n. 30
0
int main(int argc,char** argv) {
    loop = uv_default_loop();
    if (argc != 2) {
        printf("./tdial localaddr");
        return -1;
    }

    msg_len = htonl(132);
    //uv_ip4_addr("192.168.8.90", 0, &addr);
    if (UV_EINVAL == uv_ip4_addr(argv[1], 0, &addr)) {
        printf("bind error: %s\n",argv[1]);
        return -1;
    }
    addr_str = argv[1];
    uv_ip4_addr("192.168.3.99", 8999, &addr1);
    size_t i;
    for(i=0;i<CONN_NUM;i++) {
        uv_tcp_init(loop, &c[i].ts);
        c[i].ts.data = (void*)i;
        c[i].status = STATUS_NOT_CONNECT;
    }
    uv_timer_t timer_req;
    timer_req.data = (void*)0;

    uv_timer_init(loop, &timer_req);
    uv_timer_start(&timer_req, timer_cb, CONNECT_INTERVAL, CONNECT_INTERVAL);
    
    return uv_run(loop, UV_RUN_DEFAULT);
}