MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / read

Method read

examples/server/httplib.h:5024–5068  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5022}
5023
5024inline ssize_t SocketStream::read(char *ptr, size_t size) {
5025#ifdef _WIN32
5026 size =
5027 (std::min)(size, static_cast<size_t>((std::numeric_limits<int>::max)()));
5028#else
5029 size = (std::min)(size,
5030 static_cast<size_t>((std::numeric_limits<ssize_t>::max)()));
5031#endif
5032
5033 if (read_buff_off_ < read_buff_content_size_) {
5034 auto remaining_size = read_buff_content_size_ - read_buff_off_;
5035 if (size <= remaining_size) {
5036 memcpy(ptr, read_buff_.data() + read_buff_off_, size);
5037 read_buff_off_ += size;
5038 return static_cast<ssize_t>(size);
5039 } else {
5040 memcpy(ptr, read_buff_.data() + read_buff_off_, remaining_size);
5041 read_buff_off_ += remaining_size;
5042 return static_cast<ssize_t>(remaining_size);
5043 }
5044 }
5045
5046 if (!is_readable()) { return -1; }
5047
5048 read_buff_off_ = 0;
5049 read_buff_content_size_ = 0;
5050
5051 if (size < read_buff_size_) {
5052 auto n = read_socket(sock_, read_buff_.data(), read_buff_size_,
5053 CPPHTTPLIB_RECV_FLAGS);
5054 if (n <= 0) {
5055 return n;
5056 } else if (n <= static_cast<ssize_t>(size)) {
5057 memcpy(ptr, read_buff_.data(), static_cast<size_t>(n));
5058 return n;
5059 } else {
5060 memcpy(ptr, read_buff_.data(), size);
5061 read_buff_off_ = size;
5062 read_buff_content_size_ = static_cast<size_t>(n);
5063 return static_cast<ssize_t>(size);
5064 }
5065 } else {
5066 return read_socket(sock_, ptr, size, CPPHTTPLIB_RECV_FLAGS);
5067 }
5068}
5069
5070inline ssize_t SocketStream::write(const char *ptr, size_t size) {
5071 if (!is_writable()) { return -1; }

Callers 15

__init__Method · 0.45
loadMethod · 0.45
must_readFunction · 0.45
lazy_load_fileFunction · 0.45
__init__Method · 0.45
loadMethod · 0.45
must_readFunction · 0.45
lazy_load_fileFunction · 0.45
clip_model_loadFunction · 0.45

Calls 3

read_socketFunction · 0.85
copyMethod · 0.80
dataMethod · 0.45

Tested by

no test coverage detected