MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / read_user_data

Function read_user_data

net/net.c:3337–3403  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3335}
3336
3337static int read_user_data(host_node_type *host_node_ptr, int *type, int *seqnum,
3338 int *needack, int *datalen, void **data,
3339 int *malloced)
3340{
3341 int rc;
3342 net_send_message_header msghdr;
3343 uint8_t databf[NET_SEND_MESSAGE_HEADER_LEN], *p_buf, *p_buf_end;
3344 netinfo_type *netinfo_ptr = host_node_ptr->netinfo_ptr;
3345 SBUF2 *sb = host_node_ptr->sb;
3346
3347 *malloced = 0;
3348
3349 rc = read_stream(netinfo_ptr, host_node_ptr, sb, &databf, sizeof(databf));
3350 if (rc != sizeof(msghdr)) {
3351 host_node_errf(LOGMSG_ERROR, host_node_ptr,
3352 "read_user_data:error reading user data header\n");
3353 goto fail;
3354 }
3355
3356 p_buf = databf;
3357 p_buf_end = (databf + NET_SEND_MESSAGE_HEADER_LEN);
3358
3359 net_send_message_header_get(&msghdr, p_buf, p_buf_end);
3360
3361 *type = msghdr.usertype;
3362 *seqnum = msghdr.seqnum;
3363 *needack = msghdr.waitforack;
3364 *datalen = msghdr.datalen;
3365
3366 if (*datalen > 0) {
3367 if (netinfo_ptr->trace && debug_switch_net_verbose())
3368 logmsg(LOGMSG_ERROR, "Reading %d bytes %llu\n", *datalen, gettmms());
3369
3370 if (*datalen < (netinfo_ptr->user_data_buf_size)) {
3371 *data = host_node_ptr->user_data_buf;
3372 *malloced = 0;
3373 } else {
3374 *data = HOST_MALLOC(host_node_ptr, *datalen);
3375 *malloced = 1;
3376 }
3377
3378 if (*data == NULL) {
3379 host_node_errf(LOGMSG_ERROR, host_node_ptr, "%s: malloc %d failed\n", __func__,
3380 *datalen);
3381 goto fail;
3382 }
3383 rc = read_stream(netinfo_ptr, host_node_ptr, sb, *data, *datalen);
3384 if (rc != *datalen) {
3385 host_node_errf(LOGMSG_ERROR, host_node_ptr,
3386 "read_user_data:error reading user_data, "
3387 "wanted %d bytes, got %d\n",
3388 *datalen, rc);
3389
3390 if (*malloced)
3391 free(*data);
3392
3393 goto fail;
3394 }

Callers 1

process_user_messageFunction · 0.85

Calls 7

read_streamFunction · 0.85
host_node_errfFunction · 0.85
debug_switch_net_verboseFunction · 0.85
gettmmsFunction · 0.85
freeFunction · 0.85
logmsgFunction · 0.50

Tested by

no test coverage detected