카테고리 없음
오픈소스로 공부하는 Strongswan코드와 C예제.
2021. 11. 2. 19:56반응형
- Strongswan에서는 sender라는 구조체를 통해서 패킷을 전달함.
원본 코드
/**
* Job callback function to send packets
*/
static job_requeue_t send_packets(private_sender_t *this)
{
packet_t *packet;
bool oldstate;
this->mutex->lock(this->mutex);
while (this->list->get_count(this->list) == 0)
{
/* add cleanup handler, wait for packet, remove cleanup handler */
thread_cleanup_push((thread_cleanup_t)this->mutex->unlock, this->mutex);
oldstate = thread_cancelability(TRUE);
this->got->wait(this->got, this->mutex);
thread_cancelability(oldstate);
thread_cleanup_pop(FALSE);
}
this->list->remove_first(this->list, (void**)&packet);
this->sent->signal(this->sent);
this->mutex->unlock(this->mutex);
charon->socket->send(charon->socket, packet);
packet->destroy(packet);
return JOB_REQUEUE_DIRECT;
}
설명
/**
* Job callback function to send packets
*/
static job_requeue_t send_packets(private_sender_t *this)
{
packet_t *packet;
bool oldstate;
// 뮤텍스 락
// critical section start
this->mutex->lock(this->mutex);
while (this->list->get_count(this->list) == 0)
{
/* add cleanup handler, wait for packet, remove cleanup handler */
thread_cleanup_push((thread_cleanup_t)this->mutex->unlock, this->mutex);
oldstate = thread_cancelability(TRUE);
this->got->wait(this->got, this->mutex);
thread_cancelability(oldstate);
thread_cleanup_pop(FALSE);
}
this->list->remove_first(this->list, (void**)&packet);
this->sent->signal(this->sent);
// critical section end
// 뮤텍스 언락
this->mutex->unlock(this->mutex);
// 보내기 수행.
charon->socket->send(charon->socket, packet);
packet->destroy(packet);
return JOB_REQUEUE_DIRECT;
}
반응형