예제 #1
0
파일: imocap.cpp 프로젝트: apetrone/gemini
	MocapDevice* device_create()
	{
		sensor_thread_handle = nullptr;
		data_socket = -1;

		data_socket = net_socket_open(net_socket_type::UDP);
		assert(net_socket_is_valid(data_socket));

		net_address addr;
		net_address_init(&addr);
		net_address_set(&addr, "0.0.0.0", 27015);

		int32_t bind_result = net_socket_bind(data_socket, &addr);
		assert(bind_result == 0);

		net_listen_thread = true;
		sensor_thread_handle = platform::thread_create(sensor_thread, &data_socket);

		assert(_current_device == nullptr);

		MocapDevice* device = MEMORY2_NEW((*_allocator), MocapDevice);
		_current_device = device;

		return device;
	} // device_create
예제 #2
0
파일: net.c 프로젝트: wkxboot/parking_lock
void net_poll_status_procedure()
{
  if(net_link_status==NETDEV_LINKED)
  {
  if(dhcp_new_ip_flag==0)//dhcp 无效
  {
    net_ip_flag=0;//ip无效
    if(net_socket_status!=SOCKET_CLOSED)
    {
     net_socket_close();//关闭net app 重新开始
    }
  }
  else
  { 
   if(dhcp_new_ip_flag!=net_ip_flag)//ip需要更新
   {   
    net_socket_param_refresh();//更新ip等资源
    net_ip_flag=dhcp_new_ip_flag;//net ip    
   if(net_socket_status!=SOCKET_CLOSED)
   {
    net_socket_close();//关闭net app 重新开始
    }
   }
  }
  /***********************/
  if(net_socket_status==SOCKET_UDP)//-------------------
  {
    //todo

  }
  if(net_socket_status==SOCKET_INIT)//tcp init
  {
   net_socket_connect(); 
  }

  if(net_socket_status==SOCKET_CLOSED || net_socket_status==SOCKET_CLOSE_WAIT)//如果netsocket 是关闭的或者半关闭重新初始化连接
  {
   if(dhcp_new_ip_flag==net_ip_flag && net_ip_flag!=0  )//如果ip有效
   {
    net_socket_init();     
    net_socket_open();//打开当前net socket 
   }
  } 
  if(net_ip_comflict)
  {
     net_ip_comflict=FALSE;//使IP冲突无效
     net_ip_flag=0;//使ip无效  
     hal_net_device_software_reset();//如果ip冲突 就重启设备
  }
 }
 else//断开link 就关闭net socket
 {   
   if(net_socket_status!=SOCKET_CLOSED)//-----------------
   {
   net_ip_comflict=FALSE;//使IP冲突无效
   net_ip_flag=0;//使ip无效  
   net_socket_close();//关闭当前net socket  
   }
 }
}