zoukankan      html  css  js  c++  java
  • 分布式对象存储 读书笔记

    todo

     

    差不多看到第二章 环境和代码编译验证 已经确认到了第四章节

    全书能正常编译测试执行完毕应该是没问题了,剩下的就是消化吸收的问题了

    近日开始着手编写验证日志 读书笔记 

    该书籍使用的GO语言作为示例

    经过验证 windows下运行curl  rabbitmq ElasticSearch 等软件都是OK的 那么就可以在windows下使用c++来进行学习 VS的调试当然更顺手

    如果时间允许的话 也许也会使用c++重写分布式对象存储实验代码

    留一段代码 以后改写C++就靠这个实现http了

    // DelMe.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
    //
    
    #include "pch.h"
    #include <iostream>
    #include <cstdlib>
    #include <iostream>
    #include <thread>
    #include <string>
    #include <utility>
    #include <boost/asio.hpp>
    
    using boost::asio::ip::tcp;
    
    const int max_length = 1024;
    
    void session(tcp::socket sock)
    {
        try
        {
            for (;;)
            {
                char data[max_length];
    
                boost::system::error_code error;
                size_t length = sock.read_some(boost::asio::buffer(data), error);
                data[max_length - 1] = '';
                for (int i = 0; i < max_length; i++) {
                    if (data[i] != '')
                        std::cout << data[i];
                }
                std::cout << std::endl;
    
                if (error == boost::asio::error::eof)
                    break; // Connection closed cleanly by peer.
                else if (error)
                    throw boost::system::system_error(error); // Some other error.
                std::string s = "HTTP/1.0 200 OK
    Server: def
    Accept-Ranges: bytes
    Content-Length: 0
    Connection: Keep-Alive
    Content-Type: text/plain
    
    111";
                boost::asio::write(sock, boost::asio::buffer(s, s.size()));
            }
        }
        catch (std::exception& e)
        {
            std::cerr << "Exception in thread: " << e.what() << "
    ";
        }
    }
    
    void server(boost::asio::io_context& io_context, unsigned short port)
    {
        tcp::acceptor a(io_context, tcp::endpoint(tcp::v4(), port));
        for (;;)
        {
            std::thread(session, a.accept()).detach();
        }
    }
    
    int main(int argc, char* argv[])
    {
        try
        {
            boost::asio::io_context io_context;
    
            server(io_context, std::atoi("9923"));
        }
        catch (std::exception& e)
        {
            std::cerr << "Exception: " << e.what() << "
    ";
        }
    
        return 0;
    }
    cpp http
    作 者: itdef
    欢迎转帖 请保持文本完整并注明出处
    技术博客 http://www.cnblogs.com/itdef/
    B站算法视频题解
    https://space.bilibili.com/18508846
    qq 151435887
    gitee https://gitee.com/def/
    欢迎c c++ 算法爱好者 windows驱动爱好者 服务器程序员沟通交流
    如果觉得不错,欢迎点赞,你的鼓励就是我的动力
    阿里打赏 微信打赏
  • 相关阅读:
    PAT 1010. 一元多项式求导 (25)
    PAT 1009. 说反话 (20) JAVA
    PAT 1009. 说反话 (20)
    PAT 1007. 素数对猜想 (20)
    POJ 2752 Seek the Name, Seek the Fame KMP
    POJ 2406 Power Strings KMP
    ZOJ3811 Untrusted Patrol
    Codeforces Round #265 (Div. 2) 题解
    Topcoder SRM632 DIV2 解题报告
    Topcoder SRM631 DIV2 解题报告
  • 原文地址:https://www.cnblogs.com/itdef/p/9597427.html
Copyright © 2011-2022 走看看