no message

master
zcy 2021-05-16 02:42:39 +08:00
parent d628355dcd
commit fd1e17400d
1 changed files with 5 additions and 5 deletions

View File

@ -157,7 +157,7 @@ int RingBuffer<T>::Take(T *data,uint64_t len){
if(mCurrentTail >= mCurrentHead){
memcpy(data,&mData[mCurrentHead],sizeof(T)*bytes_read);
mCurrentHead += bytes_read;
mRemain = mCurrentTail - mCurrentHead;
mRemain = mSize - (mCurrentTail - mCurrentHead);
return bytes_read;
}
@ -167,21 +167,21 @@ int RingBuffer<T>::Take(T *data,uint64_t len){
if(off > mSize){
int tmp = mSize - mCurrentHead;
memcpy(data,&mData[mCurrentHead],(mSize - mCurrentHead)*sizeof(T));
memcpy(data + (mSize - mCurrentHead)*sizeof(T),&mData[0],(bytes_read - tmp)*sizeof(T));
memcpy(&data[mSize - mCurrentHead],&mData[0],(bytes_read - tmp)*sizeof(T));
mCurrentHead = off - mSize;
mRemain = mCurrentTail - mCurrentHead;
mRemain = mSize - (mCurrentTail - mCurrentHead);
return bytes_read;
}
if(off <= mSize){
memcpy(data,&mData[mCurrentHead],sizeof(T)*bytes_read);
if(off == mSize){
mCurrentHead = 0;
mRemain = mCurrentTail;
mRemain = mSize - mCurrentTail;
return bytes_read;
}
else{
mCurrentHead += bytes_read;
mRemain = (mSize - mCurrentHead) + mCurrentTail;
mRemain = mSize - ((mSize - mCurrentHead) + mCurrentTail);
return bytes_read;
}
}