Пример #1
0
MySQL* ConnectionPool::newConnection() {
	int count = pool.size();
	if (count > oldCount) {
		int a = 1;
	}
	oldCount = count;
	//printf("\nHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH\n");
	//printf("%d\n", count);
	//printf("HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH\n\n");
	if (count == 0) {
		MySQL *query = init_connect();
		Connection *conn = new Connection();
		conn->enabled = true;
		conn->query = query;
		pool.insert(pool.end(), conn);
		int count = pool.size();
		return query;
	}
	else {
		for (int i = 0; i < count; i++) {
			if (pool[i]->enabled == false) {
				pool[i]->enabled = true;
				return pool[i]->query;
			}
		}
		MySQL *query = init_connect();
		Connection *conn = new Connection();
		conn->enabled = true;
		conn->query = query;
		pool.insert(pool.end(), conn);
		int count = pool.size();
		return query;
	}
	return NULL;
}
Пример #2
0
static void *connect_thread(void *data)
{
	struct rtmp_stream *stream = data;
	int ret;

	os_set_thread_name("rtmp-stream: connect_thread");

	if (!init_connect(stream)) {
		obs_output_signal_stop(stream->output, OBS_OUTPUT_BAD_PATH);
		return NULL;
	}

	ret = try_connect(stream);

	if (ret != OBS_OUTPUT_SUCCESS) {
		obs_output_signal_stop(stream->output, ret);
		info("Connection to %s failed: %d", stream->path.array, ret);
	}

	if (!stopping(stream))
		pthread_detach(stream->connect_thread);

	os_atomic_set_bool(&stream->connecting, false);
	return NULL;
}
Пример #3
0
void* handle_socket_machine(void *arg)
{
	int fd = 0;
	get_iface_mac("eth0",devicemac);
	while(1) {
		if(! is_wifi_connected()) {
			debug(LOG_NOTICE, "tcp Waiting WIFI connected...\n");
			sleep_intp_s(5);
			continue;
		}
		if(! check_valid_id_name()) {
			debug(LOG_NOTICE, "--- waitting deviceid and devicename from uart...\n");
			sleep_intp_s(5);
			continue;
		}
		fd = init_connect(glb_cfg.svr.ip, glb_cfg.svr.port, glb_cfg.svr.noneblock);
		debug(LOG_NOTICE,"Remote Socket thread init %s:%d ret %d\n",glb_cfg.svr.ip, glb_cfg.svr.port, fd);
		if(fd < 0) {
			sleep_intp_s(15);
			continue;
		}
		loop_socket_handle(fd, glb_cfg.svr.tt_ms);
		
		if(fd > 0) close(fd);
		sleep_intp_s(5);
	}
	
	return NULL;
}
Пример #4
0
void			init_params(t_params *par)
{
  par->config.oculus = 0;
  par->sound_toggle = 50;
  par->curr_opacity = 0;
  par->intro_volume = 100;
  par->intro_sound = bunny_load_music("assets/musics/menu_loop.wav");
  par->menu_sound = bunny_load_music("assets/musics/menu.wav");
  par->window = bunny_start(1920, 1080, 1,
			    "Emmanuel can't, but {DOOM}inique Strauss can");
  par->background = bunny_new_pixelarray(1920, 1080);
  par->game_bg = bunny_new_pixelarray(1920, 1080);
  par->option = bunny_new_pixelarray(500, 70);
  par->cur_pos = *bunny_get_mouse_position();
  if (!(par->option) || !(par->background) || !(par->window)
      || !(par->game_bg))
    err("Error: can't start Doom\n");
  init_buttons(&par->menu_buttons);
  init_connect(&par->connect_buttons);
  par->again = GO_ON;
  par->current = &menu;
  par->fullscreen = 0;
  par->origin.x = (par->origin.y = 0);
  par->data = malloc(sizeof(t_data));
  par->data->win = NULL;
  par->data->message.indice = 200;
  bunny_sound_play(par->intro_sound);
  bunny_sound_volume(par->intro_sound, 60);
}
Пример #5
0
/*
 * connect回调
 * man connect
 * It is possible to select(2) or poll(2) for completion by selecting the socket
 * for writing.  After select(2) indicates  writability,  use getsockopt(2)  to
 * read the SO_ERROR option at level SOL_SOCKET to determine whether connect()
 * completed successfully (SO_ERROR is zero) or unsuccessfully (SO_ERROR is one
 * of  the  usual  error  codes  listed  here,explaining the reason for the failure)
 * 1)连接成功建立时,socket 描述字变为可写。(连接建立时,写缓冲区空闲,所以可写)
 * 2)连接建立失败时,socket 描述字既可读又可写。 (由于有未决的错误,从而可读又可写)
 */
