#include "util.h"
#include "cache.h"
+#define AVAHI_MAX_CACHE_ENTRIES 200
+
static void remove_entry(AvahiCache *c, AvahiCacheEntry *e) {
AvahiCacheEntry *t;
avahi_record_unref(e->record);
g_free(e);
+
+ g_assert(c->n_entries-- >= 1);
}
AvahiCache *avahi_cache_new(AvahiServer *server, AvahiInterface *iface) {
c->hash_table = g_hash_table_new((GHashFunc) avahi_key_hash, (GEqualFunc) avahi_key_equal);
AVAHI_LLIST_HEAD_INIT(AvahiCacheEntry, c->entries);
+ c->n_entries = 0;
return c;
}
while (c->entries)
remove_entry(c, c->entries);
+ g_assert(c->n_entries == 0);
g_hash_table_destroy(c->hash_table);
/* No entry found, therefore we create a new one */
/* g_message("couldn't find matching cache entry"); */
+
+ if (c->n_entries >= AVAHI_MAX_CACHE_ENTRIES)
+ return;
+
+ c->n_entries++;
e = g_new(AvahiCacheEntry, 1);
e->cache = c;
GHashTable *hash_table;
AVAHI_LLIST_HEAD(AvahiCacheEntry, entries);
+
+ guint n_entries;
};
AvahiCache *avahi_cache_new(AvahiServer *server, AvahiInterface *interface);
if (mtu <= 0)
max_size = AVAHI_DNS_PACKET_MAX_SIZE;
- else if (mtu >= 48)
- max_size = mtu - 48;
+ else if (mtu >= AVAHI_DNS_PACKET_EXTRA_SIZE)
+ max_size = mtu - AVAHI_DNS_PACKET_EXTRA_SIZE;
else
max_size = 0;
#define AVAHI_DNS_PACKET_MAX_SIZE 9000
#define AVAHI_DNS_PACKET_HEADER_SIZE 12
+#define AVAHI_DNS_PACKET_EXTRA_SIZE 48
typedef struct AvahiDnsPacket {
guint size, rindex, max_size;
#include <unistd.h>
#include <errno.h>
#include <string.h>
+#include <sys/ioctl.h>
#include "netlink.h"
g_assert(nl);
for (;;) {
- guint8 replybuf[64*1024];
ssize_t bytes;
- struct nlmsghdr *p = (struct nlmsghdr *) replybuf;
+ struct nlmsghdr *p;
+ guint8 buffer[64*1024];
- if ((bytes = recv(nl->fd, replybuf, sizeof(replybuf), block ? 0 : MSG_DONTWAIT)) < 0) {
+ p = (struct nlmsghdr *) buffer;
+
+ if ((bytes = recv(nl->fd, buffer, sizeof(buffer), block ? 0 : MSG_DONTWAIT)) < 0) {
if (errno == EAGAIN || errno == EINTR)
break;
- g_warning("NETLINK: recv() failed");
+ g_warning("NETLINK: recv() failed: %s", strerror(errno));
return FALSE;
}
void avahi_netlink_free(AvahiNetlink *nl) {
g_assert(nl);
-
+
g_source_destroy(nl->source);
g_source_unref(nl->source);
g_main_context_unref(nl->context);
#include "socket.h"
#include "browse.h"
-#define AVAHI_HOST_RR_HOLDOFF_MSEC 1000
+#define AVAHI_HOST_RR_HOLDOFF_MSEC 2000
static void free_entry(AvahiServer*s, AvahiEntry *e) {
AvahiEntry *t;
ssize_t l;
struct cmsghdr *cmsg;
gboolean found_ttl = FALSE, found_iface = FALSE;
+ guint ms;
g_assert(fd >= 0);
g_assert(ret_sa);
g_assert(ret_iface);
g_assert(ret_ttl);
- p = avahi_dns_packet_new(0);
+ if (ioctl(fd, FIONREAD, &ms) < 0) {
+ g_warning("ioctl(): %s", strerror(errno));
+ goto fail;
+ }
+
+ p = avahi_dns_packet_new(ms + AVAHI_DNS_PACKET_EXTRA_SIZE);
io.iov_base = AVAHI_DNS_PACKET_DATA(p);
io.iov_len = p->max_size;
msg.msg_flags = 0;
if ((l = recvmsg(fd, &msg, 0)) < 0) {
- g_warning("recvmsg(): %s\n", strerror(errno));
+ g_warning("recvmsg(): %s", strerror(errno));
goto fail;
}
struct iovec io;
uint8_t aux[64];
ssize_t l;
+ guint ms;
+
struct cmsghdr *cmsg;
gboolean found_ttl = FALSE, found_iface = FALSE;
g_assert(ret_iface);
g_assert(ret_ttl);
- p = avahi_dns_packet_new(0);
+ if (ioctl(fd, FIONREAD, &ms) < 0) {
+ g_warning("ioctl(): %s", strerror(errno));
+ goto fail;
+ }
+
+ p = avahi_dns_packet_new(ms + AVAHI_DNS_PACKET_EXTRA_SIZE);
io.iov_base = AVAHI_DNS_PACKET_DATA(p);
io.iov_len = p->max_size;
msg.msg_controllen = sizeof(aux);
msg.msg_flags = 0;
- if ((l = recvmsg(fd, &msg, 0)) < 0)
+ if ((l = recvmsg(fd, &msg, 0)) < 0) {
+ g_warning("recvmsg(): %s", strerror(errno));
goto fail;
+ }
p->size = (size_t) l;