本文整理汇总了C++中remaining_buf函数的典型用法代码示例。如果您正苦于以下问题:C++ remaining_buf函数的具体用法?C++ remaining_buf怎么用?C++ remaining_buf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了remaining_buf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: unpackmem_malloc
/*
* Given a buffer containing a network byte order 16-bit integer,
* and an arbitrary data string, copy the data string into the location
* specified by valp. Also return the sizes of 'valp' in bytes.
* Adjust buffer counters.
* NOTE: valp is set to point into a newly created buffer,
* the caller is responsible for calling free() on *valp
* if non-NULL (set to NULL on zero size buffer value)
*/
int unpackmem_malloc(char **valp, uint32_t * size_valp, Buf buffer)
{
uint32_t ns;
if (remaining_buf(buffer) < sizeof(ns))
return SLURM_ERROR;
memcpy(&ns, &buffer->head[buffer->processed], sizeof(ns));
*size_valp = ntohl(ns);
buffer->processed += sizeof(ns);
if (*size_valp > MAX_PACK_MEM_LEN) {
error("%s: Buffer to be unpacked is too large (%u > %u)",
__func__, *size_valp, MAX_PACK_MEM_LEN);
return SLURM_ERROR;
}
else if (*size_valp > 0) {
if (remaining_buf(buffer) < *size_valp)
return SLURM_ERROR;
*valp = malloc(*size_valp);
if (*valp == NULL) {
log_oom(__FILE__, __LINE__, __func__);
abort();
}
memcpy(*valp, &buffer->head[buffer->processed],
*size_valp);
buffer->processed += *size_valp;
} else
*valp = NULL;
return SLURM_SUCCESS;
}
示例2: unpackmem
/*
* Given a buffer containing a network byte order 16-bit integer,
* and an arbitrary data string, copy the data string into the location
* specified by valp. Also return the sizes of 'valp' in bytes.
* Adjust buffer counters.
* NOTE: The caller is responsible for the management of valp and
* insuring it has sufficient size
*/
int unpackmem(char *valp, uint32_t * size_valp, Buf buffer)
{
uint32_t ns;
if (remaining_buf(buffer) < sizeof(ns))
return SLURM_ERROR;
memcpy(&ns, &buffer->head[buffer->processed], sizeof(ns));
*size_valp = ntohl(ns);
buffer->processed += sizeof(ns);
if (*size_valp > MAX_PACK_MEM_LEN) {
error("%s: Buffer to be unpacked is too large (%u > %u)",
__func__, *size_valp, MAX_PACK_MEM_LEN);
return SLURM_ERROR;
}
else if (*size_valp > 0) {
if (remaining_buf(buffer) < *size_valp)
return SLURM_ERROR;
memcpy(valp, &buffer->head[buffer->processed], *size_valp);
buffer->processed += *size_valp;
} else
*valp = 0;
return SLURM_SUCCESS;
}
示例3: packmem
/*
* Given a pointer to memory (valp) and a size (size_val), convert
* size_val to network byte order and store at buffer followed by
* the data at valp. Adjust buffer counters.
*/
void packmem(char *valp, uint32_t size_val, Buf buffer)
{
uint32_t ns = htonl(size_val);
if (size_val > MAX_PACK_MEM_LEN) {
error("%s: Buffer to be packed is too large (%u > %u)",
__func__, size_val, MAX_PACK_MEM_LEN);
return;
}
if (remaining_buf(buffer) < (sizeof(ns) + size_val)) {
if ((buffer->size + size_val + BUF_SIZE) > MAX_BUF_SIZE) {
error("%s: Buffer size limit exceeded (%u > %u)",
__func__, (buffer->size + size_val + BUF_SIZE),
MAX_BUF_SIZE);
return;
}
buffer->size += (size_val + BUF_SIZE);
xrealloc_nz(buffer->head, buffer->size);
}
memcpy(&buffer->head[buffer->processed], &ns, sizeof(ns));
buffer->processed += sizeof(ns);
if (size_val) {
memcpy(&buffer->head[buffer->processed], valp, size_val);
buffer->processed += size_val;
}
}
示例4: unpackstr_array
/*
* Given 'buffer' pointing to a network byte order 16-bit integer
* (size) and a array of strings store the number of strings in
* 'size_valp' and the array of strings in valp
* NOTE: valp is set to point into a newly created buffer,
* the caller is responsible for calling xfree on *valp
* if non-NULL (set to NULL on zero size buffer value)
*/
int unpackstr_array(char ***valp, uint32_t * size_valp, Buf buffer)
{
int i;
uint32_t ns;
uint32_t uint32_tmp;
if (remaining_buf(buffer) < sizeof(ns))
return SLURM_ERROR;
memcpy(&ns, &buffer->head[buffer->processed], sizeof(ns));
*size_valp = ntohl(ns);
buffer->processed += sizeof(ns);
if (*size_valp > MAX_PACK_ARRAY_LEN) {
error("%s: Buffer to be unpacked is too large (%u > %u)",
__func__, *size_valp, MAX_PACK_ARRAY_LEN);
return SLURM_ERROR;
}
else if (*size_valp > 0) {
*valp = xmalloc_nz(sizeof(char *) * (*size_valp + 1));
for (i = 0; i < *size_valp; i++) {
if (unpackmem_xmalloc(&(*valp)[i], &uint32_tmp, buffer))
return SLURM_ERROR;
}
(*valp)[i] = NULL; /* NULL terminated array so that execle */
/* can detect end of array */
} else
*valp = NULL;
return SLURM_SUCCESS;
}
示例5: packdouble
/*
* Given a double, multiple by FLOAT_MULT and then
* typecast to a uint64_t in host byte order, convert to network byte order
* store in buffer, and adjust buffer counters.
* NOTE: There is an IEEE standard format for double.
*/
void packdouble(double val, Buf buffer)
{
uint64_t nl;
union {
double d;
uint64_t u;
} uval;
/* The 0.5 is here to round off. We have found on systems going out
* more than 15 decimals will mess things up, but this corrects it. */
uval.d = (val * FLOAT_MULT);
nl = HTON_uint64(uval.u);
if (remaining_buf(buffer) < sizeof(nl)) {
if ((buffer->size + BUF_SIZE) > MAX_BUF_SIZE) {
error("%s: Buffer size limit exceeded (%u > %u)",
__func__, (buffer->size + BUF_SIZE),
MAX_BUF_SIZE);
return;
}
buffer->size += BUF_SIZE;
xrealloc_nz(buffer->head, buffer->size);
}
memcpy(&buffer->head[buffer->processed], &nl, sizeof(nl));
buffer->processed += sizeof(nl);
}
示例6: unpack8
/*
* Given a buffer containing a network byte order 8-bit integer,
* store a host integer at 'valp', and adjust buffer counters.
*/
int unpack8(uint8_t * valp, Buf buffer)
{
if (remaining_buf(buffer) < sizeof(uint8_t))
return SLURM_ERROR;
memcpy(valp, &buffer->head[buffer->processed], sizeof(uint8_t));
buffer->processed += sizeof(uint8_t);
return SLURM_SUCCESS;
}
示例7: unpack32
/*
* Given a buffer containing a network byte order 32-bit integer,
* store a host integer at 'valp', and adjust buffer counters.
*/
int unpack32(uint32_t * valp, Buf buffer)
{
uint32_t nl;
if (remaining_buf(buffer) < sizeof(nl))
return SLURM_ERROR;
memcpy(&nl, &buffer->head[buffer->processed], sizeof(nl));
*valp = ntohl(nl);
buffer->processed += sizeof(nl);
return SLURM_SUCCESS;
}
示例8: unpackmem_array
/*
* Given a pointer to memory (valp), size (size_val), and buffer,
* store the buffer contents into memory
*/
int unpackmem_array(char *valp, uint32_t size_valp, Buf buffer)
{
if (remaining_buf(buffer) >= size_valp) {
memcpy(valp, &buffer->head[buffer->processed], size_valp);
buffer->processed += size_valp;
return SLURM_SUCCESS;
} else {
*valp = 0;
return SLURM_ERROR;
}
}
示例9: unpack16
/*
* Given a buffer containing a network byte order 16-bit integer,
* store a host integer at 'valp', and adjust buffer counters.
*/
int unpack16(uint16_t * valp, Buf buffer)
{
uint16_t ns;
if (remaining_buf(buffer) < sizeof(ns))
return SLURM_ERROR;
memcpy(&ns, &buffer->head[buffer->processed], sizeof(ns));
*valp = ntohs(ns);
buffer->processed += sizeof(ns);
return SLURM_SUCCESS;
}
示例10: unpack_time
int unpack_time(time_t * valp, Buf buffer)
{
int64_t n64;
if (remaining_buf(buffer) < sizeof(n64))
return SLURM_ERROR;
memcpy(&n64, &buffer->head[buffer->processed], sizeof(n64));
buffer->processed += sizeof(n64);
*valp = (time_t) NTOH_int64(n64);
return SLURM_SUCCESS;
}
示例11: unpackmem
/*
* Given a buffer containing a network byte order 16-bit integer,
* and an arbitrary data string, copy the data string into the location
* specified by valp. Also return the sizes of 'valp' in bytes.
* Adjust buffer counters.
* NOTE: The caller is responsible for the management of valp and
* insuring it has sufficient size
*/
int unpackmem(char *valp, uint32_t * size_valp, Buf buffer)
{
uint32_t ns;
if (remaining_buf(buffer) < sizeof(ns))
return SLURM_ERROR;
memcpy(&ns, &buffer->head[buffer->processed], sizeof(ns));
*size_valp = ntohl(ns);
buffer->processed += sizeof(ns);
if (*size_valp > MAX_PACK_MEM_LEN)
return SLURM_ERROR;
else if (*size_valp > 0) {
if (remaining_buf(buffer) < *size_valp)
return SLURM_ERROR;
memcpy(valp, &buffer->head[buffer->processed], *size_valp);
buffer->processed += *size_valp;
} else
*valp = 0;
return SLURM_SUCCESS;
}
示例12: pack8
/*
* Given a 8-bit integer in host byte order, convert to network byte order
* store in buffer, and adjust buffer counters.
*/
void pack8(uint8_t val, Buf buffer)
{
if (remaining_buf(buffer) < sizeof(uint8_t)) {
if (buffer->size > (MAX_BUF_SIZE - BUF_SIZE)) {
error("pack8: buffer size too large");
return;
}
buffer->size += BUF_SIZE;
xrealloc(buffer->head, buffer->size);
}
memcpy(&buffer->head[buffer->processed], &val, sizeof(uint8_t));
buffer->processed += sizeof(uint8_t);
}
示例13: packmem_array
/*
* Given a pointer to memory (valp), size (size_val), and buffer,
* store the memory contents into the buffer
*/
void packmem_array(char *valp, uint32_t size_val, Buf buffer)
{
if (remaining_buf(buffer) < size_val) {
if (buffer->size > (MAX_BUF_SIZE - size_val - BUF_SIZE)) {
error("packmem_array: buffer size too large");
return;
}
buffer->size += (size_val + BUF_SIZE);
xrealloc(buffer->head, buffer->size);
}
memcpy(&buffer->head[buffer->processed], valp, size_val);
buffer->processed += size_val;
}
示例14: pack8
/*
* Given a 8-bit integer in host byte order, convert to network byte order
* store in buffer, and adjust buffer counters.
*/
void pack8(uint8_t val, Buf buffer)
{
if (remaining_buf(buffer) < sizeof(uint8_t)) {
if ((buffer->size + BUF_SIZE) > MAX_BUF_SIZE) {
error("%s: Buffer size limit exceeded (%u > %u)",
__func__, (buffer->size + BUF_SIZE),
MAX_BUF_SIZE);
return;
}
buffer->size += BUF_SIZE;
xrealloc_nz(buffer->head, buffer->size);
}
memcpy(&buffer->head[buffer->processed], &val, sizeof(uint8_t));
buffer->processed += sizeof(uint8_t);
}
示例15: pack_time
/*
* Given a time_t in host byte order, promote it to int64_t, convert to
* network byte order, store in buffer and adjust buffer acc'd'ngly
*/
void pack_time(time_t val, Buf buffer)
{
int64_t n64 = HTON_int64((int64_t) val);
if (remaining_buf(buffer) < sizeof(n64)) {
if (buffer->size > (MAX_BUF_SIZE - BUF_SIZE)) {
error("pack_time: buffer size too large");
return;
}
buffer->size += BUF_SIZE;
xrealloc(buffer->head, buffer->size);
}
memcpy(&buffer->head[buffer->processed], &n64, sizeof(n64));
buffer->processed += sizeof(n64);
}