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