* Write queued output data
*/
static bool do_write(private_vici_socket_t *this, entry_t *entry,
- stream_t *stream, char *errmsg, size_t errlen)
+ stream_t *stream, char *errmsg, size_t errlen, bool block)
{
msg_buf_t *out;
ssize_t len;
while (out->hdrlen < sizeof(out->hdr))
{
len = stream->write(stream, out->hdr + out->hdrlen,
- sizeof(out->hdr) - out->hdrlen, FALSE);
+ sizeof(out->hdr) - out->hdrlen, block);
if (len == 0)
{
return FALSE;
while (out->buf.len > out->done)
{
len = stream->write(stream, out->buf.ptr + out->done,
- out->buf.len - out->done, FALSE);
+ out->buf.len - out->done, block);
if (len == 0)
{
snprintf(errmsg, errlen, "premature vici disconnect");
entry = find_entry(this, stream, 0, FALSE, TRUE);
if (entry)
{
- ret = do_write(this, entry, stream, errmsg, sizeof(errmsg));
+ ret = do_write(this, entry, stream, errmsg, sizeof(errmsg), FALSE);
if (ret)
{
/* unregister if we have no more messages to send */
}
}
+CALLBACK(flush_messages, void,
+ entry_t *entry, va_list args)
+{
+ private_vici_socket_t *this;
+ char errmsg[256] = "";
+ bool ret;
+
+ VA_ARGS_VGET(args, this);
+
+ /* no need for any locking as no other threads are running, the connections
+ * all get disconneted afterwards, so error handling is simple too */
+ ret = do_write(this, entry, entry->stream, errmsg, sizeof(errmsg), TRUE);
+
+ if (!ret && errmsg[0])
+ {
+ DBG1(DBG_CFG, errmsg);
+ }
+}
+
METHOD(vici_socket_t, destroy, void,
private_vici_socket_t *this)
{
DESTROY_IF(this->service);
+ this->connections->invoke_function(this->connections, flush_messages, this);
this->connections->destroy_function(this->connections, destroy_entry);
this->mutex->destroy(this->mutex);
free(this);