Example #1
0
File: tcp.c Project: yihuang/luv
static int luv_new_tcp(lua_State* L) {
  uv_tcp_t* handle = (uv_tcp_t*)luv_newuserdata(L, sizeof(*handle));
  int ret;
  if (lua_isnoneornil(L, 1)) {
    ret = uv_tcp_init(luv_loop(L), handle);
  }
  else {
    ret = uv_tcp_init_ex(luv_loop(L), handle, lua_tointeger(L, 1));
  }
  if (ret < 0) {
    lua_pop(L, 1);
    return luv_error(L, ret);
  }
  handle->data = luv_setup_handle(L);
  return 1;
}
static void on_connection(uv_stream_t* server, int status) {
  uv_tcp_t* handle;
  int r;

  ASSERT(status == 0);

  handle = malloc(sizeof(*handle));
  ASSERT(handle != NULL);

  r = uv_tcp_init_ex(server->loop, handle, AF_INET);
  ASSERT(r == 0);

  r = uv_accept(server, (uv_stream_t*)handle);
  ASSERT(r == UV_EBUSY);

  uv_close((uv_handle_t*) server, NULL);
  uv_close((uv_handle_t*) handle, (uv_close_cb)free);
}
Example #3
0
int uv_tcp_init(uv_loop_t* loop, uv_tcp_t* handle) {
  return uv_tcp_init_ex(loop, handle, AF_UNSPEC);
}
Example #4
0
int uv_tcp_init(uv_loop_t* loop, uv_tcp_t* tcp) {
  return uv_tcp_init_ex(loop, tcp, AF_UNSPEC);
}
Example #5
0
File: tcp.cpp Project: Xsoda/uvplus
int uvplus_tcp::init_ex(uvplus_loop &loop, int flags) {
  auto tcp = (uv_tcp_t *)context_ptr();
  return uv_tcp_init_ex(loop.context_ptr(), tcp, flags);
}