22 #include <arpa/inet.h> 23 #include <netinet/tcp.h> 40 socklen_t len =
sizeof(name);
41 int res = ::getsockname(
getSocketFD(), (sockaddr*)&name, &len);
50 inet_ntop(AF_INET, &name.sin_addr, buf,
sizeof(buf));
51 return std::string(buf);
54 bool URServer::open(
int socket_fd,
struct sockaddr* address,
size_t address_len)
57 setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &flag,
sizeof(
int));
58 return ::bind(socket_fd, address, address_len) == 0;
87 LOG_ERROR(
"Accepting socket connection failed. (errno: %d)", errno);
112 char* current_pointer = buffer;
116 if (buf_len <= 0 || buffer ==
NULL)
126 if (total_read < buf_len - 1)
129 *current_pointer++ = ch;
149 *current_pointer =
'\0';
virtual bool open(int socket_fd, struct sockaddr *address, size_t address_len)
bool read(char *character)
bool readLine(char *buffer, size_t buf_len)
bool write(const uint8_t *buf, size_t buf_len, size_t &written)
virtual void setOptions(int socket_fd)
bool setSocketFD(int socket_fd)
bool write(const uint8_t *buf, size_t buf_len, size_t &written)
bool setup(std::string &host, int port)
#define LOG_ERROR(format,...)