Files
ppsspp/Common/Net/Sinks.h
T
Henrik Rydgård 4f43cff5ca Move fileutil, net, image loaders, ui to Common. (#13506)
* Move and rename file_util/fd_util to Common/File/FileUtil and DirListing

Let's also move net while we're at it.

Move the ZIM/PNG loaders over to Common.

Move the UI framework into Common

iOS buildfix

* Buildfix

* Buildfixes

* Apple buildfix

* This typo again..

* UWP buildfix

* Fix build of PPSSPPQt, such as it is (it's not in good condition...)

* Guess what? Another buildfix.
2020-10-04 20:48:47 +02:00

75 lines
1.5 KiB
C++

#pragma once
#include <string>
namespace net {
class InputSink {
public:
InputSink(size_t fd);
bool ReadLine(std::string &s);
std::string ReadLine();
bool ReadLineWithEnding(std::string &s);
std::string ReadLineWithEnding();
// Read exactly this number of bytes, or fail.
bool TakeExact(char *buf, size_t bytes);
// Read whatever is convenient (may even return 0 bytes when there's more coming eventually.)
size_t TakeAtMost(char *buf, size_t bytes);
// Skip exactly this number of bytes, or fail.
bool Skip(size_t bytes);
bool Empty();
bool TryFill();
private:
void Fill();
bool Block();
void AccountFill(int bytes);
void AccountDrain(size_t bytes);
size_t FindNewline() const;
static const size_t BUFFER_SIZE = 32 * 1024;
static const size_t PRESSURE = 8 * 1024;
size_t fd_;
char buf_[BUFFER_SIZE];
size_t read_;
size_t write_;
size_t valid_;
};
class OutputSink {
public:
OutputSink(size_t fd);
bool Push(const std::string &s);
bool Push(const char *buf, size_t bytes);
size_t PushAtMost(const char *buf, size_t bytes);
bool PushCRLF(const std::string &s);
bool Printf(const char *fmt, ...);
bool Flush(bool allowBlock = true);
void Discard();
bool Empty();
private:
void Drain();
bool Block();
void AccountPush(size_t bytes);
void AccountDrain(int bytes);
static const size_t BUFFER_SIZE = 32 * 1024;
static const size_t PRESSURE = 8 * 1024;
size_t fd_;
char buf_[BUFFER_SIZE];
size_t read_;
size_t write_;
size_t valid_;
};
};