#include <daemon.h>
#include <threading/thread.h>
+#include <threading/rwlock.h>
#include <utils/hashtable.h>
/* Maximum size of a packet */
hashtable_t *sockets;
/**
+ * Lock for sockets hashtable
+ */
+ rwlock_t *lock;
+
+ /**
* Notification pipe to signal receiver
*/
int notify[2];
FD_SET(this->notify[0], fds);
maxfd = this->notify[0];
+ this->lock->read_lock(this->lock);
enumerator = this->sockets->create_enumerator(this->sockets);
while (enumerator->enumerate(enumerator, &key, &value))
{
maxfd = max(maxfd, value->fd);
}
enumerator->destroy(enumerator);
+ this->lock->unlock(this->lock);
return maxfd + 1;
}
enumerator_t *enumerator;
dynsock_t *key, *value, *selected = NULL;
+ this->lock->read_lock(this->lock);
enumerator = this->sockets->create_enumerator(this->sockets);
while (enumerator->enumerate(enumerator, &key, &value))
{
}
}
enumerator->destroy(enumerator);
+ this->lock->unlock(this->lock);
+
return selected;
}
char buf[] = {0x01};
int fd;
+ this->lock->read_lock(this->lock);
skt = this->sockets->get(this->sockets, &lookup);
+ this->lock->unlock(this->lock);
if (skt)
{
return skt;
.port = port,
.fd = fd,
);
+ this->lock->write_lock(this->lock);
this->sockets->put(this->sockets, skt, skt);
+ this->lock->unlock(this->lock);
/* notify receiver thread to reread socket list */
ignore_result(write(this->notify[1], buf, sizeof(buf)));
}
enumerator->destroy(enumerator);
this->sockets->destroy(this->sockets);
+ this->lock->destroy(this->lock);
close(this->notify[0]);
close(this->notify[1]);
},
.destroy = _destroy,
},
+ .lock = rwlock_create(RWLOCK_TYPE_DEFAULT),
);
if (pipe(this->notify) != 0)