<commit_before>/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *                    _______    _                                     *
 *                   (  ____ \  ( \     |\     /|                      * 
 *                   | (    \/  | (     ( \   / )                      *
 *                   | (__      | |      \ (_) /                       *
 *                   |  __)     | |       \   /                        *
 *                   | (        | |        ) (                         *
 *                   | )        | (____/\  | |                         *
 *                   |/         (_______/  \_/                         *
 *                                                                     *
 *                                                                     *
 *     fly is an awesome c++11 network library.                        *
 *                                                                     *
 *   @author: lichuan                                                  *
 *   @qq: 308831759                                                    *
 *   @email: <EMAIL>                                          *
 *   @github: https://github.com/lichuan/fly                           *
 *   @date: 2015-06-10 13:34:21                                        *
 *                                                                     *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include <unistd.h>
#include "fly/init.hpp"
#include "fly/net/client.hpp"
#include "fly/base/logger.hpp"

using namespace std::placeholders;
using fly::net::Json;

class Test_Client : public fly::base::Singleton<Test_Client>
{
public:
    void init(std::shared_ptr<fly::net::Connection<Json>> connection)
    {
        rapidjson::Document doc;
        doc.SetObject();
        rapidjson::Document::AllocatorType &allocator = doc.GetAllocator();
        doc.AddMember("msg_type", 9922, allocator); 
        doc.AddMember("msg_cmd", 2223333, allocator);
        connection->send(doc);
    }
    
    void dispatch(std::unique_ptr<fly::net::Message<Json>> connection)
    {
        CONSOLE_LOG_INFO("disaptch message");
    }
    
    void close(std::shared_ptr<fly::net::Connection<Json>> connection)
    {
        CONSOLE_LOG_INFO("close connection from %s:%d", connection->peer_addr().m_host.c_str(), connection->peer_addr().m_port);
    }
    
    void be_closed(std::shared_ptr<fly::net::Connection<Json>> connection)
    {
        CONSOLE_LOG_INFO("connection from %s:%d be closed", connection->peer_addr().m_host.c_str(), connection->peer_addr().m_port);
    }
    
    void main()
    {
        //init library
        fly::init();
        
        //init logger
        fly::base::Logger::instance()->init(fly::base::DEBUG, "client", "./log/");

        std::shared_ptr<fly::net::Poller<Json>> poller(new fly::net::Poller<Json>(4));
        std::shared_ptr<fly::net::Parser<Json>> parser(new fly::net::Parser<Json>(4));
        
        poller->start();
        parser->start();
        
        int i = 1;
        while(i-- > 0)
        {
            
            std::unique_ptr<fly::net::Client<Json>> client(new fly::net::Client<Json>(fly::net::Addr("askcoin.me", 80),
                                                                          std::bind(&Test_Client::init, this, _1),
                                                                          std::bind(&Test_Client::dispatch, this, _1),
                                                                          std::bind(&Test_Client::close, this, _1),
                                                                          std::bind(&Test_Client::be_closed, this, _1),
                                                                          poller, parser));
            if(client->connect(1000))<commit_msg>test local ip<commit_after>/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *                    _______    _                                     *
 *                   (  ____ \  ( \     |\     /|                      * 
 *                   | (    \/  | (     ( \   / )                      *
 *                   | (__      | |      \ (_) /                       *
 *                   |  __)     | |       \   /                        *
 *                   | (        | |        ) (                         *
 *                   | )        | (____/\  | |                         *
 *                   |/         (_______/  \_/                         *
 *                                                                     *
 *                                                                     *
 *     fly is an awesome c++11 network library.                        *
 *                                                                     *
 *   @author: lichuan                                                  *
 *   @qq: 308831759                                                    *
 *   @email: <EMAIL>                                          *
 *   @github: https://github.com/lichuan/fly                           *
 *   @date: 2015-06-10 13:34:21                                        *
 *                                                                     *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include <unistd.h>
#include "fly/init.hpp"
#include "fly/net/client.hpp"
#include "fly/base/logger.hpp"

using namespace std::placeholders;
using fly::net::Json;

class Test_Client : public fly::base::Singleton<Test_Client>
{
public:
    void init(std::shared_ptr<fly::net::Connection<Json>> connection)
    {
        rapidjson::Document doc;
        doc.SetObject();
        rapidjson::Document::AllocatorType &allocator = doc.GetAllocator();
        doc.AddMember("msg_type", 9922, allocator); 
        doc.AddMember("msg_cmd", 2223333, allocator);
        connection->send(doc);
    }
    
    void dispatch(std::unique_ptr<fly::net::Message<Json>> connection)
    {
        CONSOLE_LOG_INFO("disaptch message");
    }
    
    void close(std::shared_ptr<fly::net::Connection<Json>> connection)
    {
        CONSOLE_LOG_INFO("close connection from %s:%d", connection->peer_addr().m_host.c_str(), connection->peer_addr().m_port);
    }
    
    void be_closed(std::shared_ptr<fly::net::Connection<Json>> connection)
    {
        CONSOLE_LOG_INFO("connection from %s:%d be closed", connection->peer_addr().m_host.c_str(), connection->peer_addr().m_port);
    }
    
    void main()
    {
        //init library
        fly::init();
        
        //init logger
        fly::base::Logger::instance()->init(fly::base::DEBUG, "client", "./log/");

        std::shared_ptr<fly::net::Poller<Json>> poller(new fly::net::Poller<Json>(4));
        std::shared_ptr<fly::net::Parser<Json>> parser(new fly::net::Parser<Json>(4));
        
        poller->start();
        parser->start();
        
        int i = 1;
        while(i-- > 0)
        {
            
            std::unique_ptr<fly::net::Client<Json>> client(new fly::net::Client<Json>(fly::net::Addr("127.0.0.1", 8088),
                                                                          std::bind(&Test_Client::init, this, _1),
                                                                          std::bind(&Test_Client::dispatch, this, _1),
                                                                          std::bind(&Test_Client::close, this, _1),
                                                                          std::bind(&Test_Client::be_closed, this, _1),
                                                                          poller, parser));
            if(client->connect(1000))
{'fraction_non_alphanumeric': 0.14280160684203705, 'fraction_numerical': 0.01399507580666062, 'mean_word_length': 0.9475145092101943, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 63, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 100, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3669848', 'n_tokens_mistral': 2024, 'n_tokens_neox': 1904, 'n_words': 239}