+ struct callback_query *cq;
+ struct callback_result *cr;
+ int ret, fd = -1, query_shmid, result_shmid;
+ void *query_shm, *result_shm;
+ char buf[sizeof(afs_socket_cookie) + sizeof(int)];
+// char *tmpsocket_name;
+ struct sockaddr_un unix_addr;
+
+ assert(query->data && query->size);
+ ret = shm_new(query->size + sizeof(*cq));
+ if (ret < 0)
+ return ret;
+ query_shmid = ret;
+ ret = shm_attach(query_shmid, ATTACH_RW, &query_shm);
+ if (ret < 0)
+ goto out;
+ cq = query_shm;
+ cq->handler = f;
+ cq->query_size = query->size;
+
+ memcpy(query_shm + sizeof(*cq), query->data, query->size);
+ ret = shm_detach(query_shm);
+ if (ret < 0)
+ goto out;
+
+ *(uint32_t *) buf = afs_socket_cookie;
+ *(int *) (buf + sizeof(afs_socket_cookie)) = query_shmid;
+
+ ret = get_stream_socket(PF_UNIX);
+ if (ret < 0)
+ goto out;
+ fd = ret;
+ ret = init_unix_addr(&unix_addr, conf.afs_socket_arg);
+ if (ret < 0)
+ goto out;
+ ret = -E_CONNECT;
+ if (connect(fd, (struct sockaddr *)&unix_addr, sizeof(unix_addr)) < 0) /* FIXME: Use para_connect() */
+ goto out;
+ ret = send_bin_buffer(fd, buf, sizeof(buf));
+ PARA_NOTICE_LOG("bin buffer ret: %d\n", ret);
+ if (ret < 0)
+ goto out;
+ ret = recv_bin_buffer(fd, buf, sizeof(buf));
+ PARA_NOTICE_LOG("ret: %d\n", ret);
+ if (ret < 0)
+ goto out;
+ if (ret != sizeof(int)) {
+ ret = -E_RECV;
+ goto out;
+ }
+ ret = *(int *) buf;
+ PARA_NOTICE_LOG("result_shmid: %d\n", ret);
+ if (ret <= 0)
+ goto out;
+ result_shmid = ret;
+ ret = shm_attach(result_shmid, ATTACH_RO, &result_shm);
+ if (ret >= 0) {
+ assert(result);
+ cr = result_shm;
+ result->size = cr->result_size;
+ result->data = para_malloc(result->size);
+ memcpy(result->data, result_shm + sizeof(*cr), result->size);
+ ret = shm_detach(result_shm);
+ if (ret < 0)
+ PARA_ERROR_LOG("can not detach result\n");
+ } else
+ PARA_ERROR_LOG("attach result failed: %d\n", ret);
+ if (shm_destroy(result_shmid) < 0)
+ PARA_ERROR_LOG("destroy result failed\n");
+ ret = 1;
+out:
+ if (shm_destroy(query_shmid) < 0)
+ PARA_ERROR_LOG("%s\n", "shm destroy error");
+ if (fd >= 0)
+ close(fd);
+ PARA_DEBUG_LOG("callback_ret: %d\n", ret);
+ return ret;