]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
eap-radius: use watcher instead of receiver thread on DAE socket
authorMartin Willi <martin@revosec.ch>
Mon, 1 Jul 2013 09:52:42 +0000 (11:52 +0200)
committerMartin Willi <martin@revosec.ch>
Thu, 18 Jul 2013 14:00:30 +0000 (16:00 +0200)
src/libcharon/plugins/eap_radius/eap_radius_dae.c

index 2ea2b059c8b6f9835dc83c4d16efbb442f409c0b..f22ddc56f142a78bc41c1224c582cfb557a79871 100644 (file)
@@ -379,21 +379,17 @@ static void process_coa(private_eap_radius_dae_t *this,
 /**
  * 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;
        socklen_t addr_len = sizeof(addr);
        radius_message_t *request;
        char buf[2048];
        ssize_t len;
-       bool oldstate;
        host_t *client;
 
-       oldstate = thread_cancelability(TRUE);
-       len = recvfrom(this->fd, buf, sizeof(buf), 0,
+       len = recvfrom(this->fd, buf, sizeof(buf), MSG_DONTWAIT,
                                   (struct sockaddr*)&addr, &addr_len);
-       thread_cancelability(oldstate);
-
        if (len > 0)
        {
                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");
                }
        }
-       else
+       else if (errno != EWOULDBLOCK)
        {
                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)
        {
+               lib->watcher->remove(lib->watcher, this->fd);
                close(this->fd);
        }
        DESTROY_IF(this->signer);
@@ -533,9 +530,8 @@ eap_radius_dae_t *eap_radius_dae_create(eap_radius_accounting_t *accounting)
                return NULL;
        }
 
-       lib->processor->queue_job(lib->processor,
-               (job_t*)callback_job_create_with_prio((callback_job_cb_t)receive,
-                       this, NULL, (callback_job_cancel_t)return_false, JOB_PRIO_CRITICAL));
+       lib->watcher->add(lib->watcher, this->fd, WATCHER_READ,
+                                         (watcher_cb_t)receive, this);
 
        return &this->public;
 }