分布式对象存储 读书笔记

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] = '\0';
            for (int i = 0; i < max_length; i++) {
                if (data[i] != '\0')
                    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\r\nServer: def\r\nAccept-Ranges: bytes\r\nContent-Length: 0\r\nConnection: Keep-Alive\r\nContent-Type: text/plain\r\n\r\n111";
            boost::asio::write(sock, boost::asio::buffer(s, s.size()));
        }
    }
    catch (std::exception& e)
    {
        std::cerr << "Exception in thread: " << e.what() << "\n";
    }
}

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() << "\n";
    }

    return 0;
}
cpp http
复制代码

 

posted on   itdef  阅读(213)  评论(0编辑  收藏  举报

编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示