本文整理汇总了C++中rpc_set_error函数的典型用法代码示例。如果您正苦于以下问题:C++ rpc_set_error函数的具体用法?C++ rpc_set_error怎么用?C++ rpc_set_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rpc_set_error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rpc_pmap_callit_async
int rpc_pmap_callit_async(struct rpc_context *rpc, int program, int version, int procedure, const char *data, int datalen, rpc_cb cb, void *private_data)
{
struct rpc_pdu *pdu;
struct pmap_call_args ca;
pdu = rpc_allocate_pdu(rpc, PMAP_PROGRAM, PMAP_V2, PMAP_CALLIT, cb, private_data, (xdrproc_t)xdr_pmap_call_result, sizeof(pmap_call_result));
if (pdu == NULL) {
rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for portmap/callit call");
return -1;
}
ca.prog = program;
ca.vers = version;
ca.proc = procedure;
ca.args.args_len = datalen;
ca.args.args_val = data;
if (xdr_pmap_call_args(&pdu->xdr, &ca) == 0) {
rpc_set_error(rpc, "XDR error: Failed to encode data for portmap/callit call");
rpc_free_pdu(rpc, pdu);
return -1;
}
if (rpc_queue_pdu(rpc, pdu) != 0) {
rpc_set_error(rpc, "Failed to queue portmap/callit pdu: %s", rpc_get_error(rpc));
return -1;
}
return 0;
}
示例2: rpc_register_service
int rpc_register_service(struct rpc_context *rpc, int program, int version,
struct service_proc *procs, int num_procs)
{
struct rpc_endpoint *endpoint;
assert(rpc->magic == RPC_CONTEXT_MAGIC);
if (!rpc->is_server_context) {
rpc_set_error(rpc, "Not a server context.");
return -1;
}
endpoint = malloc(sizeof(*endpoint));
if (endpoint == NULL) {
rpc_set_error(rpc, "Out of memory: Failed to allocate endpoint "
"structure");
return -1;
}
endpoint->program = program;
endpoint->version = version;
endpoint->procs = procs;
endpoint->num_procs = num_procs;
endpoint->next = rpc->endpoints;
rpc->endpoints = endpoint;
return 0;
}
示例3: rpc_pmap_set_async
int rpc_pmap_set_async(struct rpc_context *rpc, int program, int version, int protocol, int port, rpc_cb cb, void *private_data)
{
struct rpc_pdu *pdu;
struct pmap_mapping m;
pdu = rpc_allocate_pdu(rpc, PMAP_PROGRAM, PMAP_V2, PMAP_SET, cb, private_data, (zdrproc_t)zdr_int, sizeof(uint32_t));
if (pdu == NULL) {
rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for portmap/set call");
return -1;
}
m.prog = program;
m.vers = version;
m.prot = protocol;
m.port = port;
if (zdr_pmap_mapping(&pdu->zdr, &m) == 0) {
rpc_set_error(rpc, "ZDR error: Failed to encode data for portmap/set call");
rpc_free_pdu(rpc, pdu);
return -1;
}
if (rpc_queue_pdu(rpc, pdu) != 0) {
rpc_set_error(rpc, "Failed to queue portmap/set pdu");
rpc_free_pdu(rpc, pdu);
return -1;
}
return 0;
}
示例4: wait_for_reply
static void wait_for_reply(struct rpc_context *rpc, struct sync_cb_data *cb_data)
{
struct pollfd pfd;
assert(rpc->magic == RPC_CONTEXT_MAGIC);
while (!cb_data->is_finished) {
pfd.fd = rpc_get_fd(rpc);
pfd.events = rpc_which_events(rpc);
if (poll(&pfd, 1, -1) < 0) {
rpc_set_error(rpc, "Poll failed");
cb_data->status = -EIO;
break;
}
if (rpc_service(rpc, pfd.revents) < 0) {
rpc_set_error(rpc, "rpc_service failed");
cb_data->status = -EIO;
break;
}
if (rpc_get_fd(rpc) == -1) {
rpc_set_error(rpc, "Socket closed\n");
break;
}
}
}
示例5: rpc_write_to_socket
static int rpc_write_to_socket(struct rpc_context *rpc)
{
int32_t count;
assert(rpc->magic == RPC_CONTEXT_MAGIC);
if (rpc->fd == -1) {
rpc_set_error(rpc, "trying to write but not connected");
return -1;
}
while (rpc->outqueue != NULL) {
int64_t total;
total = rpc->outqueue->outdata.size;
count = send(rpc->fd, rpc->outqueue->outdata.data + rpc->outqueue->written, total - rpc->outqueue->written, 0);
if (count == -1) {
if (errno == EAGAIN || errno == EWOULDBLOCK) {
return 0;
}
rpc_set_error(rpc, "Error when writing to socket :%s(%d)", strerror(errno), errno);
return -1;
}
rpc->outqueue->written += count;
if (rpc->outqueue->written == total) {
struct rpc_pdu *pdu = rpc->outqueue;
SLIST_REMOVE(&rpc->outqueue, pdu);
SLIST_ADD_END(&rpc->waitpdu, pdu);
}
}
return 0;
}
示例6: libnfs_rpc_reply_body
static bool_t libnfs_rpc_reply_body(struct rpc_context *rpc, ZDR *zdrs, struct reply_body *rmb)
{
if (!libnfs_zdr_u_int(zdrs, &rmb->stat)) {
rpc_set_error(rpc, "libnfs_rpc_reply_body failed to decode "
"STAT");
return FALSE;
}
switch (rmb->stat) {
case MSG_ACCEPTED:
if (!libnfs_accepted_reply(zdrs, &rmb->reply.areply)) {
rpc_set_error(rpc, "libnfs_rpc_reply_body failed to "
"decode ACCEPTED");
return FALSE;
}
return TRUE;
case MSG_DENIED:
if (!libnfs_rejected_reply(zdrs, &rmb->reply.rreply)) {
rpc_set_error(rpc, "libnfs_rpc_reply_body failed to "
"decode DENIED");
return FALSE;
}
return TRUE;
}
rpc_set_error(rpc, "libnfs_rpc_reply_body failed to "
"decode. Neither ACCEPTED nor DENIED");
return FALSE;
}
示例7: rpc_pmap_getport_async
int rpc_pmap_getport_async(struct rpc_context *rpc, int program, int version, rpc_cb cb, void *private_data)
{
struct rpc_pdu *pdu;
struct mapping m;
pdu = rpc_allocate_pdu(rpc, PMAP_PROGRAM, PMAP_V2, PMAP_GETPORT, cb, private_data, (xdrproc_t)xdr_int, sizeof(uint32_t));
if (pdu == NULL) {
rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for portmap/getport call");
return -1;
}
m.prog = program;
m.vers = version;
m.prot = IPPROTO_TCP;
m.port = 0;
if (xdr_mapping(&pdu->xdr, &m) == 0) {
rpc_set_error(rpc, "XDR error: Failed to encode data for portmap/getport call");
rpc_free_pdu(rpc, pdu);
return -1;
}
if (rpc_queue_pdu(rpc, pdu) != 0) {
rpc_set_error(rpc, "Failed to queue portmap/getport pdu");
rpc_free_pdu(rpc, pdu);
return -1;
}
return 0;
}
示例8: libnfs_rpc_msg
static bool_t libnfs_rpc_msg(struct rpc_context *rpc, ZDR *zdrs, struct rpc_msg *msg)
{
int ret;
if (!libnfs_zdr_u_int(zdrs, &msg->xid)) {
rpc_set_error(rpc, "libnfs_rpc_msg failed to decode XID");
return FALSE;
}
if (!libnfs_zdr_u_int(zdrs, &msg->direction)) {
rpc_set_error(rpc, "libnfs_rpc_msg failed to decode DIRECTION");
return FALSE;
}
switch (msg->direction) {
case CALL:
ret = libnfs_rpc_call_body(rpc, zdrs, &msg->body.cbody);
if (!ret) {
rpc_set_error(rpc, "libnfs_rpc_msg failed to encode "
"CALL, ret=%d: %s", ret, rpc_get_error(rpc));
}
return ret;
case REPLY:
ret = libnfs_rpc_reply_body(rpc, zdrs, &msg->body.rbody);
if (!ret) {
rpc_set_error(rpc, "libnfs_rpc_msg failed to decode "
"REPLY, ret=%d: %s", ret, rpc_get_error(rpc));
}
return ret;
default:
rpc_set_error(rpc, "libnfs_rpc_msg failed to decode. "
"Neither CALL not REPLY");
return FALSE;
}
}
示例9: assert
struct rpc_pdu *rpc_allocate_pdu2(struct rpc_context *rpc, int program, int version, int procedure, rpc_cb cb, void *private_data, zdrproc_t zdr_decode_fn, int zdr_decode_bufsize, size_t alloc_hint)
{
struct rpc_pdu *pdu;
struct rpc_msg msg;
int pdu_size;
assert(rpc->magic == RPC_CONTEXT_MAGIC);
/* Since we already know how much buffer we need for the decoding
* we can just piggyback in the same alloc as for the pdu.
*/
pdu_size = PAD_TO_8_BYTES(sizeof(struct rpc_pdu));
pdu_size += PAD_TO_8_BYTES(zdr_decode_bufsize);
pdu = malloc(pdu_size);
if (pdu == NULL) {
rpc_set_error(rpc, "Out of memory: Failed to allocate pdu structure");
return NULL;
}
memset(pdu, 0, pdu_size);
pdu->xid = rpc->xid++;
pdu->cb = cb;
pdu->private_data = private_data;
pdu->zdr_decode_fn = zdr_decode_fn;
pdu->zdr_decode_bufsize = zdr_decode_bufsize;
pdu->outdata.data = malloc(ZDR_ENCODEBUF_MINSIZE + alloc_hint);
if (pdu->outdata.data == NULL) {
rpc_set_error(rpc, "Out of memory: Failed to allocate encode buffer");
free(pdu);
return NULL;
}
zdrmem_create(&pdu->zdr, pdu->outdata.data, ZDR_ENCODEBUF_MINSIZE + alloc_hint, ZDR_ENCODE);
if (rpc->is_udp == 0) {
zdr_setpos(&pdu->zdr, 4); /* skip past the record marker */
}
memset(&msg, 0, sizeof(struct rpc_msg));
msg.xid = pdu->xid;
msg.direction = CALL;
msg.body.cbody.rpcvers = RPC_MSG_VERSION;
msg.body.cbody.prog = program;
msg.body.cbody.vers = version;
msg.body.cbody.proc = procedure;
msg.body.cbody.cred = rpc->auth->ah_cred;
msg.body.cbody.verf = rpc->auth->ah_verf;
if (zdr_callmsg(rpc, &pdu->zdr, &msg) == 0) {
rpc_set_error(rpc, "zdr_callmsg failed with %s",
rpc_get_error(rpc));
zdr_destroy(&pdu->zdr);
free(pdu->outdata.data);
free(pdu);
return NULL;
}
return pdu;
}
示例10: rpc_process_call
static int rpc_process_call(struct rpc_context *rpc, ZDR *zdr)
{
struct rpc_msg call;
struct rpc_endpoint *endpoint;
int i, min_version = 0, max_version = 0, found_program = 0;
assert(rpc->magic == RPC_CONTEXT_MAGIC);
memset(&call, 0, sizeof(struct rpc_msg));
if (zdr_callmsg(rpc, zdr, &call) == 0) {
rpc_set_error(rpc, "Failed to decode CALL message. %s",
rpc_get_error(rpc));
return rpc_send_error_reply(rpc, &call, GARBAGE_ARGS, 0, 0);
}
for (endpoint = rpc->endpoints; endpoint; endpoint = endpoint->next) {
if (call.body.cbody.prog == endpoint->program) {
if (!found_program) {
min_version = max_version = endpoint->version;
}
if (endpoint->version < min_version) {
min_version = endpoint->version;
}
if (endpoint->version > max_version) {
max_version = endpoint->version;
}
found_program = 1;
if (call.body.cbody.vers == endpoint->version) {
break;
}
}
}
if (endpoint == NULL) {
rpc_set_error(rpc, "No endpoint found for CALL "
"program:0x%08x version:%d\n",
call.body.cbody.prog, call.body.cbody.vers);
if (!found_program) {
return rpc_send_error_reply(rpc, &call, PROG_UNAVAIL,
0, 0);
}
return rpc_send_error_reply(rpc, &call, PROG_MISMATCH,
min_version, max_version);
}
for (i = 0; i < endpoint->num_procs; i++) {
if (endpoint->procs[i].proc == call.body.cbody.proc) {
if (endpoint->procs[i].decode_buf_size) {
call.body.cbody.args = zdr_malloc(zdr, endpoint->procs[i].decode_buf_size);
}
if (!endpoint->procs[i].decode_fn(zdr, call.body.cbody.args)) {
rpc_set_error(rpc, "Failed to unmarshall "
"call payload");
return rpc_send_error_reply(rpc, &call, GARBAGE_ARGS, 0 ,0);
}
return endpoint->procs[i].func(rpc, &call);
}
}
return rpc_send_error_reply(rpc, &call, PROC_UNAVAIL, 0 ,0);
}
示例11: rpc_connect_async
int rpc_connect_async(struct rpc_context *rpc, const char *server, int port, rpc_cb cb, void *private_data)
{
struct addrinfo *ai = NULL;
assert(rpc->magic == RPC_CONTEXT_MAGIC);
if (rpc->fd != -1) {
rpc_set_error(rpc, "Trying to connect while already connected");
return -1;
}
if (rpc->is_udp != 0) {
rpc_set_error(rpc, "Trying to connect on UDP socket");
return -1;
}
rpc->auto_reconnect = 0;
if (getaddrinfo(server, NULL, NULL, &ai) != 0) {
rpc_set_error(rpc, "Invalid address:%s. "
"Can not resolv into IPv4/v6 structure.", server);
return -1;
}
switch (ai->ai_family) {
case AF_INET:
((struct sockaddr_in *)&rpc->s)->sin_family = ai->ai_family;
((struct sockaddr_in *)&rpc->s)->sin_port = htons(port);
((struct sockaddr_in *)&rpc->s)->sin_addr = ((struct sockaddr_in *)(ai->ai_addr))->sin_addr;
#ifdef HAVE_SOCKADDR_LEN
((struct sockaddr_in *)&rpc->s)->sin_len = sizeof(struct sockaddr_in);
#endif
break;
case AF_INET6:
((struct sockaddr_in6 *)&rpc->s)->sin6_family = ai->ai_family;
((struct sockaddr_in6 *)&rpc->s)->sin6_port = htons(port);
((struct sockaddr_in6 *)&rpc->s)->sin6_addr = ((struct sockaddr_in6 *)(ai->ai_addr))->sin6_addr;
#ifdef HAVE_SOCKADDR_LEN
((struct sockaddr_in6 *)&rpc->s)->sin6_len = sizeof(struct sockaddr_in6);
#endif
break;
}
rpc->connect_cb = cb;
rpc->connect_data = private_data;
freeaddrinfo(ai);
if (rpc_connect_sockaddr_async(rpc, &rpc->s) != 0) {
return -1;
}
return 0;
}
示例12: rpc_send_error_reply
static int rpc_send_error_reply(struct rpc_context *rpc,
struct rpc_msg *call,
enum accept_stat err,
int min_vers, int max_vers)
{
struct rpc_pdu *pdu;
struct rpc_msg res;
assert(rpc->magic == RPC_CONTEXT_MAGIC);
memset(&res, 0, sizeof(struct rpc_msg));
res.xid = call->xid;
res.direction = REPLY;
res.body.rbody.stat = MSG_ACCEPTED;
res.body.rbody.reply.areply.reply_data.mismatch_info.low = min_vers;
res.body.rbody.reply.areply.reply_data.mismatch_info.high = max_vers;
res.body.rbody.reply.areply.verf = _null_auth;
res.body.rbody.reply.areply.stat = err;
if (rpc->is_udp) {
/* send the reply back to the client */
memcpy(&rpc->udp_dest, &rpc->udp_src, sizeof(rpc->udp_dest));
}
pdu = rpc_allocate_reply_pdu(rpc, &res, 0);
if (pdu == NULL) {
rpc_set_error(rpc, "Failed to send error_reply: %s",
rpc_get_error(rpc));
return -1;
}
rpc_queue_pdu(rpc, pdu);
return 0;
}
示例13: rpc_mount3_null_async
int rpc_mount3_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
{
struct rpc_pdu *pdu;
pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_NULL, cb, private_data, (zdrproc_t)zdr_void, 0);
if (pdu == NULL) {
rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for mount/null call");
return -1;
}
if (rpc_queue_pdu(rpc, pdu) != 0) {
rpc_set_error(rpc, "Out of memory. Failed to queue pdu for mount/null call");
return -1;
}
return 0;
}
示例14: rpc_pmap_null_async
int rpc_pmap_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
{
struct rpc_pdu *pdu;
pdu = rpc_allocate_pdu(rpc, PMAP_PROGRAM, PMAP_V2, PMAP_NULL, cb, private_data, (xdrproc_t)xdr_void, 0);
if (pdu == NULL) {
rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for portmap/null call");
return -1;
}
if (rpc_queue_pdu(rpc, pdu) != 0) {
rpc_set_error(rpc, "Out of memory. Failed to queue pdu for portmap/null call");
rpc_free_pdu(rpc, pdu);
return -1;
}
return 0;
}
示例15: rpc_rquota1_null_async
int rpc_rquota1_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
{
struct rpc_pdu *pdu;
pdu = rpc_allocate_pdu(rpc, RQUOTA_PROGRAM, RQUOTA_V1, RQUOTA1_NULL, cb, private_data, (xdrproc_t)xdr_void, 0);
if (pdu == NULL) {
rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for rquota1/null call");
return -1;
}
if (rpc_queue_pdu(rpc, pdu) != 0) {
rpc_set_error(rpc, "Out of memory. Failed to queue pdu for rquota1/null call");
rpc_free_pdu(rpc, pdu);
return -2;
}
return 0;
}