void socket::connect_cb ()
{
    int32 ecode = socket::validate();

    if ( 0 == ecode )
    {
        KEEP_ALIVE( socket::fd() );
        USER_TIMEOUT( socket::fd() );

        socket::start();
    }

    /* 连接失败或回调脚本失败,都会被connect_new删除 */
    static class lnetwork_mgr *network_mgr = lnetwork_mgr::instance();
    bool is_ok = network_mgr->connect_new( _conn_id,ecode );

    if ( expect_true( is_ok && 0 == ecode ) )
    {
        init_connect();
    }
    else
    {
        socket::stop ();
    }
}
Пример #6
0
int
main(int argc, char *argv[])
{
	SQLSMALLINT len;
	const char * const*p;
	SQLINTEGER n;

	if (odbc_read_login_info())
		exit(1);

	/* connect string using DSN */
	init_connect();
	sprintf(tmp, "DSN=%s;UID=%s;PWD=%s;DATABASE=%s;ClientCharset=UTF-8;", odbc_server, odbc_user, odbc_password, odbc_database);
	CHKDriverConnect(NULL, T(tmp), SQL_NTS, (SQLTCHAR *) tmp, sizeof(tmp)/sizeof(SQLTCHAR), &len, SQL_DRIVER_NOPROMPT, "SI");
	if (!odbc_driver_is_freetds()) {
		odbc_disconnect();
		printf("Driver is not FreeTDS, exiting\n");
		return 0;
	}

	if (!odbc_db_is_microsoft() || odbc_db_version_int() < 0x08000000u) {
		odbc_disconnect();
		printf("Test for MSSQL only\n");
		return 0;
	}

	CHKAllocStmt(&odbc_stmt, "S");

	/* create test table */
	sprintf(tmp, "IF OBJECT_ID(N'%s') IS NOT NULL DROP TABLE %s", table_name, table_name);
	odbc_command(tmp);
	sprintf(tmp, "CREATE TABLE %s (k int, c NCHAR(10), vc NVARCHAR(10))", table_name);
	odbc_command(tmp);

	/* insert with INSERT statements */
	for (n = 1, p = strings; p[0] && p[1]; p += 2, ++n) {
		sprintf(tmp, "INSERT INTO %s VALUES (%d,N'%s',N'%s')", table_name, (int) n, p[0], p[1]);
		odbc_command(tmp);
	}

	/* check rows */
	for (n = 1, p = strings_hex; p[0] && p[1]; p += 2, ++n) {
		sprintf(tmp, "IF NOT EXISTS(SELECT * FROM %s WHERE k = %d AND c = %s AND vc = %s) SELECT 1", table_name, (int) n, p[0], p[1]);
		CheckNoRow(tmp);
	}

	TestBinding(0);

	TestBinding(1);

	/* cleanup */
	sprintf(tmp, "IF OBJECT_ID(N'%s') IS NOT NULL DROP TABLE %s", table_name, table_name);
	odbc_command(tmp);

	odbc_disconnect();
	printf("Done.\n");
	return 0;
}
Пример #7
0
NetAndUart::NetAndUart(QWidget *parent) :
    QWidget(parent)
{
    //ui->setupUi(this);
    serial = NULL;
    readAll = true;
    timerData = new QTimer();

    init_ui();
    init_connect();

}
Пример #8
0
FxConfigDia::FxConfigDia(FxMainWindow *wind, QWidget *parent): QDialog(parent)
{
    FX_FUNCTION
    setupUi(this);
    mainwind = wind;
    hotKey->installEventFilter(this);

    FxConfigDia::hasInstance = true;

    init_state();
    init_connect();
}
Пример #9
0
int
main(int argc, char *argv[])
{
	SQLTCHAR tmp[2048];
	char conn[128];
	SQLTCHAR sqlstate[6];
	SQLSMALLINT len;
	int port;
	time_t start_time, end_time;

#ifdef _WIN32
	WSADATA wsaData;
	WSAStartup(MAKEWORD(1, 1), &wsaData);
#endif

	if (tds_mutex_init(&mtx))
		return 1;

	if (odbc_read_login_info())
		exit(1);

	/*
	 * prepare our odbcinst.ini 
	 * is better to do it before connect cause uniODBC cache INIs
	 * the name must be odbcinst.ini cause unixODBC accept only this name
	 */
	if (odbc_driver[0]) {
		FILE *f = fopen("odbcinst.ini", "w");

		if (f) {
			fprintf(f, "[FreeTDS]\nDriver = %s\n", odbc_driver);
			fclose(f);
			/* force iODBC */
			setenv("ODBCINSTINI", "./odbcinst.ini", 1);
			setenv("SYSODBCINSTINI", "./odbcinst.ini", 1);
			/* force unixODBC (only directory) */
			setenv("ODBCSYSINI", ".", 1);
		}
	}

	for (port = 12340; port < 12350; ++port)
		if (!init_fake_server(port))
			break;
	if (port == 12350) {
		fprintf(stderr, "Cannot bind to a port\n");
		return 1;
	}
	printf("Fake server bound at port %d\n", port);

	init_connect();
	CHKSetConnectAttr(SQL_ATTR_CONNECTION_TIMEOUT, (SQLPOINTER) 10, sizeof(SQLINTEGER), "SI");
	CHKSetConnectAttr(SQL_ATTR_LOGIN_TIMEOUT, (SQLPOINTER) 10, SQL_IS_UINTEGER, "SI");

	/* this is expected to work with unixODBC */
	printf("try to connect to our port just to check connection timeout\n");
	sprintf(conn, "DRIVER=FreeTDS;SERVER=127.0.0.1;Port=%d;TDS_Version=7.0;UID=test;PWD=test;DATABASE=tempdb;", port);
	start_time = time(NULL);
	CHKDriverConnect(NULL, T(conn), SQL_NTS, tmp, ODBC_VECTOR_SIZE(tmp), &len, SQL_DRIVER_NOPROMPT, "E");
	end_time = time(NULL);

	memset(sqlstate, 'X', sizeof(sqlstate));
	tmp[0] = 0;
	CHKGetDiagRec(SQL_HANDLE_DBC, odbc_conn, 1, sqlstate, NULL, tmp, ODBC_VECTOR_SIZE(tmp), NULL, "SI");
	odbc_disconnect();
	tds_mutex_lock(&mtx);
	CLOSESOCKET(fake_sock);
	tds_mutex_unlock(&mtx);
	tds_thread_join(fake_thread, NULL);

	printf("Message: %s - %s\n", C(sqlstate), C(tmp));
	if (strcmp(C(sqlstate), "HYT00") || !strstr(C(tmp), "Timeout")) {
		fprintf(stderr, "Invalid timeout message\n");
		return 1;
	}
	if (end_time - start_time < 10 || end_time - start_time > 16) {
		fprintf(stderr, "Unexpected connect timeout (%d)\n", (int) (end_time - start_time));
		return 1;
	}

	printf("Done.\n");
	ODBC_FREE();
	return 0;
}
Пример #10
0
int
main(int argc, char *argv[])
{
	char tmp[1024];

	if (odbc_read_login_info())
		exit(1);

	/* try setting db name before connect */
	printf("SQLConnect before 1..\n");
	init_connect();
	set_dbname("master");
	normal_connect();
	check_dbname("master");

	/* check change after connection */
	printf("SQLConnect after..\n");
	set_dbname("tempdb");
	check_dbname("tempdb");

	printf("SQLConnect after not existing..\n");
	strcpy(tmp, "IDontExist");
	CHKSetConnectAttr(SQL_ATTR_CURRENT_CATALOG, (SQLPOINTER) tmp, strlen(tmp), "E");
	check_dbname("tempdb");

	odbc_disconnect();

	/* try setting db name before connect */
	printf("SQLConnect before 2..\n");
	init_connect();
	set_dbname("tempdb");
	normal_connect();
	check_dbname("tempdb");
	odbc_disconnect();

	/* try connect string with using DSN */
	printf("SQLDriverConnect before 1..\n");
	sprintf(tmp, "DSN=%s;UID=%s;PWD=%s;DATABASE=%s;", odbc_server, odbc_user, odbc_password, odbc_database);
	init_connect();
	set_dbname("master");
	driver_connect(tmp);
	check_dbname(odbc_database);
	odbc_disconnect();

	/* try connect string with using DSN */
	printf("SQLDriverConnect before 2..\n");
	sprintf(tmp, "DSN=%s;UID=%s;PWD=%s;", odbc_server, odbc_user, odbc_password);
	init_connect();
	set_dbname("tempdb");
	driver_connect(tmp);
	check_dbname("tempdb");
	odbc_disconnect();

	if (failed) {
		printf("Some tests failed\n");
		return 1;
	}

	printf("Done.\n");
	return 0;
}
Пример #11
0
int
main(int argc, char *argv[])
{
	char tmp[512];
	char out[32];
	SQLLEN n_len;
	SQLSMALLINT len;
	const char * const*p;
	int n;

	if (odbc_read_login_info())
		exit(1);

	/* connect string using DSN */
	init_connect();
	sprintf(tmp, "DSN=%s;UID=%s;PWD=%s;DATABASE=%s;ClientCharset=UTF-8;", odbc_server, odbc_user, odbc_password, odbc_database);
	CHKDriverConnect(NULL, T(tmp), SQL_NTS, (SQLTCHAR *) tmp, sizeof(tmp)/sizeof(SQLTCHAR), &len, SQL_DRIVER_NOPROMPT, "SI");
	if (!odbc_driver_is_freetds()) {
		odbc_disconnect();
		printf("Driver is not FreeTDS, exiting\n");
		odbc_test_skipped();
		return 0;
	}

	if (!odbc_db_is_microsoft() || odbc_db_version_int() < 0x08000000u || odbc_tds_version() < 0x701) {
		odbc_disconnect();
		/* protocol till 7.1 does not support telling encoding so we
		 * cannot understand how the string is encoded
		 */
		printf("Test for MSSQL only using protocol 7.1\n");
		odbc_test_skipped();
		return 0;
	}

	CHKAllocStmt(&odbc_stmt, "S");

	/* create test table */
	odbc_command("CREATE TABLE #tmpHebrew (i INT, v VARCHAR(10) COLLATE Hebrew_CI_AI)");

	/* insert with INSERT statements */
	for (n = 0, p = strings_hex; p[n]; ++n) {
		sprintf(tmp, "INSERT INTO #tmpHebrew VALUES(%d, CAST(%s AS NVARCHAR(10)))", n+1, p[n]);
		odbc_command(tmp);
	}

	/* test conversions in libTDS */
	odbc_command("SELECT v FROM #tmpHebrew");

	/* insert with SQLPrepare/SQLBindParameter/SQLExecute */
	CHKBindCol(1, SQL_C_CHAR, out, sizeof(out), &n_len, "S");
	for (n = 0, p = strings; p[n]; ++n) {
		CHKFetch("S");
		if (n_len != strlen(p[n]) || strcmp(p[n], out) != 0) {
			fprintf(stderr, "Wrong row %d %s\n", n, out);
			odbc_disconnect();
			return 1;
		}
	}

	odbc_disconnect();
	printf("Done.\n");
	return 0;
}
Пример #12
0
int
main(int argc, char *argv[])
{
	char tmp[2048];
	SQLSMALLINT len;
	int succeeded = 0;
	int is_freetds = 1;
	SQLRETURN rc;

	if (odbc_read_login_info())
		exit(1);

	/*
	 * prepare our odbcinst.ini 
	 * is better to do it before connect cause uniODBC cache INIs
	 * the name must be odbcinst.ini cause unixODBC accept only this name
	 */
	if (odbc_driver[0]) {
		FILE *f = fopen("odbcinst.ini", "w");

		if (f) {
			fprintf(f, "[FreeTDS]\nDriver = %s\n", odbc_driver);
			fclose(f);
			/* force iODBC */
			setenv("ODBCINSTINI", "./odbcinst.ini", 1);
			setenv("SYSODBCINSTINI", "./odbcinst.ini", 1);
			/* force unixODBC (only directory) */
			setenv("ODBCSYSINI", ".", 1);
		}
	}

	printf("SQLConnect connect..\n");
	odbc_connect();
	if (!odbc_driver_is_freetds())
		is_freetds = 0;
	odbc_disconnect();
	++succeeded;

	if (!is_freetds) {
		printf("Driver is not FreeTDS, exiting\n");
		return 0;
	}

	/* try connect string with using DSN */
	printf("connect string DSN connect..\n");
	init_connect();
	sprintf(tmp, "DSN=%s;UID=%s;PWD=%s;DATABASE=%s;", odbc_server, odbc_user, odbc_password, odbc_database);
	CHKDriverConnect(NULL, T(tmp), SQL_NTS, (SQLTCHAR *) tmp, sizeof(tmp)/sizeof(SQLTCHAR), &len, SQL_DRIVER_NOPROMPT, "SI");
	odbc_disconnect();
	++succeeded;

	/* try connect string using old SERVERNAME specification */
	printf("connect string SERVERNAME connect..\n");
	printf("odbcinst.ini must be configured with FreeTDS driver..\n");

	/* this is expected to work with unixODBC */
	init_connect();
	sprintf(tmp, "DRIVER=FreeTDS;SERVERNAME=%s;UID=%s;PWD=%s;DATABASE=%s;", odbc_server, odbc_user, odbc_password, odbc_database);
	rc = CHKDriverConnect(NULL, T(tmp), SQL_NTS, (SQLTCHAR *) tmp, sizeof(tmp)/sizeof(SQLTCHAR), &len, SQL_DRIVER_NOPROMPT, "SIE");
	if (rc == SQL_ERROR) {
		printf("Unable to open data source (ret=%d)\n", rc);
	} else {
		++succeeded;
	}
	odbc_disconnect();

	/* this is expected to work with iODBC */
	init_connect();
	sprintf(tmp, "DRIVER=%s;SERVERNAME=%s;UID=%s;PWD=%s;DATABASE=%s;", odbc_driver, odbc_server, odbc_user, odbc_password, odbc_database);
	rc = CHKDriverConnect(NULL, T(tmp), SQL_NTS, (SQLTCHAR *) tmp, sizeof(tmp)/sizeof(SQLTCHAR), &len, SQL_DRIVER_NOPROMPT, "SIE");
	if (rc == SQL_ERROR) {
		printf("Unable to open data source (ret=%d)\n", rc);
	} else {
		++succeeded;
	}
	odbc_disconnect();

#ifdef _WIN32
	if (get_entry("SERVER")) {
		init_connect();
		sprintf(tmp, "DRIVER=FreeTDS;SERVER=%s;UID=%s;PWD=%s;DATABASE=%s;", entry, odbc_user, odbc_password, odbc_database);
		if (get_entry("TDS_Version"))
			sprintf(strchr(tmp, 0), "TDS_Version=%s;", entry);
		rc = CHKDriverConnect(NULL, T(tmp), SQL_NTS, (SQLTCHAR *) tmp, sizeof(tmp)/sizeof(SQLTCHAR), &len, SQL_DRIVER_NOPROMPT, "SIE");
		if (rc == SQL_ERROR) {
			printf("Unable to open data source (ret=%d)\n", rc);
		} else {
			++succeeded;
		}
		odbc_disconnect();
	}
#endif

	/* at least one should success.. */
	if (succeeded < 3) {
		ODBC_REPORT_ERROR("Too few successes");
		exit(1);
	}

	printf("Done.\n");
	return 0;
}
Пример #13
0
int main(int argc, char *argv[])
{
    // 添加系统事件监听
    signal(SIGINT, intHandler);
#ifndef _WIN32
    signal(SIGPIPE, SIG_IGN);
#endif
    my_tox = init_tox();
    init_tox_connection(my_tox);
    load_data(my_tox);
    // 处理参数
    if(argc >3){
		local_port = atoi(argv[1]);
        target_id = argv[2];
        target_ip = argv[3];
        target_port = atoi(argv[4]);
        
        uint8_t my_address_bin[TOX_FRIEND_ADDRESS_SIZE+1];
        uint8_t my_address_str[TOX_FRIEND_ADDRESS_SIZE*2+1];
        tox_get_address(my_tox,my_address_bin);
        hex_bin_to_string(my_address_bin,TOX_FRIEND_ADDRESS_SIZE,my_address_str);
        printf("MYID:%s\n",my_address_str);
    }else{
		local_port = 9990 ;
		target_id = "3E567CBCE8DA8A18ED3C30127ADB61D78AFA2D01B5CD12425C110E84F23AC365144CE2807378";
		target_ip = "127.0.0.1";
		target_port = 22;
    }
    // 虛擬參數
    
    // 初始化消息隊列
    msg_task_queue = createQueue(MAX_MSG_CACHE); // 远程操作消息队列
    
    // 開始tox線程
    pthread_t tox_thread;
    int iret1 = pthread_create( &tox_thread, NULL, tox_works,NULL);
    if(iret1){
        exit(EXIT_FAILURE);
    }
    
    // 初始化本地连接
    local_socksfd = init_local_sock_serv(local_port);
    
    // 等待tox成功連接
    while(!tox_isconnected(my_tox)){
#ifdef _WIN32
		Sleep(20);
#else
		usleep(20000);
#endif
        
    }
    printf("TOXCORE:ONLINE\n");
    printf("SERVER:LISTEN ON %d\n",local_port);
    // 進入請求者模式
    int res = init_connect(my_tox,target_id,&msg_listener_list);
    if(res == 402){
        printf("CONNECT:OK\n");
    }
    else{
        printf("CONNECT:ERROR\n");
    }
    

    // client mode
    // create local tcp server
    msocks_list = create_local_socks_list();
    
    while(1){
        struct sockaddr_in cli_addr;
        uint32_t clilen = sizeof(cli_addr);
		int32_t newsockfd = accept(local_socksfd,
			(struct sockaddr *) &cli_addr,
			&clilen);
        
		if (newsockfd < 0){
			printf("socket error\n");
		}
		else{
			printf("accepted:%d\n", newsockfd);
			// 发送创建远程端口指令
            uint32_t sockfd = newsockfd;
            uint8_t *target_addr_bin = (uint8_t *)malloc(sizeof(uint8_t)*TOX_FRIEND_ADDRESS_SIZE);
            hex_string_to_bin(target_addr_bin,target_id);
            add_local_socks(msocks_list,sockfd,target_addr_bin,target_ip,target_port);
            // create remote socket
            uint8_t uuid[UUID_LENGTH+1];
            get_local_socks_uuid(msocks_list,sockfd,uuid);
            create_remote_socket(uuid,target_addr_bin,target_ip,target_port);
            free(target_addr_bin);
		}
    }
    
    printf("EXITED\n");
    return 0; 
}
Пример #14
0
int main(int argc,char **argv)
{
	if(argc >=2 && strcmp(argv[1],"-d") == 0) {
		//daemon(0,0); //maybe cause SIGTOP tty Interrupt
		NOTE("Starting as daemon, forking to background");
		init_daemon();
	}
	/*
	 * Make sure only one copy of the daemon is running.
	 */
	if (already_running()) {
		syslog(LOG_ERR, "net4g daemon already running\n");
		exit(1);
	}
	
	// close timer on gpio
	record2file(WTD_TRIG,"none",4);
	record2file(WTD_BRIG,"0",1);
	
	openlog("net4g",LOG_NOWAIT,LOG_DAEMON);
	glb_cfg = config_init();
	nvram_renew("/tmp/board_info");
	nvram_renew("/tmp/pub_info");
	
//	nvram_buflist();
	
	init_signals();
#if 0
	pthread_t pid = 0;
	if(pthread_create(&pid,NULL,(void*)handle_gps,NULL) < 0 ) {
		ERROR("create gps thread error!\n");
		exit(1);
	}
	pthread_detach(pid);
#else
	pthread_t tpid = 0;
	if(pthread_create(&tpid,NULL,(void*)handle_tty,NULL) < 0 ) {
		ERROR("create tty thread error!\n");
		exit(1);
	}
	pthread_detach(tpid);
#endif

#if 1
	pthread_t apid = 0;
	if(pthread_create(&apid,NULL,(void*)handle_agps,NULL) < 0 ) {
		ERROR("create Agps thread error!\n");
		exit(1);
	}
	pthread_detach(apid);
#endif
	
	pthread_t ptid = 0;
	if(pthread_create(&ptid,NULL,(void*)handle_timing_gpio,NULL) < 0 ) {
		ERROR("create GPIO thread error!\n");
		exit(1);
	}
	pthread_detach(ptid);
	
	int disconnected = 1;
	int faild_login = 1;
	int ret = 0;
	int socket = 0;
	struct timeval last_tv;
	struct timeval now_tv;
	unsigned int login_count = 1;
	unsigned int info_count = 1;
	unsigned int failcount = 0;
	char recv_buf[1024] = {0};
	
	while(!exit_flag && failcount < 360) {
		record2file(WTD_BRIG,"1",1);
		
		if(access("/dev/ttyUSB2",F_OK) != 0) {
			ERROR("waiting for detecting 4G modult;ttyUSB2\n");
			goto DISCONN;
		}
		
		if(access("/tmp/dialok",F_OK) != 0) {
			ERROR("waiting for ppp dial OK\n");
			goto DISCONN;
		}
		
		if(disconnected) {
			record2file("/tmp/onoffline","Offline",7);
			//system("/bin/echo Offline > /tmp/onoffline");
			faild_login = 1;
			nvram_renew("/tmp/board_info");
			socket = init_connect(nvram_get("remote_ip"),atoi(nvram_get("remote_port")),1);
			NOTE("remote socket = %d\n",socket);
			if(socket >= 0) {
				gettimeofday(&last_tv,NULL);
				disconnected = 0;
				set_socket_keepalive(socket);
				glb_remote_socket = socket;
				failcount = 0;
			} else {
				failcount++;
				glb_remote_socket = -1;
				record2file(WTD_BRIG,"0",1);
				sleep_seconds_intr(30);
				continue;
			}
		}
		// login
		if(faild_login) {
			record2file("/tmp/onoffline","Offline",7);
			//system("/bin/echo Offline > /tmp/onoffline");
			nvram_renew("/tmp/board_info");
			ret = send_login(socket,login_count++);
			if(ret > 0) {
				gettimeofday(&last_tv,NULL);
				faild_login = 0;
				login_count = 0;
				//system("/bin/echo Online > /tmp/onoffline");
				record2file("/tmp/onoffline","Online",6);
			} else if(ret == -2){
				//socket error
				ERROR("Error send login!\n");
				goto DISCONN;
			} else {
				//recv msg format error
				NOTE("To relogin!\n");
				failcount++;
				record2file(WTD_BRIG,"0",1);
				sleep_seconds_intr(30);
				continue;
			}
		}
		
		gettimeofday(&now_tv,NULL);
		//printf("time;%ld:%ld\n",now_tv.tv_sec,last_tv.tv_sec);
		if(now_tv.tv_sec - last_tv.tv_sec >= 230) {
			gettimeofday(&last_tv,NULL);
			NOTE("net4g -- keepalive...%u, but server no response, to reconnect\n",info_count);
			//server no response ,but send ok
			goto DISCONN;
		}

		fd_set fds;
		struct timeval tv;
		FD_ZERO(&fds);
		FD_SET(socket, &fds); 
		/* init socket timeout, set to 60 seconds */
		tv.tv_sec = 60;
		tv.tv_usec = 0;

		//server handle socket event
		if((ret = select(socket + 1, &fds, NULL, NULL, &tv)) < 0)
		{
			if(errno == EINTR) {
				//gettimeofday(&last_tv,NULL);
				NOTE("server socket select EINTR\n");
				record2file(WTD_BRIG,"0",1);
				continue;
			} else {
				ERROR("select error:%d\n",errno);
				goto DISCONN;
			}
		} else if(ret == 0) {
			ret = send_board_info(socket,info_count++);
			if(ret <= 0) {
				ERROR("Error send gpsinfo!\n");
				goto DISCONN;
			} else {
				record2file(WTD_BRIG,"0",1);
				continue;
			}
		}
		if(FD_ISSET(socket, &fds) <= 0) {
			ERROR("something wrong while waiting for socket,error:%d\n",errno);
			goto DISCONN;
		}
		
		memset(recv_buf,0,sizeof(recv_buf));
		ret = recv(socket,recv_buf,1023,0);
		if(ret <= 0) {
			ERROR("Error while recv socket:%d:%s\n",errno,strerror(errno));
			goto DISCONN;
		}
		NOTE("RECV:%s\n",recv_buf);
		ret = handle_msg(socket,recv_buf);
		if(ret < 0) {
			goto DISCONN;
		} else if(ret == 1) {
			exit_flag = 1;
			goto EXIT;
		} else {
			//ok
		}
		failcount = 0;
		record2file(WTD_BRIG,"0",1);
		gettimeofday(&last_tv,NULL);
		continue;
		
	DISCONN:
		failcount++;
		glb_remote_socket = -1;
		disconnected = 1;
		faild_login = 1;
		if(socket > 0) close(socket);
		socket = -1;
		sleep_seconds_intr(25);
		record2file(WTD_BRIG,"0",1);
		sleep_seconds_intr(1);
	} //end while(1)
EXIT:
	exit_flag = 1;
	if(socket > 0) close(socket);
	NOTE("net4g process exit!!\n");
	config_close(glb_cfg);
	closelog();
	return 0;
}