Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BuffGetData: better handle the case of wait=false #1522

Merged
merged 1 commit into from
Sep 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 27 additions & 7 deletions src/XrdHttp/XrdHttpProtocol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1415,19 +1415,39 @@ void XrdHttpProtocol::BuffConsume(int blen) {
/******************************************************************************/

/// Get a pointer, valid for up to blen bytes from the buffer. Returns the n
/// of bytes that one is allowed to read

/// of bytes that one is allowed to use in the *data block
/// If wait = true then the call may wait for the data to come from the socket
/// If wait = false then the call returns:
/// - what's in the buffer if there's anything in the buffer
/// - what can be read from the socket without waiting
/// In this case an error will return -1, instead the absence of data
/// will return 0
int XrdHttpProtocol::BuffgetData(int blen, char **data, bool wait) {
int rlen;

TRACE(DEBUG, "BuffgetData: requested " << blen << " bytes");

if (wait && (blen > BuffUsed())) {
TRACE(REQ, "BuffgetData: need to read " << blen - BuffUsed() << " bytes");
if ( getDataOneShot(blen - BuffUsed(), true) ) return 0;


if (wait) {
// If there's not enough data in the buffer then wait on the socket until it comes
if (blen > BuffUsed()) {
TRACE(REQ, "BuffgetData: need to read " << blen - BuffUsed() << " bytes");
if ( getDataOneShot(blen - BuffUsed(), true) )
// The wanted data could not be read. Either timeout of connection closed
return 0;
}
} else {
// Get a peek at the socket, without waiting, if we have no data in the buffer
if ( !BuffUsed() ) {
if ( getDataOneShot(blen, false) )
// The wanted data could not be read. Either timeout of connection closed
return -1;
}
}

if (myBuffStart < myBuffEnd) {
// And now make available the data taken from the buffer. Note that the buffer
// may be empty...
if (myBuffStart <= myBuffEnd) {
rlen = min( (long) blen, (long)(myBuffEnd - myBuffStart) );

} else
Expand Down