30 #define HT_DISABLE_LOG_DEBUG 1
46 #include <netinet/tcp.h>
47 #include <sys/types.h>
48 #include <sys/socket.h>
49 #include <netinet/in.h>
50 #include <arpa/inet.h>
62 if (event->revents & POLLIN)
63 return handle_incoming_connection();
71 #if defined(__APPLE__) || defined(__FreeBSD__)
75 if (event->filter == EVFILT_READ)
76 return handle_incoming_connection();
80 #elif defined(__linux__)
84 return handle_incoming_connection();
86 #elif defined(__sun__)
89 if (event->portev_events == POLLIN)
90 return handle_incoming_connection();
102 struct sockaddr_in addr;
103 socklen_t addr_len =
sizeof(sockaddr_in);
109 if ((sd = accept(m_sd, (
struct sockaddr *)&addr, &addr_len)) < 0) {
112 HT_ERRORF(
"accept() failure: %s", strerror(errno));
116 HT_DEBUGF(
"Just accepted incoming connection, fd=%d (%s:%d)",
117 m_sd, inet_ntoa(addr.sin_addr), ntohs(addr.sin_port));
122 #if defined(__linux__)
123 if (setsockopt(sd, SOL_TCP, TCP_NODELAY, &one,
sizeof(one)) < 0)
124 HT_WARNF(
"setsockopt(TCP_NODELAY) failure: %s", strerror(errno));
125 #elif defined(__sun__)
126 if (setsockopt(sd, IPPROTO_TCP, TCP_NODELAY, (
char*)&one,
sizeof(one)) < 0)
127 HT_ERRORF(
"setting TCP_NODELAY: %s", strerror(errno));
128 #elif defined(__APPLE__) || defined(__FreeBSD__)
129 if (setsockopt(sd, SOL_SOCKET, SO_NOSIGPIPE, &one,
sizeof(one)) < 0)
130 HT_WARNF(
"setsockopt(SO_NOSIGPIPE) failure: %s", strerror(errno));
133 if (setsockopt(m_sd, SOL_SOCKET, SO_KEEPALIVE, &one,
sizeof(one)) < 0)
134 HT_ERRORF(
"setsockopt(SO_KEEPALIVE) failure: %s", strerror(errno));
136 int bufsize = 4*32768;
138 if (setsockopt(sd, SOL_SOCKET, SO_SNDBUF, (
char *)&bufsize,
sizeof(bufsize)) < 0)
139 HT_WARNF(
"setsockopt(SO_SNDBUF) failed - %s", strerror(errno));
141 if (setsockopt(sd, SOL_SOCKET, SO_RCVBUF, (
char *)&bufsize,
sizeof(bufsize)) < 0)
142 HT_WARNF(
"setsockopt(SO_RCVBUF) failed - %s", strerror(errno));
145 m_handler_factory->get_instance(dhp);
149 m_handler_map->insert_handler(handler,
true);
154 HT_ERRORF(
"Problem starting polling on incoming connection - %s",
164 HT_ERRORF(
"Problem sending proxy map to %s - %s",
174 deliver_event(event);
int start_polling(int mode=PollEvent::READ)
Start polling on the handler with the poll interest specified in mode.
#define HT_WARNF(msg,...)
chrono::time_point< fast_clock > time_point
Declarations for ReactorRunner.
std::shared_ptr< Event > EventPtr
Smart pointer to Event.
Connection established event.
static HandlerMapPtr handler_map
Smart pointer to HandlerMap.
File system utility functions.
Declarations for IOHandlerAccept.
const char * get_text(int error)
Returns a descriptive error message.
Logging routines and macros.
Compatibility Macros for C/C++.
I/O handler for TCP sockets.
bool handle_incoming_connection()
Handles incoming connection requests.
Declarations for HandlerMap.
Declarations for IOHandlerData.
static bool set_flags(int fd, int flags)
Sets fcntl flags of a socket.
#define HT_DEBUGF(msg,...)
Writing can be performed without blocking.
Declarations for ReactorFactory.
std::shared_ptr< DispatchHandler > DispatchHandlerPtr
Smart pointer to DispatchHandler.
#define HT_ERRORF(msg,...)
Error codes, Exception handling, error logging.
bool handle_event(struct pollfd *event, ClockT::time_point arrival_time) override
Handle poll() interface events.
static bool proxy_master
Set to true if this process is acting as "Proxy Master".