Try to send HA sync messages synchronously

This commit is contained in:
Martin Willi
2010-04-07 13:55:15 +02:00
committed by Martin Willi
parent f4f394e67c
commit 3c82381296
+25 -15
View File
@@ -81,9 +81,7 @@ static job_requeue_t send_message(job_data_t *data)
this = data->this; this = data->this;
chunk = data->message->get_encoding(data->message); chunk = data->message->get_encoding(data->message);
if (sendto(this->fd, chunk.ptr, chunk.len, 0, if (send(this->fd, chunk.ptr, chunk.len, 0) < chunk.len)
this->remote->get_sockaddr(this->remote),
*this->remote->get_sockaddr_len(this->remote)) < chunk.len)
{ {
DBG1(DBG_CFG, "pushing HA sync message failed: %s", strerror(errno)); DBG1(DBG_CFG, "pushing HA sync message failed: %s", strerror(errno));
} }
@@ -95,20 +93,32 @@ static job_requeue_t send_message(job_data_t *data)
*/ */
static void push(private_ha_sync_socket_t *this, ha_sync_message_t *message) static void push(private_ha_sync_socket_t *this, ha_sync_message_t *message)
{ {
callback_job_t *job; chunk_t chunk;
job_data_t *data;
data = malloc_thing(job_data_t); /* Try to send synchronously, but non-blocking. */
data->message = message; chunk = message->get_encoding(message);
data->this = this; if (send(this->fd, chunk.ptr, chunk.len, MSG_DONTWAIT) < chunk.len)
{
if (errno == EAGAIN)
{
callback_job_t *job;
job_data_t *data;
/* we send sync message asynchronously. This is required, as sendto() /* Fallback to asynchronous transmission. This is required, as sendto()
* is a blocking call if it acquires a policy. Otherwise we could * is a blocking call if it acquires a policy. We could end up in a
* end up in a deadlock, as we own an IKE_SA. */ * deadlock, as we own an IKE_SA. */
job = callback_job_create((callback_job_cb_t)send_message, data = malloc_thing(job_data_t);
data, (void*)job_data_destroy, NULL); data->message = message;
charon->processor->queue_job(charon->processor, (job_t*)job); data->this = this;
sched_yield();
job = callback_job_create((callback_job_cb_t)send_message,
data, (void*)job_data_destroy, NULL);
charon->processor->queue_job(charon->processor, (job_t*)job);
return;
}
DBG1(DBG_CFG, "pushing HA sync message failed: %s", strerror(errno));
}
message->destroy(message);
} }
/** /**