Beispiel #1
0
int main (int argc, char **argv) {
  signal (SIGSEGV, sig_handler);
  signal (SIGABRT, sig_handler);

  log_level = 10;
  
  args_parse (argc, argv);
  printf (
    "Telegram-client version " TG_VERSION ", Copyright (C) 2013 Vitaly Valtman\n"
    "Telegram-client comes with ABSOLUTELY NO WARRANTY; for details type `show_license'.\n"
    "This is free software, and you are welcome to redistribute it\n"
    "under certain conditions; type `show_license' for details.\n"
  );
  running_for_first_time ();
  parse_config ();


  get_terminal_attributes ();

  #ifdef USE_LUA
  if (lua_file) {
    lua_init (lua_file);
  }
  #endif

  inner_main ();
  
  return 0;
}
Beispiel #2
0
bool lua_load_states(const char *filename, 
  const char *blend, const char *depth, const char *sampler, const char *rasterizer, 
  ID3D11BlendState **b, ID3D11DepthStencilState **d, ID3D11SamplerState **s, ID3D11RasterizerState **r)
{
  lua_State *l = NULL;
  if (!lua_init(&l, filename))
    return false;

  SCOPED_OBJ([l](){lua_close(l); } );

  if (lua_pcall(l, 0, 0, 0)) {
    LOG_WARNING_LN(lua_tostring(l, -1));
    return false;
  }

  // XXX: To get this to work, the lua_longjmp struct must be moved from ldo.c to ldo.h. There
  // has to be a cleaner way to do this..
/*
  lua_longjmp jmp;
  jmp.previous = l->errorJmp;
  jmp.status = 0;
  l->errorJmp = &jmp;

  int err;
  if (!(err = setjmp(jmp.b))) {
*/
    CComPtr<ID3D11BlendState> tmp_blend;
    CComPtr<ID3D11SamplerState> tmp_sampler;
    CComPtr<ID3D11DepthStencilState> tmp_dss;
    CComPtr<ID3D11RasterizerState> tmp_rast;

    if (blend && !blend_state_from_lua(l, blend, tmp_blend))
      return false;

    if (depth && !depth_stencil_state_from_lua(l, depth, tmp_dss))
      return false;

    if (sampler && !sampler_from_lua(l, sampler, tmp_sampler))
      return false;

    if (rasterizer && !rasterizer_state_from_lua(l, rasterizer, tmp_rast))
      return false;

    if (b) *b = tmp_blend.Detach();
    if (d) *d = tmp_dss.Detach();
    if (s) *s = tmp_sampler.Detach();
    if (r) *r = tmp_rast.Detach();
/*
  } else {
    LOG_ERROR_LN("Error loading lua state: %s", filename);
    return false;
  }
*/
	return true;
}
Beispiel #3
0
int main() {
	if (!lua_init()) {
		printf("cannot init lua\n");
		exit(1);
	}
	
	lua_register(lua_state(), "simpleclient_create", simpleclient_create_lua);
	lua_register(lua_state(), "simpleclient_destroy", simpleclient_destroy_lua);
	lua_register(lua_state(), "simpleclient_connect", simpleclient_connect_lua);

	lua_dofile("./scripts/main.lua");
	
	lua_fini();
}
Beispiel #4
0
int main(int argc, char **argv)
{
    int err = 0;
    lua_State *L;
    setup_signal_handler();
    /* parse args once to read config file location */
    if (parse_args(argc, argv, &err) != 0) {
        return err;
    }
    /* ini file sets defaults for arguments*/
    parse_config(inifile);
    if (!global.inifile) {
        log_error("could not open ini configuration %s\n", inifile);
    }
    /* parse arguments again, to override ini file */
    parse_args(argc, argv, &err);

    log_open(logfile);
    locale_init();

#ifdef CRTDBG
    init_crtdbg();
#endif

    L = lua_init();
    game_init();
    bind_monsters(L);
    err = eressea_run(L, luafile);
    if (err) {
        log_error("script %s failed with code %d\n", luafile, err);
        return err;
    }
#ifdef MSPACES
    malloc_stats();
#endif

    game_done();
    lua_done(L);
    log_close();
    if (global.inifile) {
        iniparser_freedict(global.inifile);
    }
    return 0;
}
Beispiel #5
0
int main(int argc, char **argv)
{
  int err, result = 0;
  lua_State *L;
  setup_signal_handler();
  parse_config(inifile);
  log_open(logfile);

  err = parse_args(argc, argv, &result);
  if (err) {
    return result;
  }

  locale_init();

#ifdef CRTDBG
  init_crtdbg();
#endif

    L = lua_init();
  game_init();
  register_races();
  register_borders();
  register_spells();
  bind_monsters(L);
  err = eressea_run(L, luafile);
  if (err) {
    log_error("server execution failed with code %d\n", err);
    return err;
  }
#ifdef MSPACES
  malloc_stats();
#endif

  game_done();
  lua_done(L);
  log_close();
  if (global.inifile) {
    iniparser_free(global.inifile);
  }
  return 0;
}
Beispiel #6
0
void TgLoopThread::run()
{
    qDebug() << "Thread started";
    std::vector<std::string> parameters;
    parameters.push_back("-B");
    parameters.push_back("-R");
    char** p = new char*[parameters.size()];

    for(size_t i = 0; i < parameters.size(); i++)
    {
        p[i] = (char*)parameters[i].c_str();
    }

    lua_init();
    lua_register(luaState, "on_binlog_replay_end", onBinlogReplayEnd);
    lua_register(luaState, "on_username_asked", onUsernameAsked);
    qDebug() << "Lua functions registered";

    qDebug() << "Calling tg-main";
    disabled_main(2, p);
    delete [] p;
}
Beispiel #7
0
int tmain (int argc, char **argv) {
//  signal (SIGSEGV, sig_segv_handler);
//  signal (SIGABRT, sig_abrt_handler);

  log_level = 10;

  args_parse (argc, argv);
  running_for_first_time ();
  parse_config ();


  get_terminal_attributes ();

  #ifdef USE_LUA
  if (lua_file) {
    lua_init (lua_file);
  }
  #endif

  inner_main ();

  return 0;
}
Beispiel #8
0
int main(int argc, char **argv)
{
    int err = 0;
    lua_State *L;
    dictionary *d = 0;
    setup_signal_handler();
    message_handle_missing(MESSAGE_MISSING_REPLACE);
    /* parse arguments again, to override ini file */
    err = parse_args(argc, argv);
    if (err != 0) {
        return (err > 0) ? 0 : err;
    }
    d = parse_config(inifile);
    if (!d) {
        log_error("could not open ini configuration %s\n", inifile);
    }

    locale_init();

    L = lua_init(d);
    game_init();
    bind_monsters(L);
    err = eressea_run(L, luafile);
    if (err) {
        log_error("script %s failed with code %d\n", luafile, err);
        return err;
    }
    game_done();
    lua_done(L);
    log_close();
    stats_write(stdout, "");
    stats_close();
    if (d) {
        iniparser_freedict(d);
    }
    return 0;
}
Beispiel #9
0
void context_lua_t::lua_ctx_init(message_t& message)
{
	int32_t argc = (int32_t)message_integer(message);
	int32_t envc = lua_gettop(m_lstate) - argc;
	const char *file = lua_tostring(m_lstate, 1);
	if (luaL_loadfile(m_lstate, file) == LUA_OK) {
		lua_State *co;
		lua_init(m_lstate);
		lua_insert(m_lstate, -envc - 1);
		lua_init_env(m_lstate, envc);
		co = lua_new_root_coro(m_lstate);
		lua_pushlightuserdata(m_lstate, NULL);
		lua_pushcclosure(m_lstate, lua_ref_callback_entry, argc + 1); /* make the c closure callback */
		lua_xmove(m_lstate, co, 1);  /* move top c closure to co */
		lua_pop(m_lstate, 1);		 /* pop the file name on top */
		resume_coroutine(co, 0);
		if (!is_active()) {
			singleton_ref(node_lua_t).context_destroy(this, m_handle, "lua context exit normally");
		}
		return;
	}
	const char *error = lua_tostring(m_lstate, -1);
	singleton_ref(node_lua_t).context_destroy(this, m_handle, "fail to initialize lua context %s, %s", file, error);
}
Beispiel #10
0
Datei: main.c Projekt: analani/tg
int main (int argc, char **argv) {
  signal (SIGSEGV, termination_signal_handler);
  signal (SIGABRT, termination_signal_handler);
  signal (SIGBUS, termination_signal_handler);
  signal (SIGQUIT, termination_signal_handler);
  signal (SIGFPE, termination_signal_handler);

  signal (SIGPIPE, SIG_IGN);
  
  signal (SIGTERM, sig_term_handler);
  signal (SIGINT, sig_term_handler);

  rl_catch_signals = 0;


  log_level = 10;
  
  args_parse (argc, argv);
  
  change_user_group ();

  if (port > 0) {
    struct sockaddr_in serv_addr;

    sfd = socket (AF_INET, SOCK_STREAM, 0);
    if (sfd < 0) {
      perror ("socket");
      exit(1);
    }

    memset (&serv_addr, 0, sizeof (serv_addr));
    
    serv_addr.sin_family = AF_INET;
    serv_addr.sin_addr.s_addr = htonl (0x7f000001);
    serv_addr.sin_port = htons (port);
 
    if (bind (sfd, (struct sockaddr *) &serv_addr, sizeof (serv_addr)) < 0) {
      perror ("bind");
      exit(1);
    }

    listen (sfd, 5);
  } else {
    sfd = -1;
  }
  
  if (unix_socket) {
    assert (strlen (unix_socket) < 100);
    struct sockaddr_un serv_addr;

    usfd = socket (AF_UNIX, SOCK_STREAM, 0);
    if (usfd < 0) {
      perror ("socket");
      exit(1);
    }

    memset (&serv_addr, 0, sizeof (serv_addr));
    
    serv_addr.sun_family = AF_UNIX;

    snprintf (serv_addr.sun_path, 108, "%s", unix_socket);
 
    if (bind (usfd, (struct sockaddr *) &serv_addr, sizeof (serv_addr)) < 0) {
      perror ("bind");
      exit(1);
    }

    listen (usfd, 5);    
  } else {
    usfd = -1;
  }

  if (daemonize) {
    signal (SIGHUP, sighup_handler);
    reopen_logs ();
  }
  signal (SIGUSR1, sigusr1_handler);

  if (!disable_output) {
    printf (
      "Telegram-cli version " TGL_VERSION ", Copyright (C) 2013-2014 Vitaly Valtman\n"
      "Telegram-cli comes with ABSOLUTELY NO WARRANTY; for details type `show_license'.\n"
      "This is free software, and you are welcome to redistribute it\n"
      "under certain conditions; type `show_license' for details.\n"
    );
  }
  running_for_first_time ();
  parse_config ();

  tgl_set_rsa_key ("/etc/" PROG_NAME "/server.pub");
  tgl_set_rsa_key ("tg-server.pub");


  get_terminal_attributes ();

  #ifdef USE_LUA
  if (lua_file) {
    lua_init (lua_file);
  }
  #endif

  inner_main ();
  
  return 0;
}
Beispiel #11
0
int main (int argc, char **argv) {
  signal (SIGSEGV, termination_signal_handler);
  signal (SIGABRT, termination_signal_handler);
  signal (SIGBUS, termination_signal_handler);
  signal (SIGQUIT, termination_signal_handler);
  signal (SIGFPE, termination_signal_handler);

  signal (SIGPIPE, SIG_IGN);
  
  signal (SIGTERM, sig_term_handler);
  signal (SIGINT, sig_term_handler);

  rl_catch_signals = 0;


  log_level = 10;
  
  args_parse (argc, argv);
  
  change_user_group ();

  if (port > 0) {
    struct sockaddr_in serv_addr;
    int yes = 1;
    sfd = socket (AF_INET, SOCK_STREAM, 0);
    if (sfd < 0) {
      perror ("socket");
      exit(1);
    }

    if(setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) < 0) {
      perror("setsockopt");
      exit(1);
    }
    memset (&serv_addr, 0, sizeof (serv_addr));
    
    serv_addr.sin_family = AF_INET;
    serv_addr.sin_addr.s_addr = accept_any_tcp ? INADDR_ANY : htonl (0x7f000001);
    serv_addr.sin_port = htons (port);
 
    if (bind (sfd, (struct sockaddr *) &serv_addr, sizeof (serv_addr)) < 0) {
      perror ("bind");
      exit(1);
    }

    listen (sfd, 5);
  } else {
    sfd = -1;
  }
  
  if (unix_socket) {
    assert (strlen (unix_socket) < 100);
    struct sockaddr_un serv_addr;

    usfd = socket (AF_UNIX, SOCK_STREAM, 0);
    if (usfd < 0) {
      perror ("socket");
      exit(1);
    }

    memset (&serv_addr, 0, sizeof (serv_addr));
    
    serv_addr.sun_family = AF_UNIX;

    snprintf (serv_addr.sun_path, sizeof(serv_addr.sun_path), "%s", unix_socket);
 
    if (bind (usfd, (struct sockaddr *) &serv_addr, sizeof (serv_addr)) < 0) {
      perror ("bind");
      exit(1);
    }

    listen (usfd, 5);    
  } else {
    usfd = -1;
  }

  if (daemonize) {
    signal (SIGHUP, sighup_handler);
    reopen_logs ();
  }
  signal (SIGUSR1, sigusr1_handler);

  if (!disable_output) {
    printf (
      "Telegram-cli version " TELEGRAM_CLI_VERSION ", Copyright (C) 2013-2015 Vitaly Valtman\n"
      "Telegram-cli comes with ABSOLUTELY NO WARRANTY; for details type `show_license'.\n"
      "This is free software, and you are welcome to redistribute it\n"
      "under certain conditions; type `show_license' for details.\n"
      "Telegram-cli uses libtgl version " TGL_VERSION "\n"
#ifndef TGL_AVOID_OPENSSL 
      "Telegram-cli includes software developed by the OpenSSL Project\n"
      "for use in the OpenSSL Toolkit. (http://www.openssl.org/)\n"
#endif
#ifdef USE_PYTHON
      "Telegram-cli uses libpython version " PY_VERSION "\n"
#endif
    );
  }
  running_for_first_time ();
  parse_config ();

  #ifdef __FreeBSD__
  tgl_set_rsa_key (TLS, "/usr/local/etc/" PROG_NAME "/server.pub");
  #else
  tgl_set_rsa_key (TLS, "/etc/" PROG_NAME "/server.pub");
  #endif
  tgl_set_rsa_key (TLS, "tg-server.pub");

  tgl_set_rsa_key_direct (TLS, tglmp_get_default_e (), tglmp_get_default_key_len (), tglmp_get_default_key ());

  get_terminal_attributes ();

  #ifdef USE_LUA
  if (lua_file) {
    lua_init (lua_file, lua_param);
  }
  #endif
  #ifdef USE_PYTHON
  if (python_file) {
    py_init (python_file);
  }
  #endif


  inner_main ();
  
  return 0;
}
Beispiel #12
0
void running_machine::start()
{
	// initialize basic can't-fail systems here
	config_init(*this);
	m_input = auto_alloc(*this, input_manager(*this));
	output_init(*this);
	palette_init(*this);
	m_render = auto_alloc(*this, render_manager(*this));
	generic_machine_init(*this);
	generic_sound_init(*this);

	// allocate a soft_reset timer
	m_soft_reset_timer = m_scheduler.timer_alloc(timer_expired_delegate(FUNC(running_machine::soft_reset), this));

	// init the osd layer
	m_osd.init(*this);

	// create the video manager
	m_video = auto_alloc(*this, video_manager(*this));
	ui_init(*this);

	// initialize the base time (needed for doing record/playback)
	::time(&m_base_time);

	// initialize the input system and input ports for the game
	// this must be done before memory_init in order to allow specifying
	// callbacks based on input port tags
	time_t newbase = input_port_init(*this);
	if (newbase != 0)
		m_base_time = newbase;

	// intialize UI input
	ui_input_init(*this);

	// initialize the streams engine before the sound devices start
	m_sound = auto_alloc(*this, sound_manager(*this));

	// first load ROMs, then populate memory, and finally initialize CPUs
	// these operations must proceed in this order
	rom_init(*this);
	memory_init(*this);
	watchdog_init(*this);

	// must happen after memory_init because this relies on generic.spriteram
	generic_video_init(*this);

	// allocate the gfx elements prior to device initialization
	gfx_init(*this);

	// initialize natural keyboard support
	inputx_init(*this);

	// initialize image devices
	image_init(*this);
	tilemap_init(*this);
	crosshair_init(*this);

	// initialize the debugger
	if ((debug_flags & DEBUG_FLAG_ENABLED) != 0)
		debugger_init(*this);

	// call the game driver's init function
	// this is where decryption is done and memory maps are altered
	// so this location in the init order is important
	ui_set_startup_text(*this, "Initializing...", true);

	// start up the devices
	const_cast<device_list &>(devicelist()).start_all();

	// if we're coming in with a savegame request, process it now
	const char *savegame = options().state();
	if (savegame[0] != 0)
		schedule_load(savegame);

	// if we're in autosave mode, schedule a load
	else if (options().autosave() && (m_system.flags & GAME_SUPPORTS_SAVE) != 0)
		schedule_load("auto");

	// set up the cheat engine
	m_cheat = auto_alloc(*this, cheat_manager(*this));

	lua_init(*this);
	extern void Update_RAM_Search(running_machine &machine);
	this->add_notifier(MACHINE_NOTIFY_FRAME, machine_notify_delegate(FUNC(Update_RAM_Search), this));

	// disallow save state registrations starting here
	m_save.allow_registration(false);
}
Beispiel #13
0
int main() {
    t_min = 5;
    port = 5222;

    strncpy(dbhost, "localhost", MAX_CHAR_LENGTH);
    dbport = 3306;
    strncpy(dbuser, "root", MAX_CHAR_LENGTH);
    strncpy(dbpass, "123456", MAX_CHAR_LENGTH);
    strncpy(dbname, "ucenter", MAX_CHAR_LENGTH);
    strncpy(dbtable, "uc_members", MAX_CHAR_LENGTH);
    strncpy(fieldusername, "username", MAX_CHAR_LENGTH);
    strncpy(fieldpassword, "password", MAX_CHAR_LENGTH);

    int i;
    for (i = 0; i < MAX_FDS; i++) {
        fd_clients[i] = NULL;
    }

    for (i = 0; i < MAX_ROOMS; i++) {
        
        pthread_mutex_init(&t_mutex_room[i], NULL);
        rooms[i].enable = 0;
        rooms[i].num = 0;
        memset(rooms[i].name, '\0', sizeof (rooms[i].name));
        rooms[i].client = NULL;
    }

    if (hash_create(MAX_USERS) == 0) {
        log_write(LOG_ERR, "hcreate error", __FILE__, __LINE__);
        return (EXIT_FAILURE);
    }

    rooms[0].enable = 1;
    strncpy(rooms[0].name, "Myleft聊天大厅", MAX_CHAR_LENGTH);

    lua_init();
    lua_load_config();
    lua_load_room();

    db_connect();

    //创建epoll句柄
    epfd = epoll_create(MAX_FDS);

    int optval = 1; // 关闭之后重用socket
    unsigned int optlen = sizeof (optval);

    if ((s.listen_sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
        log_write(LOG_ERR, "socket error", __FILE__, __LINE__);
        destory();
        return (EXIT_FAILURE);
    }

    log_write(LOG_DEBUG, "listen socked created", __FILE__, __LINE__);

    setsockopt(s.listen_sockfd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof (optlen)); //端口重用,如意外没有释放端口,还可以绑定成功

    bzero(&s.listen_addr, sizeof (s.listen_addr)); //memset 适合大数据

    s.listen_addr.sin_family = AF_INET;
    s.listen_addr.sin_port = htons(port);
    s.listen_addr.sin_addr.s_addr = htonl(INADDR_ANY); //inet_addr("127.0.0.1");

    if (bind(s.listen_sockfd, (struct sockaddr*) & s.listen_addr, sizeof (s.listen_addr)) < 0) {
        log_write(LOG_ERR, "bind error", __FILE__, __LINE__);
        destory();
        return (EXIT_FAILURE);
    }

    if (listen(s.listen_sockfd, 3) < 0) {
        log_write(LOG_ERR, "listen error", __FILE__, __LINE__);
        destory();
        return (EXIT_FAILURE);
    }
    printf("listenning......\n");

    /* 设置socket为非阻塞模式,使用libevent编程这是必不可少的。 */
    if (evutil_make_socket_nonblocking(s.listen_sockfd) < 0) {
        log_write(LOG_ERR, "evutil_make_socket_nonblocking error", __FILE__, __LINE__);
        destory();
        return (EXIT_FAILURE);
    }

    //设置与要处理的事件相关的文件描述符
    ev.data.fd = s.listen_sockfd;
    //设置要处理的事件类型
    ev.events = EPOLLIN;

    int nfds;
    int client_fd;
    struct sockaddr_in client_addr;
    socklen_t client_len = sizeof (client_addr);

    char msgbuffer[MAX_BUFFER_LENGTH];
    int recv_bits;

    //注册epoll事件
    epoll_ctl(epfd, EPOLL_CTL_ADD, s.listen_sockfd, &ev);

    pthread_mutex_init(&t_mutex, NULL);
    pthread_cond_init(&t_cond, NULL);

    pthread_mutex_init(&t_mutex_hash, NULL);

    delay.tv_sec = 2;
    delay.tv_nsec = 0;

    //开启心跳线程heartbeat
    pthread_create(&t_heartbeat, NULL, heartbeat, NULL);

    //初始化任务线程,开启两个线程来完成任务,线程之间会互斥地访问任务链表
    t_num = 0;
    while (t_num < t_min && t_num < T_MAX) {
        t_num++;
        pthread_create(&tid[t_num], NULL, readtask, NULL);
    }

    clients *client_fdnode;
    int logout = 0;
    while (1) {
        //等待epoll事件的发生
        nfds = epoll_wait(epfd, events, MAX_EVENTS, 3000);
        //处理所发生的所有事件
        for (i = 0; i < nfds; ++i) {
            time(&mytimestamp);
            p = gmtime(&mytimestamp);
            printf("fd:%d, file:%s, line:%d\n", events[i].data.fd, __FILE__, __LINE__);
            if (events[i].data.fd == s.listen_sockfd) {//主socket
                client_fd = accept(s.listen_sockfd, (struct sockaddr *) & client_addr, &client_len);
                if (client_fd < 0) {
                    perror("connfd<0");
                }

                evutil_make_socket_nonblocking(client_fd);

                clients *node = (clients *) malloc(sizeof (clients));
                node->fd = client_fd;
                node->roomid = -1;
                node->state = FD_STATE_WAIT;
                node->type = CLIENT_TYPE_NONE;
                node->anonymous = 1;
                node->x = 1;
                node->y = 1;
                node->keepalivetime = mytimestamp;
                //node->username[0] = '\0';
                memset(node->username, 1 ,sizeof(node->username));//bzero(c, sizeof(c));
                node->next = NULL;
                
                fd_clients[client_fd] = node;

                ev.events = EPOLLIN | EPOLLET;
                ev.data.fd = client_fd;
                epoll_ctl(epfd, EPOLL_CTL_ADD, client_fd, &ev);
                log_write(LOG_DEBUG, "epoll_ctl", __FILE__, __LINE__);
            } else if (events[i].events & EPOLLIN) {
                logout = 0;
                memset(msgbuffer, '\0', sizeof (msgbuffer));
                printf("msgbuffer:%s", msgbuffer);
                if (events[i].data.fd < 0) {
                    continue;
                }
                client_fdnode = fd_clients[events[i].data.fd];
                if (client_fdnode == NULL) {
                    events[i].data.fd = -1;
                    close(events[i].data.fd);
                }
                client_fdnode->keepalivetime = mytimestamp;
                recv_bits = read(events[i].data.fd, msgbuffer, sizeof (msgbuffer));
                if (recv_bits <= 0) {
                    printf("recv_bits:%d, file:%s, line:%d\n", recv_bits, __FILE__, __LINE__);
                    logout = 1;

                    events[i].data.fd = -1;
                    if (client_fdnode->state != FD_STATE_SUCCESS) {
                        node_del(client_fdnode);
                        continue; //退出
                    }
                } else if (recv_bits >= MAX_BUFFER_LENGTH) {
                    log_write(LOG_DEBUG, "recv_bits>", __FILE__, __LINE__);
                    logout = 1;

                    events[i].data.fd = -1;
                    if (client_fdnode->state != FD_STATE_SUCCESS) {
                        node_del(client_fdnode);
                        continue; //退出
                    }
                } else if (strncmp(msgbuffer, PING, sizeof (PING)) == 0) {
                    send_message(client_fdnode->fd, "<event type='0'/>");
                    continue; //退出
                } else if (strncmp(msgbuffer, QUIT, sizeof (QUIT)) == 0) {
                    log_write(LOG_DEBUG, "QUIT", __FILE__, __LINE__);
                    logout = 1;

                    events[i].data.fd = -1;
                    if (client_fdnode->state != FD_STATE_SUCCESS) {
                        node_del(client_fdnode);
                        continue; //退出
                    }
                } else if (strncmp(msgbuffer, POLICY, sizeof (POLICY)) == 0) {
                    printf("msg:%s, file:%s, line:%i\n", crossdomain, __FILE__, __LINE__);
                    //send_message(events[i].data.fd, crossdomain);
                    write(events[i].data.fd, crossdomain, MAX_BUFFER_LENGTH);
                    continue; //退出
                }
                log_write(LOG_DEBUG, "添加新的读任务", __FILE__, __LINE__);
                //添加新的读任务
                struct task *new_task = (struct task *) malloc(sizeof (struct task));
                if (new_task != NULL) {
                    new_task->client = client_fdnode;
                    new_task->logout = logout;
                    new_task->data = (char *) malloc(MAX_BUFFER_LENGTH * sizeof (char));
                    strcpy(new_task->data, msgbuffer);
                    new_task->next = NULL;
                    log_write(LOG_DEBUG, "new_task", __FILE__, __LINE__);
                    pthread_mutex_lock(&t_mutex);

                    if (task_head == NULL) {
                        task_head = new_task;
                    } else {
                        struct task *temp_task;
                        temp_task = task_head;
                        while (temp_task->next != NULL) {
                            temp_task = temp_task->next;
                        }
                        temp_task->next = new_task;
                    }
                    //唤醒其中一个线程即可
                    log_write(LOG_DEBUG, "唤醒所有等待cond1条件的线程", __FILE__, __LINE__);
                    pthread_cond_signal(&t_cond);

                    //唤醒所有等待cond1条件的线程
                    //log_write(LOG_DEBUG, "唤醒所有等待cond1条件的线程", __FILE__, __LINE__);
                    //pthread_cond_broadcast(&t_cond);

                    pthread_mutex_unlock(&t_mutex);
                }
            } else if (events[i].events & EPOLLOUT) {
                if (events[i].data.fd < 0) {
                    continue;
                }

                //设置用于读操作的文件描述符
                ev.data.fd = events[i].data.fd;
                //设置用于注测的读操作事件
                ev.events = EPOLLIN | EPOLLET;
                //修改sockfd上要处理的事件为EPOLIN
                epoll_ctl(epfd, EPOLL_CTL_MOD, events[i].data.fd, &ev);
            } else if (events[i].events & EPOLLRDHUP) {//tcp连接中断检测
                if (events[i].data.fd < 0) {
                    continue;
                }

                client_fdnode = fd_clients[events[i].data.fd];
                if (client_fdnode == NULL) {
                    events[i].data.fd = -1;
                    close(events[i].data.fd);
                }
                log_write(LOG_DEBUG, "EPOLLRDHUP 对方断开", __FILE__, __LINE__);

                events[i].data.fd = -1;
                node_del(client_fdnode);
                continue;

            } else if (events[i].events & EPOLLERR) {//tcp连接中断检测
                if (events[i].data.fd < 0) {
                    continue;
                }

                client_fdnode = fd_clients[events[i].data.fd];
                if (client_fdnode == NULL) {
                    events[i].data.fd = -1;
                    close(events[i].data.fd);
                }
                log_write(LOG_DEBUG, "EPOLLERR 对方断开", __FILE__, __LINE__);

                events[i].data.fd = -1;
                node_del(client_fdnode);
                continue;

            } else {
                perror("other event");
            }
            printf("一次小循环\n");
        }
    }

    close(s.listen_sockfd);
    destory();
    return (EXIT_SUCCESS);
}