288632 {
288633#ifdef _WIN32
288635 (std::min)(size, static_cast<size_t>((std::numeric_limits<int>::max)()));
288636#else
288637 size = (std::min)(size,
288638 static_cast<size_t>((std::numeric_limits<ssize_t>::max)()));
288639#endif
288640
288641 if (read_buff_off_ < read_buff_content_size_) {
288642 auto remaining_size = read_buff_content_size_ - read_buff_off_;
288643 if (size <= remaining_size) {
288644 memcpy(ptr, read_buff_.data() + read_buff_off_, size);
288645 read_buff_off_ +=
size;
288646 return static_cast<ssize_t
>(
size);
288647 } else {
288648 memcpy(ptr, read_buff_.data() + read_buff_off_, remaining_size);
288649 read_buff_off_ += remaining_size;
288650 return static_cast<ssize_t>(remaining_size);
288651 }
288652 }
288653
288654 if (!wait_readable()) { return -1; }
288655
288656 read_buff_off_ = 0;
288657 read_buff_content_size_ = 0;
288658
288659 if (size < read_buff_size_) {
288660 auto n = read_socket(sock_, read_buff_.data(), read_buff_size_,
288661 CPPHTTPLIB_RECV_FLAGS);
288662 if (n <= 0) {
288663 return n;
288664 } else if (n <= static_cast<ssize_t>(size)) {
288665 memcpy(ptr, read_buff_.data(), static_cast<size_t>(n));
288666 return n;
288667 } else {
288668 memcpy(ptr, read_buff_.data(), size);
288669 read_buff_off_ =
size;
288670 read_buff_content_size_ = static_cast<size_t>(n);
288671 return static_cast<ssize_t
>(
size);
288672 }
288673 } else {
288674 return read_socket(sock_, ptr, size, CPPHTTPLIB_RECV_FLAGS);
288675 }
288676}
GOpaque< Size > size(const GMat &src)