Commit ffdf1c917a0f22db8c88dee8cd17886302864a79
1 parent
73ef26ae
Read buf fixes
Showing
2 changed files
with
7 additions
and
1 deletions
client.cpp
| ... | ... | @@ -40,7 +40,7 @@ bool Client::readFdIntoBuffer() |
| 40 | 40 | { |
| 41 | 41 | wi += n; |
| 42 | 42 | |
| 43 | - if (getReadBufBytesUsed() >= readBufsize) | |
| 43 | + if (getReadBufMaxWriteSize() == 0) | |
| 44 | 44 | { |
| 45 | 45 | growReadBuffer(); |
| 46 | 46 | } |
| ... | ... | @@ -53,12 +53,16 @@ bool Client::readFdIntoBuffer() |
| 53 | 53 | if (errno == EAGAIN || errno == EWOULDBLOCK) |
| 54 | 54 | break; |
| 55 | 55 | else |
| 56 | + { | |
| 57 | + std::cerr << strerror(errno) << std::endl; | |
| 56 | 58 | return false; |
| 59 | + } | |
| 57 | 60 | } |
| 58 | 61 | } |
| 59 | 62 | |
| 60 | 63 | if (n == 0) // client disconnected. |
| 61 | 64 | { |
| 65 | + std::cerr << "normal disconnect" << std::endl; | |
| 62 | 66 | return false; |
| 63 | 67 | } |
| 64 | 68 | ... | ... |
client.h
| ... | ... | @@ -42,6 +42,7 @@ class Client |
| 42 | 42 | ThreadData_p threadData; |
| 43 | 43 | std::mutex writeBufMutex; |
| 44 | 44 | |
| 45 | + // Note: this is not the inverse of free space, because there can be non-used lead-in in the buffer! | |
| 45 | 46 | size_t getReadBufBytesUsed() |
| 46 | 47 | { |
| 47 | 48 | return wi - ri; |
| ... | ... | @@ -68,6 +69,7 @@ class Client |
| 68 | 69 | return available; |
| 69 | 70 | } |
| 70 | 71 | |
| 72 | + // Note: this is not the inverse of free space, because there can be non-used lead-in in the buffer! | |
| 71 | 73 | size_t getWriteBufBytesUsed() |
| 72 | 74 | { |
| 73 | 75 | return wwi - wri; | ... | ... |