本文整理汇总了C++中xdr_getpos函数的典型用法代码示例。如果您正苦于以下问题:C++ xdr_getpos函数的具体用法?C++ xdr_getpos怎么用?C++ xdr_getpos使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xdr_getpos函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CBTF_SendToFile
/**
* Send performance data to a file.
*
* Sends performance data to the current "send-to" file previously specified by
* CBTF_SetSendToFile(). Any header generation and data encoding is performed
* by the caller. Here the data is treated purely as a buffer of bytes to be
* sent.
*
* @param size Size of the data to be sent (in bytes).
* @param data Pointer to the data to be sent.
* @return Integer "1" if succeeded or "0" if failed.
*
* @ingroup RuntimeAPI
*/
int CBTF_SendToFile(const unsigned size, const void* data)
{
unsigned encoded_size;
char buffer[8]; /* Large enough to encode one 32-bit unsigned integer */
XDR xdrs;
int fd;
/* Access our thread-local storage */
#ifdef USE_EXPLICIT_TLS
TLS* tls = CBTF_GetTLS(TLSKey);
#else
TLS* tls = &the_tls;
#endif
Assert(tls != NULL);
/* Create an XDR stream using the encoding buffer */
xdrmem_create(&xdrs, buffer, sizeof(buffer), XDR_ENCODE);
/* Encode the size of the data to be sent */
Assert(xdr_u_int(&xdrs, (void*)&size) == TRUE);
/* Get the encoded size */
encoded_size = xdr_getpos(&xdrs);
/* Close the XDR stream */
xdr_destroy(&xdrs);
/* Open the file for writing */
Assert((fd = open(tls->path, O_WRONLY | O_APPEND)) >= 0);
/* Write the size of the data to be sent */
Assert(write(fd, buffer, encoded_size) == encoded_size);
/* Write the data */
Assert(write(fd, data, size) == size);
/* fsync call taken out due to slow processing time reported at LLNL */
/* via Matt Legendre for a LLNL user. */
#if 0
/* Flush the data to disk. We could also test for fsyncdata
* and use that as our fsync vi a #define.
*/
Assert(fsync(fd) == 0);
#endif
/* Close the file */
Assert(close(fd) == 0);
/* Indicate success to the caller */
return 1;
}
示例2: make_rpc_packet
int
make_rpc_packet(char *buf, int buflen, u_long proc, struct rpc_msg *mp, voidp arg, XDRPROC_T_TYPE arg_xdr, AUTH *auth)
{
XDR msg_xdr;
int len;
/*
* Never cast pointers between different integer types, it breaks badly
* on big-endian platforms if those types have different sizes.
*
* Cast to a local variable instead, and use that variable's address.
*/
enum_t local_proc = (enum_t) proc;
xdrmem_create(&msg_xdr, buf, buflen, XDR_ENCODE);
/*
* Basic protocol header
*/
if (!xdr_callhdr(&msg_xdr, mp))
return -EIO;
/*
* Called procedure number
*/
if (!xdr_enum(&msg_xdr, &local_proc))
return -EIO;
/*
* Authorization
*/
if (!AUTH_MARSHALL(auth, &msg_xdr))
return -EIO;
/*
* Arguments
*/
if (!(*arg_xdr) (&msg_xdr, arg))
return -EIO;
/*
* Determine length
*/
len = xdr_getpos(&msg_xdr);
/*
* Throw away xdr
*/
xdr_destroy(&msg_xdr);
return len;
}
示例3: ocrecordcount
/* Counting records actually requires walking the xdr packet
so it is not necessarily cheap*/
size_t
ocrecordcount(OCstate* state, OCcontent* content)
{
int stat = OC_NOERR;
size_t count;
OCnode* node = content->node;
XDR* xdrs;
char tmp[BYTES_PER_XDR_UNIT];
OCASSERT((node != NULL));
OCASSERT((node->octype == OC_Sequence));
OCASSERT((content->mode == Recordmode));
/* If we are using memdata; then use that value */
if(content->memdata != NULL) {
return content->memdata->count;
}
xdrs = content->tree->data.xdrs;
OCASSERT((xdrs != NULL));
/* checkpoint the beginning of this instance*/
if(!content->xdrpos.valid) {
content->xdrpos.offset = xdr_getpos(xdrs);
content->xdrpos.valid = 1;
}
/* move to checkpoint position*/
if(!xdr_setpos(xdrs,content->xdrpos.offset)) return 0;
for(count=0;;count++) {
/* pick up the sequence record begin marker*/
/* extract the tag byte*/
if(!xdr_opaque(xdrs,tmp,sizeof(tmp))) return 0;
if(tmp[0] == StartOfoclist) {
/* skip instance*/
stat = ocskipinstance(content->node,xdrs);
if(stat != OC_NOERR) return 0;
} else if(tmp[0] == EndOfoclist) {
break; /* done with the count*/
} else {
oc_log(LOGERR,"missing/invalid begin/end record marker\n");
return 0;
}
}
/* move back to checkpoint position*/
if(!xdr_setpos(xdrs,content->xdrpos.offset)) return 0;
return count;
}
示例4: reply
void
reply (xdrproc_t xdrp, char *ret)
{
XDR xdr;
CLEANUP_FREE char *buf = NULL;
char lenbuf[4];
struct guestfs_message_header hdr;
uint32_t len;
buf = malloc (GUESTFS_MESSAGE_MAX);
if (!buf)
error (EXIT_FAILURE, errno, "malloc");
xdrmem_create (&xdr, buf, GUESTFS_MESSAGE_MAX, XDR_ENCODE);
memset (&hdr, 0, sizeof hdr);
hdr.prog = GUESTFS_PROGRAM;
hdr.vers = GUESTFS_PROTOCOL_VERSION;
hdr.direction = GUESTFS_DIRECTION_REPLY;
hdr.status = GUESTFS_STATUS_OK;
hdr.proc = proc_nr;
hdr.serial = serial;
if (!xdr_guestfs_message_header (&xdr, &hdr))
error (EXIT_FAILURE, 0, "failed to encode reply header");
if (xdrp) {
/* This can fail if the reply body is too large, for example
* if it exceeds the maximum message size. In that case
* we want to return an error message instead. (RHBZ#509597).
*/
if (!(*xdrp) (&xdr, ret)) {
reply_with_error ("guestfsd: failed to encode reply body\n(maybe the reply exceeds the maximum message size in the protocol?)");
xdr_destroy (&xdr);
return;
}
}
len = xdr_getpos (&xdr);
xdr_destroy (&xdr);
xdrmem_create (&xdr, lenbuf, 4, XDR_ENCODE);
xdr_u_int (&xdr, &len);
xdr_destroy (&xdr);
if (xwrite (sock, lenbuf, 4) == -1)
error (EXIT_FAILURE, 0, "xwrite failed");
if (xwrite (sock, buf, (size_t) len) == -1)
error (EXIT_FAILURE, 0, "xwrite failed");
}
示例5: virNetMessageEncodeHeader
/*
* @msg: the outgoing message, whose header to encode
*
* Encodes the length word and header of the message, setting the
* message offset ready to encode the payload. Leaves space
* for the length field later. Upon return bufferLength will
* refer to the total available space for message, while
* bufferOffset will refer to current space used by header
*
* returns 0 if successfully encoded, -1 upon fatal error
*/
int virNetMessageEncodeHeader(virNetMessagePtr msg)
{
XDR xdr;
int ret = -1;
unsigned int len = 0;
msg->bufferLength = VIR_NET_MESSAGE_MAX + VIR_NET_MESSAGE_LEN_MAX;
if (VIR_REALLOC_N(msg->buffer, msg->bufferLength) < 0) {
virReportOOMError();
return ret;
}
msg->bufferOffset = 0;
/* Format the header. */
xdrmem_create(&xdr,
msg->buffer,
msg->bufferLength,
XDR_ENCODE);
/* The real value is filled in shortly */
if (!xdr_u_int(&xdr, &len)) {
virReportError(VIR_ERR_RPC, "%s", _("Unable to encode message length"));
goto cleanup;
}
if (!xdr_virNetMessageHeader(&xdr, &msg->header)) {
virReportError(VIR_ERR_RPC, "%s", _("Unable to encode message header"));
goto cleanup;
}
len = xdr_getpos(&xdr);
xdr_setpos(&xdr, 0);
/* Fill in current length - may be re-written later
* if a payload is added
*/
if (!xdr_u_int(&xdr, &len)) {
virReportError(VIR_ERR_RPC, "%s", _("Unable to re-encode message length"));
goto cleanup;
}
msg->bufferOffset += len;
ret = 0;
cleanup:
xdr_destroy(&xdr);
return ret;
}
示例6: gvir_sandbox_rpcpacket_encode_header
/*
* @msg: the outgoing message, whose header to encode
*
* Encodes the length word and header of the message, setting the
* message offset ready to encode the payload. Leaves space
* for the length field later. Upon return bufferLength will
* refer to the total available space for message, while
* bufferOffset will refer to current space used by header
*
* returns 0 if successfully encoded, -1 upon fatal error
*/
gboolean gvir_sandbox_rpcpacket_encode_header(GVirSandboxRPCPacket *msg,
GError **error)
{
XDR xdr;
gboolean ret = FALSE;
unsigned int len = 0;
msg->bufferLength = sizeof(msg->buffer);
msg->bufferOffset = 0;
/* Format the header. */
xdrmem_create(&xdr,
msg->buffer,
msg->bufferLength,
XDR_ENCODE);
/* The real value is filled in shortly */
if (!xdr_u_int(&xdr, &len)) {
g_set_error(error, 0, 0,
"%s", "Unable to encode message length");
goto cleanup;
}
if (!xdr_GVirSandboxProtocolHeader(&xdr, &msg->header)) {
g_set_error(error, 0, 0,
"%s", "Unable to encode message header");
goto cleanup;
}
len = xdr_getpos(&xdr);
xdr_setpos(&xdr, 0);
/* Fill in current length - may be re-written later
* if a payload is added
*/
if (!xdr_u_int(&xdr, &len)) {
g_set_error(error, 0, 0,
"%s", "Unable to re-encode message length");
goto cleanup;
}
msg->bufferOffset += len;
ret = TRUE;
cleanup:
xdr_destroy(&xdr);
return ret;
}
示例7: request_meta_data
static int request_meta_data (const char *host, const char *name) /* {{{ */
{
Ganglia_metadata_msg msg;
char buffer[BUFF_SIZE];
unsigned int buffer_size;
XDR xdr;
size_t i;
memset (&msg, 0, sizeof (msg));
msg.id = gmetadata_request;
msg.Ganglia_metadata_msg_u.grequest.metric_id.host = strdup (host);
msg.Ganglia_metadata_msg_u.grequest.metric_id.name = strdup (name);
if ((msg.Ganglia_metadata_msg_u.grequest.metric_id.host == NULL)
|| (msg.Ganglia_metadata_msg_u.grequest.metric_id.name == NULL))
{
sfree (msg.Ganglia_metadata_msg_u.grequest.metric_id.host);
sfree (msg.Ganglia_metadata_msg_u.grequest.metric_id.name);
return (-1);
}
memset (buffer, 0, sizeof (buffer));
xdrmem_create (&xdr, buffer, sizeof (buffer), XDR_ENCODE);
if (!xdr_Ganglia_metadata_msg (&xdr, &msg))
{
sfree (msg.Ganglia_metadata_msg_u.grequest.metric_id.host);
sfree (msg.Ganglia_metadata_msg_u.grequest.metric_id.name);
return (-1);
}
buffer_size = xdr_getpos (&xdr);
DEBUG ("gmond plugin: Requesting meta data for %s/%s.",
host, name);
pthread_mutex_lock (&mc_send_sockets_lock);
for (i = 0; i < mc_send_sockets_num; i++)
sendto (mc_send_sockets[i].fd, buffer, (size_t) buffer_size,
/* flags = */ 0,
(struct sockaddr *) &mc_send_sockets[i].addr,
mc_send_sockets[i].addrlen);
pthread_mutex_unlock (&mc_send_sockets_lock);
sfree (msg.Ganglia_metadata_msg_u.grequest.metric_id.host);
sfree (msg.Ganglia_metadata_msg_u.grequest.metric_id.name);
return (0);
} /* }}} int request_meta_data */
示例8: ltspfs_getattr
void
ltspfs_getattr (int sockfd, XDR *in)
{
XDR out;
char path[PATH_MAX];
char output[LTSP_MAXBUF];
int i;
struct stat stbuf;
if (get_fn(sockfd, in, path)) {
if (debug)
info ("get_fn failed\n");
eacces(sockfd);
return;
}
if (lstat (path, &stbuf) == -1) {
status_return(sockfd, FAIL);
return;
}
xdrmem_create(&out, output, LTSP_MAXBUF, XDR_ENCODE);
i = 0;
xdr_int(&out, &i); /* First, the dummy length */
xdr_int(&out, &i); /* Then the 0 status return */
xdr_u_longlong_t(&out, &(stbuf.st_dev)); /* device */
xdr_u_longlong_t(&out, &(stbuf.st_ino)); /* inode */
xdr_u_int(&out, &(stbuf.st_mode)); /* protection */
xdr_u_int(&out, &(stbuf.st_nlink)); /* number of hard links */
xdr_u_int(&out, &(stbuf.st_uid)); /* user ID of owner */
xdr_u_int(&out, &(stbuf.st_gid)); /* group ID of owner */
xdr_u_longlong_t(&out, &(stbuf.st_rdev)); /* device type */
xdr_longlong_t(&out, &(stbuf.st_size)); /* total size, in bytes */
xdr_long(&out, &(stbuf.st_blksize)); /* blocksize for fs I/O */
xdr_longlong_t(&out, &(stbuf.st_blocks)); /* number of blocks allocated */
xdr_long(&out, &(stbuf.st_atime)); /* time of last access */
xdr_long(&out, &(stbuf.st_mtime)); /* time of last modification */
xdr_long(&out, &(stbuf.st_ctime)); /* time of last status change */
i = xdr_getpos(&out); /* Get our position */
xdr_setpos(&out, 0); /* Rewind to the beginning */
xdr_int(&out, &i); /* Rewrite with proper length */
xdr_destroy(&out);
if (debug)
info("returning OK");
writen(sockfd, output, i);
}
示例9: sodero_deserialize_UDP_report_v1
int sodero_deserialize_UDP_report_v1(char *buffer, int numbytes, int *start_pos,
const int num_max_elements, TSoderoUDPReportMsg *stored_data) {
XDR xdr_handle;
int result, size, num_element;
TSoderoUDPReportMsg incoming_data;
xdrmem_create(&xdr_handle, buffer, SEND_RECV_BUFFER_SIZE, XDR_DECODE);
int curr_pos, prev_pos;
prev_pos = *start_pos;
curr_pos = prev_pos;
num_element = 0;
for (; curr_pos < numbytes;) {
// printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
xdr_setpos(&xdr_handle, curr_pos);
memset(&incoming_data, 0, sizeof(TSoderoUDPReportMsg));
// result = xdr_TSoderoUDPReport(& xdr_handle, &incoming_data);
result = xdr_TSoderoUDPReportMsg(&xdr_handle,
&stored_data[num_element]);
if (result != TRUE) {
// error
printf("Decoding error\n");
return 0;
}
size = xdr_getpos(&xdr_handle);
// printf("Decode %d bytes of encoded data\n", size - curr_pos);
curr_pos = size;
num_element++;
if (num_element == num_max_elements) {
// printf("Reach max report data elements\n");
// printf("-------------------------------------------------------\n\n");
break;
}
// printf("-------------------------------------------------------\n\n");
}
*start_pos = curr_pos;
xdr_destroy(&xdr_handle);
return num_element;
}
示例10: send_dirent_info
/* Extract the information from the entry, serialize and send it out.
* Return 0 on success, -1 on error.
*/
static int
send_dirent_info (TSK_FS_FILE *fsfile, const char *path)
{
XDR xdr;
int ret = 0;
size_t len = 0;
struct guestfs_int_tsk_dirent dirent;
CLEANUP_FREE char *buf = NULL, *fname = NULL;
/* Set dirent fields */
memset (&dirent, 0, sizeof dirent);
/* Build the full relative path of the entry */
ret = asprintf (&fname, "%s%s", path, fsfile->name->name);
if (ret < 0) {
perror ("asprintf");
return -1;
}
dirent.tsk_inode = fsfile->name->meta_addr;
dirent.tsk_type = file_type (fsfile);
dirent.tsk_name = fname;
dirent.tsk_flags = file_flags (fsfile);
file_metadata (fsfile->meta, &dirent);
/* Serialize tsk_dirent struct. */
buf = malloc (GUESTFS_MAX_CHUNK_SIZE);
if (buf == NULL) {
perror ("malloc");
return -1;
}
xdrmem_create (&xdr, buf, GUESTFS_MAX_CHUNK_SIZE, XDR_ENCODE);
ret = xdr_guestfs_int_tsk_dirent (&xdr, &dirent);
if (ret == 0) {
perror ("xdr_guestfs_int_tsk_dirent");
return -1;
}
len = xdr_getpos (&xdr);
xdr_destroy (&xdr);
/* Send serialised tsk_dirent out. */
return send_file_write (buf, len);
}
示例11: virNetMessageDecodeLength
int virNetMessageDecodeLength(virNetMessagePtr msg)
{
XDR xdr;
unsigned int len;
int ret = -1;
xdrmem_create(&xdr, msg->buffer,
msg->bufferLength, XDR_DECODE);
if (!xdr_u_int(&xdr, &len)) {
virReportError(VIR_ERR_RPC, "%s", _("Unable to decode message length"));
goto cleanup;
}
msg->bufferOffset = xdr_getpos(&xdr);
if (len < VIR_NET_MESSAGE_LEN_MAX) {
virReportError(VIR_ERR_RPC,
_("packet %d bytes received from server too small, want %d"),
len, VIR_NET_MESSAGE_LEN_MAX);
goto cleanup;
}
/* Length includes length word - adjust to real length to read. */
len -= VIR_NET_MESSAGE_LEN_MAX;
if (len > VIR_NET_MESSAGE_MAX) {
virReportError(VIR_ERR_RPC,
_("packet %d bytes received from server too large, want %d"),
len, VIR_NET_MESSAGE_MAX);
goto cleanup;
}
/* Extend our declared buffer length and carry
on reading the header + payload */
msg->bufferLength += len;
if (VIR_REALLOC_N(msg->buffer, msg->bufferLength) < 0) {
virReportOOMError();
goto cleanup;
}
VIR_DEBUG("Got length, now need %zu total (%u more)",
msg->bufferLength, len);
ret = 0;
cleanup:
xdr_destroy(&xdr);
return ret;
}
示例12: ltspfs_readdir
void
ltspfs_readdir (int sockfd, XDR *in)
{
XDR out;
char path[PATH_MAX];
char output[LTSP_MAXBUF];
DIR *dp;
char *nameptr;
struct dirent *de;
int i;
if (get_fn(sockfd, in, path)) { /* Get the dir name */
eacces(sockfd);
return;
}
dp = opendir (path);
if (dp == NULL) {
status_return(sockfd, FAIL); /* opendir failed */
return;
}
while ((de = readdir (dp)) != NULL) {
xdrmem_create(&out, output, LTSP_MAXBUF, XDR_ENCODE);
i = 0;
xdr_int(&out, &i); /* First, the dummy length */
i = LTSP_STATUS_CONT;
xdr_int(&out, &i); /* Then the 2 status return */
xdr_u_longlong_t(&out, &(de->d_ino)); /* Inode */
xdr_u_char(&out, &(de->d_type)); /* type */
nameptr = de->d_name;
xdr_string(&out, &nameptr, PATH_MAX); /* filename */
i = xdr_getpos(&out); /* Get our position */
xdr_setpos(&out, 0); /* Rewind to the beginning */
xdr_int(&out, &i); /* Rewrite with proper length */
xdr_destroy(&out);
if (debug)
info("returning %s", de->d_name);
writen(sockfd, output, i);
}
closedir (dp);
status_return(sockfd, OK);
}
示例13: apply_buf
static bool_t
apply_buf(bool_t (*fn)(), caddr_t in, u_int size)
{
bool_t result;
char out[BUFSIZ];
XDR xin, xout;
xdrbuf_create(&xin, 0, XDR_ENCODE);
/* Inline to force grow. */
if (!fn(&xin, in) || !xdr_inline(&xin, 2 * BUFSIZ)) {
xdr_destroy(&xin);
return FALSE;
}
xdrmem_create(&xout, xin.x_base, xdr_getpos(&xin), XDR_DECODE);
result = fn(&xout, out) && 0 == memcmp(in, out, size);
xdr_destroy(&xin);
return result;
}
示例14: smb_netfileinfo_encode
/*
* Encode an smb_netfileinfo_t into a buffer.
*/
int
smb_netfileinfo_encode(smb_netfileinfo_t *info, uint8_t *buf,
uint32_t buflen, uint_t *nbytes)
{
XDR xdrs;
int rc = 0;
xdrmem_create(&xdrs, (const caddr_t)buf, buflen, XDR_ENCODE);
if (!smb_netfileinfo_xdr(&xdrs, info))
rc = -1;
if (nbytes != NULL)
*nbytes = xdr_getpos(&xdrs);
xdr_destroy(&xdrs);
return (rc);
}
示例15: main
int main()
{
XDR xdr;
char buffer[512];
FSINFO3args args;
FSINFO3res res;
memset(&args, 0, sizeof args);
memset(&res, 0, sizeof res);
char rootHandle[28];
args.fsroot.data.data_val = (char*) rootHandle;
args.fsroot.data.data_len = sizeof(rootHandle);
xdrmem_create(&xdr, buffer, sizeof(buffer), XDR_ENCODE);
xdr_FSINFO3args(&xdr, &args);
printf("%d\n", xdr_getpos(&xdr));
xdr_destroy(&xdr);
return 0;
}