int siridb_tee_connect(siridb_tee_t * tee)
{
- LOGC("TEE CONNECT0");
+ if (tee->flags & SIRIDB_TEE_FLAG_CONNECTING)
+ {
+ return 0;
+ }
+ tee->flags |= SIRIDB_TEE_FLAG_CONNECTING;
uv_connect_t * req = malloc(sizeof(uv_connect_t));
if (req == NULL)
{
if (uv_pipe_init(siri.loop, &tee->pipe, 0))
{
+ tee->flags &= ~SIRIDB_TEE_FLAG_CONNECTING;
+ free(req);
return -1;
}
tee->flags |= SIRIDB_TEE_FLAG_INIT;
tee->pipe.data = tee;
uv_pipe_connect(req, &tee->pipe, tee->pipe_name_, tee__on_connect);
- LOGC("TEE CONNECT2");
return 0;
}
int siridb_tee_set_pipe_name(siridb_tee_t * tee, const char * pipe_name)
{
- LOGC("SET NAME0");
free(tee->pipe_name_);
free(tee->err_msg_);
tee->err_msg_ = NULL;
{
tee__runtime_init(&tee->pipe);
}
- LOGC("SET NAME5");
return 0;
}
void siridb_tee_write(siridb_tee_t * tee, sirinet_promise_t * promise)
{
- LOGC("TEE_WRITE0");
uv_write_t * req = malloc(sizeof(uv_write_t));
if (!req)
{
log_error("Cannot allocate memory for tee request");
return;
}
- LOGC("TEE_WRITE1");
req->data = promise;
sirinet_promise_incref(promise);
log_error("Cannot write to tee");
sirinet_promise_decref(promise);
}
- LOGC("TEE_WRITE2");
}
const char * tee_str(siridb_tee_t * tee)
static void tee__runtime_init(uv_pipe_t * pipe)
{
- LOGC("ON_INIT0");
siridb_tee_t * tee = pipe->data;
tee->flags &= ~SIRIDB_TEE_FLAG_INIT;
{
log_error("Could not connect to tee at runtime");
}
- LOGC("ON_INIT2");
}
static void tee__close_cb(uv_pipe_t * pipe)
{
- LOGC("ONCLOSE0");
siridb_tee_t * tee = pipe->data;
- LOGC("ONCLOSE1");
tee->flags &= ~SIRIDB_TEE_FLAG_INIT;
+ tee->flags &= ~SIRIDB_TEE_FLAG_CONNECTING;
tee->flags &= ~SIRIDB_TEE_FLAG_CONNECTED;
- LOGC("ONCLOSE2");
}
static void tee__write_cb(uv_write_t * req, int status)
{
- LOGC("ON_WRITE0");
sirinet_promise_t * promise = req->data;
sirinet_promise_decref(promise);
- LOGC("ON_WRITE1");
if (status)
{
log_error("Socket (tee) write error: %s", uv_strerror(status));
}
free(req);
- LOGC("ON_WRITE2");
}
static void tee__on_connect(uv_connect_t * req, int status)
{
- LOGC("ON_CONN0");
siridb_tee_t * tee = req->data;
if (status == 0)
tee->flags |= SIRIDB_TEE_FLAG_CONNECTED;
goto done;
}
- LOGC("ON_CONN1");
free(tee->err_msg_);
tee->err_msg_ = NULL;
{
log_warning(tee->err_msg_);
}
- LOGC("HERE0");
fail:
uv_close((uv_handle_t *) req->handle, (uv_close_cb) tee__close_cb);
- LOGC("HERE0.1");
done:
free(req);
- LOGC("HERE1");
}
static void tee__alloc_buffer(
size_t suggsz __attribute__((unused)),
uv_buf_t * buf)
{
- LOGC("ALLOC0");
buf->base = tee__buf;
buf->len = TEE__BUF_SZ;
- LOGC("ALLOC1");
}
ssize_t nread,
const uv_buf_t * buf __attribute__((unused)))
{
- LOGC("ON_DATA0");
if (nread < 0)
{
if (nread != UV_EOF)
log_info("Disconnected from tee");
uv_close((uv_handle_t *) client, (uv_close_cb) tee__close_cb);
}
- LOGC("ON_DATA1");
if (nread > 0)
{
log_debug("Got %zd bytes on tee which will be ignored", nread);
}
-
- LOGC("ON_DATA2");
}