static void network_exit(void) { server_exit(); btd_profile_unregister(&panu_profile); btd_profile_unregister(&gn_profile); btd_profile_unregister(&nap_profile); bnep_cleanup(); }
void network_manager_exit(void) { server_exit(); btd_unregister_device_driver(&network_panu_driver); btd_unregister_device_driver(&network_gn_driver); btd_unregister_device_driver(&network_nap_driver); connection_exit(); btd_unregister_adapter_driver(&network_server_driver); dbus_connection_unref(connection); connection = NULL; bnep_cleanup(); }
void network_manager_exit(void) { if (conf->server_enabled) server_exit(); if (conf->connection_enabled) connection_exit(); g_dbus_unregister_interface(connection, NETWORK_PATH, NETWORK_MANAGER_INTERFACE); dbus_connection_unref(connection); connection = NULL; bnep_cleanup(); bridge_cleanup(); }
void server_quit(int signo) { printf("server is shuting down\n"); server_exit(); exit(0); }
void main_loop( void ) { int listenfd,fd, nready; struct sockaddr client; ssize_t client_len; fd_set read_set; struct timeval timeout, timeofday_old, timeofday_new; struct timezone tz; listenfd = net_listen(NULL,g_server.port); if( listenfd < 0 ) return; max_fd=listenfd; FD_ZERO(&all_set); FD_SET(listenfd,&all_set); if( g_server.with_console ) { FD_SET(CONSOLE_FD, &all_set); } #define TIMEOUT_SEC (180) /* 3 minutes */ /* 5 minutes */ timeout.tv_sec = TIMEOUT_SEC; timeout.tv_usec = 0; gettimeofday( &timeofday_old, &tz ); memset( &tz, 0, sizeof(tz) ); while(1) { read_set = all_set; nready = select( max_fd+1, &read_set, NULL, NULL, &timeout ); /* recompute the timeout */ if( gettimeofday( &timeofday_new, &tz ) == 0 ) { int s = timeofday_new.tv_sec - timeofday_old.tv_sec; if( TIMEOUT_SEC > s ) timeout.tv_sec = TIMEOUT_SEC - s; else timeout.tv_sec = TIMEOUT_SEC; /* it is aprox 3 minutes */ if( s == 0 ) timeout.tv_usec = timeofday_new.tv_usec - timeofday_old.tv_usec; else timeout.tv_usec = 0; /* may occur sometimes */ if( s > TIMEOUT_SEC ) { timeout.tv_sec = TIMEOUT_SEC; timeout.tv_usec = 0; gettimeofday( &timeofday_old, &tz ); server_is_idle(); } } /* error ?*/ if( nready == -1 ) { if(errno!=EINTR) { fprintf(stderr,_("tegserver: Abnormal error in select()\n")); perror("tegserver:"); } continue; /* timeout ? */ } else if( nready == 0 ) { MAIN_DEBUG("timeout\n"); timeout.tv_sec = TIMEOUT_SEC; timeout.tv_usec = 0; gettimeofday( &timeofday_old, &tz ); server_is_idle(); continue; } /* new client */ if(FD_ISSET( listenfd, &read_set) ) { MAIN_DEBUG("new client\n"); client_len = sizeof( client ); fd = accept( listenfd, (struct sockaddr *)&client, &client_len ); if( fd != -1 ) fd_add( fd ); if(--nready <= 0) continue; } /* input from console */ if( g_server.with_console && FD_ISSET(CONSOLE_FD, &read_set)) { TEG_STATUS ts = console_handle(CONSOLE_FD); if(ts==TEG_STATUS_GAMEOVER || ts==TEG_STATUS_CONNCLOSED) server_exit(listenfd); if(--nready <= 0) continue; } /* input from players */ for(fd=0;fd<=max_fd;fd++) { if( (fd!=listenfd && fd!=CONSOLE_FD) && FD_ISSET(fd,&read_set) ) { if(play_teg( fd )==TEG_STATUS_CONNCLOSED) { MAIN_DEBUG("closing connection\n"); /* kick robots if they are alone */ player_kick_unparent_robots(); } if(--nready <= 0) break; } } } }