dhcp: use watcher instead of dedicated receiver thread
This commit is contained in:
@@ -562,7 +562,8 @@ static void handle_ack(private_dhcp_socket_t *this, dhcp_t *dhcp, int optlen)
|
|||||||
/**
|
/**
|
||||||
* Receive DHCP responses
|
* Receive DHCP responses
|
||||||
*/
|
*/
|
||||||
static job_requeue_t receive_dhcp(private_dhcp_socket_t *this)
|
static bool receive_dhcp(private_dhcp_socket_t *this, int fd,
|
||||||
|
watcher_event_t event)
|
||||||
{
|
{
|
||||||
struct sockaddr_ll addr;
|
struct sockaddr_ll addr;
|
||||||
socklen_t addr_len = sizeof(addr);
|
socklen_t addr_len = sizeof(addr);
|
||||||
@@ -571,14 +572,12 @@ static job_requeue_t receive_dhcp(private_dhcp_socket_t *this)
|
|||||||
struct udphdr udp;
|
struct udphdr udp;
|
||||||
dhcp_t dhcp;
|
dhcp_t dhcp;
|
||||||
} packet;
|
} packet;
|
||||||
int oldstate, optlen, origoptlen, optsize, optpos = 0;
|
int optlen, origoptlen, optsize, optpos = 0;
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
dhcp_option_t *option;
|
dhcp_option_t *option;
|
||||||
|
|
||||||
oldstate = thread_cancelability(TRUE);
|
len = recvfrom(fd, &packet, sizeof(packet), MSG_DONTWAIT,
|
||||||
len = recvfrom(this->receive, &packet, sizeof(packet), 0,
|
|
||||||
(struct sockaddr*)&addr, &addr_len);
|
(struct sockaddr*)&addr, &addr_len);
|
||||||
thread_cancelability(oldstate);
|
|
||||||
|
|
||||||
if (len >= sizeof(struct iphdr) + sizeof(struct udphdr) +
|
if (len >= sizeof(struct iphdr) + sizeof(struct udphdr) +
|
||||||
offsetof(dhcp_t, options))
|
offsetof(dhcp_t, options))
|
||||||
@@ -611,7 +610,7 @@ static job_requeue_t receive_dhcp(private_dhcp_socket_t *this)
|
|||||||
optpos += optsize;
|
optpos += optsize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return JOB_REQUEUE_DIRECT;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
METHOD(dhcp_socket_t, destroy, void,
|
METHOD(dhcp_socket_t, destroy, void,
|
||||||
@@ -627,6 +626,7 @@ METHOD(dhcp_socket_t, destroy, void,
|
|||||||
}
|
}
|
||||||
if (this->receive > 0)
|
if (this->receive > 0)
|
||||||
{
|
{
|
||||||
|
lib->watcher->remove(lib->watcher, this->receive);
|
||||||
close(this->receive);
|
close(this->receive);
|
||||||
}
|
}
|
||||||
this->mutex->destroy(this->mutex);
|
this->mutex->destroy(this->mutex);
|
||||||
@@ -767,10 +767,8 @@ dhcp_socket_t *dhcp_socket_create()
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
lib->processor->queue_job(lib->processor,
|
lib->watcher->add(lib->watcher, this->receive, WATCHER_READ,
|
||||||
(job_t*)callback_job_create_with_prio((callback_job_cb_t)receive_dhcp,
|
(watcher_cb_t)receive_dhcp, this);
|
||||||
this, NULL, (callback_job_cancel_t)return_false, JOB_PRIO_CRITICAL));
|
|
||||||
|
|
||||||
return &this->public;
|
return &this->public;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user