56 return unix_domain_peer;
71 return _hostname + std::to_string(_port);
100 return (expiry < when);
113 static const char *
getIp(
int fd, uint16_t *
port =
nullptr,
117 static const char *
getIp(
struct sockaddr *address, uint16_t *
port=
nullptr);
120 static const char *
getIp(
struct addrinfo *address, uint16_t *
port=
nullptr);
128 if (WSAGetLastError() == WSAEWOULDBLOCK ||
129 WSAGetLastError() == WSAEINPROGRESS ||
130 WSAGetLastError() == WSAENOTCONN ||
133 if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINPROGRESS
134 || errno == EINTR || !errno)
188 struct addrinfo *localAddr=
nullptr);
200 errno_log() <<
"failed socket " << _socket;
210 bool createServerSocket();
212 static void clearCache();
219 std::string _peer_label;
221 void setSocket(
int fd) {
231 int unix_domain_peer = 0;
233 std::string _hostname;
The network engine.
Definition: engine.h:33
A simple logger. All classes that want to write to the global log file should inherit from this class...
Definition: logger.h:86
std::string label() const
Return the object's log label.
Definition: logger.h:251
static TimePoint timeMax()
Return a very distant time.
Definition: logger.h:228
std::ostream & errno_log() const
Write a line of error log after a failed system call has set the global errno to a non-zero value.
Definition: logger.cpp:143
static TimePoint timeAfter(double s)
Return current time plus s seconds.
Definition: logger.h:223
This is a slave to the Engine class. You can't use it directly, only through its subclasses,...
Definition: socket.h:18
Task * owner() const
Return task owning the socket.
Definition: socket.h:27
static bool socketInError(int fd)
Return true if the file descriptor has encountered a fatal error.
Definition: socket.cpp:204
PollState state() const
Return current socket state.
Definition: socket.h:43
static int closeSocket(int fd)
Close a file descriptor.
Definition: socket.cpp:196
virtual void setOwner(Task *t)
Set the given task as owner of the socket.
Definition: socket.h:84
int getUnixDomainPeer() const
Return the peer socket descriptor.
Definition: socket.h:55
int id() const
Return unique connection ID if connected.
Definition: socket.h:79
bool inError() const
Return true if the socket has encountered a fatal error.
Definition: socket.h:197
std::string hostname() const
Return name of the host to which the socket is supposed to connect.
Definition: socket.h:32
void setWantToSend()
Notify intention of sending large amounts of data.
Definition: socket.h:164
static bool isTempError()
Return true unless last syscall encountered a fatal error.
Definition: socket.h:126
bool hasExpired(const TimePoint &when) const
Return true if the given TimePoint is after the socket's expiry.
Definition: socket.h:99
struct addrinfo * getAddressInfo(uint16_t iptype=0)
Perform DNS lookup of remote host.
Definition: socket.cpp:100
virtual std::string cacheLabel()
Return the socket's cache group, or an empty string.
Definition: socket.h:70
virtual PollState checkReadBlock()
This will be called regularly on READ_BLOCKED sockets to check if the block can be lifted.
Definition: socket.h:153
int socket() const
Return file descriptor.
Definition: socket.h:170
void createNonBlockingSocket(struct addrinfo *addressEntry, struct addrinfo *localAddr=nullptr)
Create socket and initiate the connection.
Definition: socket.cpp:162
uint16_t port() const
Return port number to which the socket is supposed to connect.
Definition: socket.h:37
bool setNonBlocking(int fd)
Set socket as non-blocking.
Definition: socket.cpp:219
const char * localIp() const
Return local IP address in static buffer.
Definition: socket.h:104
static const char * getIp(int fd, uint16_t *port=nullptr, bool peer=true)
Return IP address of connected socket in static buffer.
Definition: socket.cpp:283
void setExpiry(double s)
Set a time to live for the socket.
Definition: socket.h:94
virtual bool wantToSend()
Return true if socket is watched for writeability.
Definition: socket.h:142
void closeMe()
Tell the network engine that the connection should be closed.
Definition: socket.h:178
The purpose of a task is to manage socket connections, and/or to execute timers.
Definition: task.h:39
Measure elapsed time during execution, for example by timer events.
PollState
Definition: pollstate.h:11