eap-radius: use watcher instead of receiver thread on DAE socket

This commit is contained in:
Martin Willi
2013-07-18 16:00:30 +02:00
parent c0db5d3845
commit 5f755cef46
@@ -379,21 +379,17 @@ static void process_coa(private_eap_radius_dae_t *this,
/** /**
* Receive RADIUS DAE requests * Receive RADIUS DAE requests
*/ */
static job_requeue_t receive(private_eap_radius_dae_t *this) static bool receive(private_eap_radius_dae_t *this)
{ {
struct sockaddr_storage addr; struct sockaddr_storage addr;
socklen_t addr_len = sizeof(addr); socklen_t addr_len = sizeof(addr);
radius_message_t *request; radius_message_t *request;
char buf[2048]; char buf[2048];
ssize_t len; ssize_t len;
bool oldstate;
host_t *client; host_t *client;
oldstate = thread_cancelability(TRUE); len = recvfrom(this->fd, buf, sizeof(buf), MSG_DONTWAIT,
len = recvfrom(this->fd, buf, sizeof(buf), 0,
(struct sockaddr*)&addr, &addr_len); (struct sockaddr*)&addr, &addr_len);
thread_cancelability(oldstate);
if (len > 0) if (len > 0)
{ {
request = radius_message_parse(chunk_create(buf, len)); request = radius_message_parse(chunk_create(buf, len));
@@ -433,11 +429,11 @@ static job_requeue_t receive(private_eap_radius_dae_t *this)
DBG1(DBG_NET, "ignoring invalid RADIUS DAE request"); DBG1(DBG_NET, "ignoring invalid RADIUS DAE request");
} }
} }
else else if (errno != EWOULDBLOCK)
{ {
DBG1(DBG_NET, "receiving RADIUS DAE request failed: %s", strerror(errno)); DBG1(DBG_NET, "receiving RADIUS DAE request failed: %s", strerror(errno));
} }
return JOB_REQUEUE_DIRECT; return TRUE;
} }
/** /**
@@ -483,6 +479,7 @@ METHOD(eap_radius_dae_t, destroy, void,
{ {
if (this->fd != -1) if (this->fd != -1)
{ {
lib->watcher->remove(lib->watcher, this->fd);
close(this->fd); close(this->fd);
} }
DESTROY_IF(this->signer); DESTROY_IF(this->signer);
@@ -533,9 +530,8 @@ eap_radius_dae_t *eap_radius_dae_create(eap_radius_accounting_t *accounting)
return NULL; return NULL;
} }
lib->processor->queue_job(lib->processor, lib->watcher->add(lib->watcher, this->fd, WATCHER_READ,
(job_t*)callback_job_create_with_prio((callback_job_cb_t)receive, (watcher_cb_t)receive, this);
this, NULL, (callback_job_cancel_t)return_false, JOB_PRIO_CRITICAL));
return &this->public; return &this->public;
} }