asan target, Reset() methods, fix EAGAIN handling
This commit is contained in:
4
Makefile
4
Makefile
@@ -13,3 +13,7 @@ firebuf.a: $(objects)
|
|||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm --force *.o *.a
|
rm --force *.o *.a
|
||||||
|
|
||||||
|
asan:
|
||||||
|
$(MAKE) clean
|
||||||
|
FIRE_CXXFLAGS="-O1 -g -fsanitize=address -fno-omit-frame-pointer -std=gnu++2a -Wall -Werror" $(MAKE) all
|
||||||
|
|||||||
11
buffer.cc
11
buffer.cc
@@ -35,6 +35,10 @@ void ConstBuffer::Commit() {
|
|||||||
commit_ = start_;
|
commit_ = start_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConstBuffer::Reset() {
|
||||||
|
commit_ = start_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Buffer::Buffer(char *buf, size_t size, size_t len)
|
Buffer::Buffer(char *buf, size_t size, size_t len)
|
||||||
: ConstBuffer(buf, size),
|
: ConstBuffer(buf, size),
|
||||||
@@ -65,7 +69,7 @@ bool Buffer::Write(const std::string_view& str) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffer::Wrote(size_t len) {
|
void Buffer::Wrote(ssize_t len) {
|
||||||
CHECK_LE(len, WriteMaxLen());
|
CHECK_LE(len, WriteMaxLen());
|
||||||
len_ += len;
|
len_ += len;
|
||||||
}
|
}
|
||||||
@@ -80,4 +84,9 @@ void Buffer::Consume() {
|
|||||||
commit_ = 0;
|
commit_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Buffer::Reset() {
|
||||||
|
ConstBuffer::Reset();
|
||||||
|
len_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace firebuf
|
} // namespace firebuf
|
||||||
|
|||||||
6
buffer.h
6
buffer.h
@@ -18,6 +18,8 @@ class ConstBuffer {
|
|||||||
void ResetRead(); // next read from last commit
|
void ResetRead(); // next read from last commit
|
||||||
void Commit(); // commit read position
|
void Commit(); // commit read position
|
||||||
|
|
||||||
|
virtual void Reset(); // full reset
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const char *const_buf_;
|
const char *const_buf_;
|
||||||
size_t len_;
|
size_t len_;
|
||||||
@@ -33,10 +35,12 @@ class Buffer : public ConstBuffer {
|
|||||||
[[nodiscard]] char *WritePtr();
|
[[nodiscard]] char *WritePtr();
|
||||||
[[nodiscard]] size_t WriteMaxLen() const;
|
[[nodiscard]] size_t WriteMaxLen() const;
|
||||||
bool Write(const std::string_view& str);
|
bool Write(const std::string_view& str);
|
||||||
void Wrote(size_t len);
|
void Wrote(ssize_t len);
|
||||||
|
|
||||||
void Consume(); // discard up to last commit
|
void Consume(); // discard up to last commit
|
||||||
|
|
||||||
|
void Reset() override; // full reset
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::unique_ptr<char[]> own_buf_;
|
std::unique_ptr<char[]> own_buf_;
|
||||||
char *buf_;
|
char *buf_;
|
||||||
|
|||||||
@@ -8,6 +8,13 @@ StreamBuffer::StreamBuffer(int sock, size_t size)
|
|||||||
|
|
||||||
bool StreamBuffer::Refill() {
|
bool StreamBuffer::Refill() {
|
||||||
auto read_len = read(sock_, WritePtr(), WriteMaxLen());
|
auto read_len = read(sock_, WritePtr(), WriteMaxLen());
|
||||||
|
if (read_len == -1) {
|
||||||
|
if (errno == EINTR) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
PLOG(ERROR) << "read()";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (read_len == 0) {
|
if (read_len == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user