Giter Club home page Giter Club logo

Comments (7)

awen162 avatar awen162 commented on May 14, 2024 1

两种情况对比测试发现,在result.h头文件中,调用如下的左值和右值函数,导致一个使用移动构造,一个使用赋值构造。 具体要如何修复,我也不是很清楚。
wait_for 调用了第一个函数进行结果赋值,将return *res,修改为return std::move(*res)测试可以,但是不清楚会不会带来其它问题。 非wait_for 调用了第二个函数进行结果赋值

constexpr T result() & {
        if (auto exception = std::get_if<std::exception_ptr>(&result_)) {
            std::rethrow_exception(*exception);
        }
        if (auto res = std::get_if<T>(&result_)) {
            return *res;
        }
        throw NoResultError{};
    }
    constexpr T result() && {
        if (auto exception = std::get_if<std::exception_ptr>(&result_)) {
            std::rethrow_exception(*exception);
        }
        if (auto res = std::get_if<T>(&result_)) {
            return std::move(*res);
        }
        throw NoResultError{};
    }

那应该就是这一行的问题了: https://github.com/netcan/asyncio/blob/master/include/asyncio/wait_for.h#L21

改成:

return std::move(result_).result();

然后所有测试通过的话,应该就没问题了。

按照你给的修改方案,58个测试用例测试都可以了。wait_for那里也没有再使用赋值构造了,直接使用了移动构造。

from asyncio.

netcan avatar netcan commented on May 14, 2024

看样子是发生了越界读,原因是客户端发送的字符串少发了'\0'。已经修复,可以参考这个提交。
1481361#diff-4a4b47f02ae41b2a8b7e9512e447950c24862dfe67049798ff0653c047e210caR15

from asyncio.

awen162 avatar awen162 commented on May 14, 2024

谢谢答复!
有个疑问:没有修改echo_client代码前,测试没有问题。那里也是没有添加结束符的。现在就改调用wait_for就有问题了,这里面有没有可能还有其它问题?
麻烦帮忙分析下,或者有什么方法进行分析,我可以尝试去分析下,谢谢!

from asyncio.

awen162 avatar awen162 commented on May 14, 2024

另外发现个问题:
auto data = co_await stream.read(100); 中,data.data()的地址,与stream.read中分配的result.data()地址一致。说明是使用了移动构造。
auto data = co_await asyncio::wait_for(stream.read(100), 300ms);中,data.data()的地址,与stream.read中分配的result.data()地址不是一致。说明是使用了拷贝或者赋值构造,这里是否可以优化下?

from asyncio.

netcan avatar netcan commented on May 14, 2024

另外发现个问题: auto data = co_await stream.read(100); 中,data.data()的地址,与stream.read中分配的result.data()地址一致。说明是使用了移动构造。 auto data = co_await asyncio::wait_for(stream.read(100), 300ms);中,data.data()的地址,与stream.read中分配的result.data()地址不是一致。说明是使用了拷贝或者赋值构造,这里是否可以优化下?

你分析的对,中间应该是发生了拷贝构造。可以优化,得找出发生拷贝构造的时机点,然后通过完美转发之类的移动。暂时没时间改,你可以尝试提下PR,或者等我后续修复也行。

from asyncio.

awen162 avatar awen162 commented on May 14, 2024

两种情况对比测试发现,在result.h头文件中,调用如下的左值和右值函数,导致一个使用移动构造,一个使用赋值构造。
具体要如何修复,我也不是很清楚。

wait_for 调用了第一个函数进行结果赋值,将return *res,修改为return std::move(*res)测试可以,但是不清楚会不会带来其它问题。
非wait_for 调用了第二个函数进行结果赋值

constexpr T result() & {
        if (auto exception = std::get_if<std::exception_ptr>(&result_)) {
            std::rethrow_exception(*exception);
        }
        if (auto res = std::get_if<T>(&result_)) {
            return *res;
        }
        throw NoResultError{};
    }
    constexpr T result() && {
        if (auto exception = std::get_if<std::exception_ptr>(&result_)) {
            std::rethrow_exception(*exception);
        }
        if (auto res = std::get_if<T>(&result_)) {
            return std::move(*res);
        }
        throw NoResultError{};
    }

from asyncio.

netcan avatar netcan commented on May 14, 2024

两种情况对比测试发现,在result.h头文件中,调用如下的左值和右值函数,导致一个使用移动构造,一个使用赋值构造。 具体要如何修复,我也不是很清楚。

wait_for 调用了第一个函数进行结果赋值,将return *res,修改为return std::move(*res)测试可以,但是不清楚会不会带来其它问题。 非wait_for 调用了第二个函数进行结果赋值

constexpr T result() & {
        if (auto exception = std::get_if<std::exception_ptr>(&result_)) {
            std::rethrow_exception(*exception);
        }
        if (auto res = std::get_if<T>(&result_)) {
            return *res;
        }
        throw NoResultError{};
    }
    constexpr T result() && {
        if (auto exception = std::get_if<std::exception_ptr>(&result_)) {
            std::rethrow_exception(*exception);
        }
        if (auto res = std::get_if<T>(&result_)) {
            return std::move(*res);
        }
        throw NoResultError{};
    }

那应该就是这一行的问题了:
https://github.com/netcan/asyncio/blob/master/include/asyncio/wait_for.h#L21

改成:

return std::move(result_).result();

然后所有测试通过的话,应该就没问题了。

from asyncio.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.