GithubHelp home page GithubHelp logo

环形buffer有问题 about gear-lib HOT 2 CLOSED

gozfree avatar gozfree commented on August 27, 2024
环形buffer有问题

from gear-lib.

Comments (2)

weixuechao2018 avatar weixuechao2018 commented on August 27, 2024

ssize_t rb_write(struct ringbuffer *rb, const void *buf, size_t len)
{
if (!rb) {
return -1;
}
int left = rb_get_space_free(rb);
if ((int)len > left) {
printf("Not enough space: %zu request, %d available\n", len, left);
return -1;
}
// 这里修改过
#if 1
if((rb->length - rb->end) < len) {
int firstLen = rb->length - rb->end;
memcpy(rb_end_ptr(rb), buf, firstLen);
rb->end = (rb->end + firstLen) % rb->length;

    int secondLen = len - firstLen;
    memcpy(rb_end_ptr(rb), buf+firstLen, secondLen);
    rb->end = (rb->end + secondLen) % rb->length;
} else {
    memcpy(rb_end_ptr(rb), buf, len);
    rb->end = (rb->end + len) % rb->length;
}

#else
memcpy(rb_end_ptr(rb), buf, len);
rb->end = (rb->end + len) % rb->length;
#endif

return len;

}
这样改的,我测试了可以循环写,不知道对不对

from gear-lib.

gozfree avatar gozfree commented on August 27, 2024

非常感谢,你是对的,已经fix了
b916cf6

from gear-lib.

Related Issues (20)

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.