+ 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)];
+ struct sockaddr_un unix_addr;
+ size_t query_shm_size = sizeof(*cq);
+
+ if (query)
+ query_shm_size += query->size;
+ ret = shm_new(query_shm_size);
+ 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_shm_size - sizeof(*cq);
+
+ if (query)
+ 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 = PARA_CONNECT(fd, &unix_addr);
+ if (ret < 0)
+ goto out;
+ ret = send_bin_buffer(fd, buf, sizeof(buf));
+ if (ret < 0)
+ goto out;
+ ret = recv_bin_buffer(fd, buf, sizeof(buf));
+ if (ret < 0)
+ goto out;
+ if (ret != sizeof(int)) {
+ ret = -E_RECV;
+ goto out;
+ }
+ ret = *(int *) buf;
+ 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;