int result;
asprintf(&send_msg, "get_subbuffer %s", buf->name);
- result = ustcomm_send_request(&buf->conn, send_msg, &received_msg);
+ result = ustcomm_send_request(buf->conn, send_msg, &received_msg);
if((result == -1 && (errno == ECONNRESET || errno == EPIPE)) || result == 0) {
DBG("app died while being traced");
retval = GET_SUBBUF_DIED;
int result;
asprintf(&send_msg, "put_subbuffer %s %ld", buf->name, buf->consumed_old);
- result = ustcomm_send_request(&buf->conn, send_msg, &received_msg);
+ result = ustcomm_send_request(buf->conn, send_msg, &received_msg);
if(result < 0 && (errno == ECONNRESET || errno == EPIPE)) {
retval = PUT_SUBBUF_DIED;
goto end;
return NULL;
}
+ buf->conn = malloc(sizeof(struct ustcomm_connection));
+ if(buf->conn == NULL) {
+ ERR("add_buffer: insufficient memory");
+ free(buf);
+ return NULL;
+ }
+
buf->name = bufname;
buf->pid = pid;
/* connect to app */
- result = ustcomm_connect_app(buf->pid, &buf->conn);
+ result = ustcomm_connect_app(buf->pid, buf->conn);
if(result) {
WARN("unable to connect to process, it probably died before we were able to connect");
return NULL;
/* get pidunique */
asprintf(&send_msg, "get_pidunique");
- result = ustcomm_send_request(&buf->conn, send_msg, &received_msg);
+ result = ustcomm_send_request(buf->conn, send_msg, &received_msg);
free(send_msg);
if(result == -1) {
ERR("problem in ustcomm_send_request(get_pidunique)");
/* get shmid */
asprintf(&send_msg, "get_shmid %s", buf->name);
- result = ustcomm_send_request(&buf->conn, send_msg, &received_msg);
+ result = ustcomm_send_request(buf->conn, send_msg, &received_msg);
free(send_msg);
if(result == -1) {
ERR("problem in ustcomm_send_request(get_shmid)");
/* get n_subbufs */
asprintf(&send_msg, "get_n_subbufs %s", buf->name);
- result = ustcomm_send_request(&buf->conn, send_msg, &received_msg);
+ result = ustcomm_send_request(buf->conn, send_msg, &received_msg);
free(send_msg);
if(result == -1) {
ERR("problem in ustcomm_send_request(g_n_subbufs)");
/* get subbuf size */
asprintf(&send_msg, "get_subbuf_size %s", buf->name);
- result = ustcomm_send_request(&buf->conn, send_msg, &received_msg);
+ result = ustcomm_send_request(buf->conn, send_msg, &received_msg);
free(send_msg);
if(result == -1) {
ERR("problem in ustcomm_send_request(get_subbuf_size)");
{
int result;
- result = ustcomm_close_app(&buf->conn);
+ result = ustcomm_close_app(buf->conn);
if(result == -1) {
WARN("problem calling ustcomm_close_app");
}
if(callbacks->on_close_buffer)
callbacks->on_close_buffer(callbacks, buf);
+ free(buf->conn);
free(buf);
}
char *recvbuf;
/* check for requests on our public socket */
- result = ustcomm_ustd_recv_message(&instance->comm, &recvbuf, NULL, timeout);
+ result = ustcomm_ustd_recv_message(instance->comm, &recvbuf, NULL, timeout);
if(result == -1 && errno == EINTR) {
/* Caught signal */
}
void libustd_delete_instance(struct libustd_instance *instance)
{
if(instance->is_init)
- ustcomm_fini_ustd(&instance->comm);
+ ustcomm_fini_ustd(instance->comm);
pthread_mutex_destroy(&instance->mutex);
free(instance->sock_path);
+ free(instance->comm);
free(instance);
}
if(!instance)
return NULL;
+ instance->comm = malloc(sizeof(struct ustcomm_ustd));
+ if(!instance->comm) {
+ free(instance);
+ return NULL;
+ }
+
instance->callbacks = callbacks;
instance->quit_program = 0;
instance->is_init = 0;
int libustd_init_instance(struct libustd_instance *instance)
{
int result;
- result = ustcomm_init_ustd(&instance->comm, instance->sock_path);
+ result = ustcomm_init_ustd(instance->comm, instance->sock_path);
if(result == -1) {
ERR("failed to initialize socket");
return 1;