-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
144 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "net/proxy/util/write.h" | ||
|
||
#include <utility> | ||
|
||
namespace net { | ||
namespace proxy { | ||
namespace { | ||
|
||
class WriteOperation { | ||
public: | ||
WriteOperation( | ||
Stream &stream, | ||
ConstBufferSpan buffer, | ||
absl::AnyInvocable<void(std::error_code) &&> callback); | ||
|
||
void start() { write(); } | ||
|
||
private: | ||
void write(); | ||
void finish(std::error_code ec) { std::move(callback_)(ec); } | ||
|
||
Stream &stream_; | ||
ConstBufferSpan buffer_; | ||
absl::AnyInvocable<void(std::error_code) &&> callback_; | ||
}; | ||
|
||
WriteOperation::WriteOperation( | ||
Stream &stream, | ||
ConstBufferSpan buffer, | ||
absl::AnyInvocable<void(std::error_code) &&> callback) | ||
: stream_(stream), | ||
buffer_(buffer), | ||
callback_(std::move(callback)) {} | ||
|
||
void WriteOperation::write() { | ||
stream_.write( | ||
{{buffer_.data(), buffer_.size()}}, | ||
[this](std::error_code ec, size_t size) { | ||
if (ec) { | ||
finish(ec); | ||
return; | ||
} | ||
buffer_.remove_prefix(size); | ||
if (buffer_.empty()) { | ||
finish({}); | ||
return; | ||
} | ||
write(); | ||
}); | ||
} | ||
|
||
} // namespace | ||
|
||
void write( | ||
Stream &stream, | ||
ConstBufferSpan buffer, | ||
absl::AnyInvocable<void(std::error_code) &&> callback) { | ||
auto *operation = new WriteOperation(stream, buffer, std::move(callback)); | ||
operation->start(); | ||
} | ||
|
||
} // namespace proxy | ||
} // namespace net |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef _NET_PROXY_UTIL_WRITE_H | ||
#define _NET_PROXY_UTIL_WRITE_H | ||
|
||
#include <system_error> | ||
|
||
#include "absl/functional/any_invocable.h" | ||
#include "base/types.h" | ||
#include "net/proxy/stream.h" | ||
|
||
namespace net { | ||
namespace proxy { | ||
|
||
void write( | ||
Stream &stream, | ||
ConstBufferSpan buffer, | ||
absl::AnyInvocable<void(std::error_code) &&> callback); | ||
|
||
} // namespace proxy | ||
} // namespace net | ||
|
||
#endif // _NET_PROXY_UTIL_WRITE_H |