CS144---lab1

这篇博客详细介绍了CS144实验1的目标和实现,重点在于构建一个StreamReassembler,它能够将TCP传输的字节流片段重组为有序、无损的数据流。文章涵盖了StreamReassembler的构造、push_substring方法、stream_out访问接口以及unassembled_bytes方法的解释,并提供了实验结果。
摘要由CSDN通过智能技术生成

一.实验目的:

  TCP创建了一种可靠数据传输服务,其确保了一个进程从缓存中读出的数据流是无损坏,无间隙,非冗余和按序的数据流。

  在lab1中,将实现一个流重组器——一个将字节流的小段(称为字符串或段)缝合回正确序列的连续的字节流的模块。

二.代码:

stream_reassembler.hh

#ifndef SPONGE_LIBSPONGE_STREAM_REASSEMBLER_HH
#define SPONGE_LIBSPONGE_STREAM_REASSEMBLER_HH

#include "byte_stream.hh"

#include <iostream>
#include <cstdint>
#include <string>
#include <set>

//! \brief A class that assembles a series of excerpts from a byte stream (possibly out of order,
//! possibly overlapping) into an in-order byte stream.
class StreamReassembler {
  private:
    // Your code here -- add private members as necessary.
	std::set<pair<uint64_t, string> > _blocks{};
	size_t _unassembled_bytes = 0;
	size_t _head_index = 0;
	bool _eof{false};

    ByteStream _output;  //!< The reassembled in-order byte stream
    size_t _capacity;    //!< The maximum number of bytes

	pair<uint64_t, string> merge_node(pair<uint64_t, string> a, pair<uint64_t, string> b);
  public:
    //! \brief Construct a `StreamReassembler` that will store up to `capacity` bytes.
    //! \note This capacity limits both the bytes that have been reassembled,
    //! and those that have not yet been reassemble
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我是纠结伦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值