int addressfamily = AF_UNSPEC;
int maxtimeout = 900;
int seconds_till_retry = 5;
+int udp_rcvbuf = 0;
+int udp_sndbuf = 0;
listen_socket_t listen_socket[MAXSOCKETS];
int listen_sockets;
static void configure_tcp(connection_t *c) {
int option;
-#ifdef O_NONBLOCK
- int flags = fcntl(c->socket, F_GETFL);
-
- if(fcntl(c->socket, F_SETFL, flags | O_NONBLOCK) < 0) {
- logger(LOG_ERR, "fcntl for %s: %s", c->hostname, strerror(errno));
- }
-#elif defined(WIN32)
- unsigned long arg = 1;
-
- if(ioctlsocket(c->socket, FIONBIO, &arg) != 0) {
- logger(LOG_ERR, "ioctlsocket for %s: %d", c->hostname, sockstrerror(sockerrno));
- }
-#endif
-
#if defined(SOL_TCP) && defined(TCP_NODELAY)
option = 1;
setsockopt(c->socket, SOL_TCP, TCP_NODELAY, (void *)&option, sizeof option);
return -1;
}
-#ifdef O_NONBLOCK
- {
- int flags = fcntl(nfd, F_GETFL);
-
- if(fcntl(nfd, F_SETFL, flags | O_NONBLOCK) < 0) {
- closesocket(nfd);
- logger(LOG_ERR, "System call `%s' failed: %s", "fcntl",
- strerror(errno));
- return -1;
- }
- }
-#elif defined(WIN32)
- {
- unsigned long arg = 1;
- if(ioctlsocket(nfd, FIONBIO, &arg) != 0) {
- closesocket(nfd);
- logger(LOG_ERR, "Call to `%s' failed: %s", "ioctlsocket", sockstrerror(sockerrno));
- return -1;
- }
- }
-#endif
-
option = 1;
setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, (void *)&option, sizeof option);
+ if(udp_rcvbuf && setsockopt(nfd, SOL_SOCKET, SO_RCVBUF, (void *)&udp_rcvbuf, sizeof(udp_rcvbuf)))
+ logger(LOG_WARNING, "Can't set UDP SO_RCVBUF to %i: %s", udp_rcvbuf, strerror(errno));
+
+ if(udp_sndbuf && setsockopt(nfd, SOL_SOCKET, SO_SNDBUF, (void *)&udp_sndbuf, sizeof(udp_sndbuf)))
+ logger(LOG_WARNING, "Can't set UDP SO_SNDBUF to %i: %s", udp_sndbuf, strerror(errno));
+
#if defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY)
if(sa->sa.sa_family == AF_INET6)
setsockopt(nfd, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&option, sizeof option);
do_outgoing_connection(c);
- event_set(&c->inevent, c->socket, EV_READ | EV_PERSIST, handle_meta_connection_data, c);
- event_add(&c->inevent, NULL);
c->buffer = bufferevent_new(c->socket, handle_meta_read, handle_meta_write, handle_meta_connection_error, c);
if(!c->buffer) {
logger(LOG_ERR, "bufferevent_new() failed: %s", strerror(errno));
abort();
}
bufferevent_disable(c->buffer, EV_READ);
+
+ if(!thread_create(&c->thread, handle_meta_connection_data, c)) {
+ logger(LOG_ERR, "create_thread() failed: %s", strerror(errno));
+ abort();
+ }
}
/*
ifdebug(CONNECTIONS) logger(LOG_NOTICE, "Connection from %s", c->hostname);
- event_set(&c->inevent, c->socket, EV_READ | EV_PERSIST, handle_meta_connection_data, c);
- event_add(&c->inevent, NULL);
c->buffer = bufferevent_new(c->socket, NULL, handle_meta_write, handle_meta_connection_error, c);
if(!c->buffer) {
logger(LOG_ERR, "bufferevent_new() failed: %s", strerror(errno));
c->allow_request = ID;
send_id(c);
+
+ if(!thread_create(&c->thread, handle_meta_connection_data, c)) {
+ logger(LOG_ERR, "create_thread() failed: %s", strerror(errno));
+ abort();
+ }
}
void free_outgoing(outgoing_t *outgoing) {