示例#1
0
文件: main.cpp 项目: songinfo/project
int main(void)
{
	//
	std::string filepath = "/home/chao/Desktop/project/spellcorrect/conf/my.conf";
	MyConf myconf(filepath);
	myconf.init();
	myconf.show();

	std::map<std::string, std::string> my_map = myconf.get_map();
	std::string sip = my_map["server_ip"];
	std::string sport = my_map["server_port"];
	std::stringstream ss(sport);
	int iport = 0;
	ss >> iport;
	std::cout << iport << std::endl;

	ThreadPool thp(50, 10);
	thp.start();



	InetAddress inetAddr(sip, iport);
	Socket mySocket;
	mySocket.init(0, inetAddr);

	int listenfd = mySocket.get_sockfd();

	epoll_t et;
	epoll_init(&et, listenfd, &foo );
	while(1)
	{
		epoll_loop(&et);
		epoll_handle_fd(&et, thp);

	}

	epoll_destroy(&et);

	return 0;
}
示例#2
0
int main (void)
{
    int err;
    struct sockaddr addr;
    socklen_t alen = sizeof(addr);
    int lsocket, s, count;
    char buf[C_CMD_BUF_SIZE];
    MNLD_DATA_T *obj = &mnld_data;

    lsocket = android_get_control_socket(SOCKET_MNL);
    if (lsocket < 0) {
        MND_ERR("fail to get socket from environment: %s\n",strerror(errno));
        exit(1);
    }
    if (listen(lsocket, 5)) {
        MND_ERR("listen on socket failed: %s\n", strerror(errno));
        exit(1);
    }
    if (setup_signal_handler()) {
        MND_ERR("setup_signal_handler: %d (%s)\n", errno, strerror(errno));
        exit(1);
    }
    if (mnl_init()) {
        MND_ERR("mnl_init: %d (%s)\n", errno, strerror(errno));
        exit(1);
    }
    MND_MSG("listening..\n");
    while(1) {
        int eof, s = accept(lsocket, &addr, &alen);
        if (s < 0) {
            MND_ERR("Accept failed!! :%s\n", strerror(errno));
            continue;
        }
        obj->cur_accept_socket = s;
        fcntl(s, F_SETFD, FD_CLOEXEC);

        if (epoll_init()) {
            MND_ERR("epoll_init: %d (%s)\n", errno, strerror(errno));
            exit(1);
        }
        MND_MSG("new connection\n");
        for (;;) {
            err = process();
            if (err == ERR_REMOTE_HANGUP) {
                MND_ERR("remote hangup (cleanup?), wait for new connection\n");
                break;
            } else if (err == ERR_MNL_DIED) {
                MND_ERR("mnl process died, kill it\n");
                kill_mnl_process();
            } else if (errno == EINTR) {
                continue;
            } else if (err) {
                MND_ERR("process data error: %d (%s)\n", errno, strerror(errno));
            }
        }
        MND_MSG("closing connection\n");
        close(s);
        epoll_destroy();
    }
    MND_MSG("exit mnld \n!!");
    return 0;
}