2020-09-29 08:24:41 +00:00
|
|
|
#pragma once
|
2012-06-03 17:01:08 +00:00
|
|
|
|
2020-09-29 08:24:41 +00:00
|
|
|
#include <cstring>
|
2012-06-03 17:01:08 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace fd_util {
|
|
|
|
|
|
|
|
// Slow as hell and should only be used for prototyping.
|
2020-09-29 08:24:41 +00:00
|
|
|
size_t ReadLine(int fd, char *buffer, size_t buf_size);
|
2012-06-03 17:01:08 +00:00
|
|
|
|
|
|
|
// Decently fast.
|
2020-09-29 08:24:41 +00:00
|
|
|
size_t WriteLine(int fd, const char *buffer, size_t buf_size);
|
|
|
|
size_t WriteLine(int fd, const char *buffer);
|
|
|
|
size_t Write(int fd, const std::string &str);
|
2012-06-03 17:01:08 +00:00
|
|
|
|
|
|
|
// Returns true if the fd became ready, false if it didn't or
|
|
|
|
// if there was another error.
|
2016-05-26 01:53:59 +00:00
|
|
|
bool WaitUntilReady(int fd, double timeout, bool for_write = false);
|
2012-06-03 17:01:08 +00:00
|
|
|
|
|
|
|
void SetNonBlocking(int fd, bool non_blocking);
|
|
|
|
|
2016-07-03 19:38:55 +00:00
|
|
|
std::string GetLocalIP(int sock);
|
|
|
|
|
2012-06-03 17:01:08 +00:00
|
|
|
} // fd_util
|