1
0
Fork 0
mirror of https://gitlab.com/niansa/llama_any.git synced 2025-03-06 20:48:27 +01:00
llama_any/Sender.cpp
2023-04-06 10:00:27 +02:00

29 lines
896 B
C++

#include "Runtime.hpp"
#include "Sender.hpp"
#include "basic-coro/AwaitableTask.hpp"
#include <string_view>
#ifndef PLATFORM_WINDOWS
# include <sys/select.h>
#else
# include <ws2tcpip.h>
# include <winsock2.h>
#endif
basiccoro::AwaitableTask<Result> Sender::Simple::write(std::string_view str, bool moreData) {
co_return co_await this->write(reinterpret_cast<const std::byte*>(str.data()), str.size(), moreData);
}
basiccoro::AwaitableTask<Result> Sender::Simple::write(const std::byte *data, size_t size, bool moreData) {
std::string fres;
// Wait for socket to get ready for writing
if (co_await aMan.waitWrite(fd) == Result::Error) [[unlikely]] {
co_return Result::Error;
}
// Write
co_return (send(fd, reinterpret_cast<const char*>(data), size, MSG_FLAGS_OR_ZERO(MSG_NOSIGNAL | (int(moreData)*MSG_MORE))) < 0)?Result::Error:Result::Success;
}