NewMadeleine

Documentation

« back to PM2 home.
nm_sr_peek.c

set header size on given request, i.e.

set header size on given request, i.e. send at least this size eagerly

/*
* NewMadeleine
* Copyright (C) 2016-2024 (see AUTHORS file)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <assert.h>
#include "../common/nm_examples_helper.h"
const char msg[] = "Hello, world!";
int main(int argc, char**argv)
{
nm_len_t len = sizeof(int) + strlen(msg) + 1;
void*buf = malloc(len);
nm_sr_request_t request;
nm_examples_init(&argc, argv);
{
memset(buf, 0, len);
struct nm_data_s data;
nm_data_contiguous_build(&data, buf, sizeof(int));
int rc = nm_sr_recv_peek(p_session, &request, &data);
assert(rc == NM_ESUCCESS);
int*p_len = buf;
printf("SUCCESS- rc = %d; header len = %d\n", rc, *p_len);
nm_sr_rwait(p_session, &request);
printf("buffer contents: %s\n", (char*)(buf + sizeof(int)));
}
else
{
int*p_len = buf;
strcpy(buf + sizeof(int), msg);
*p_len = len;
puk_sleep(1);
printf("# sender- header len = %d\n", *p_len);
nm_sr_isend(p_session, p_gate, 0, buf, len, &request);
nm_sr_swait(p_session, &request);
}
free(buf);
return 0;
}
@ NM_ESUCCESS
successful operation
Definition nm_errno.h:36
static void nm_data_contiguous_build(struct nm_data_s *p_data, void *ptr, nm_len_t len)
Definition nm_data.h:355
static int is_server
static void nm_examples_init(int *argc, char *argv[])
static nm_session_t p_session
static void nm_examples_exit(void)
static nm_gate_t p_gate
uint16_t len
chunk len
Definition nm_headers.h:0
static void nm_sr_recv_init(nm_session_t p_session, nm_sr_request_t *p_request)
static int nm_sr_recv_peek(nm_session_t p_session, nm_sr_request_t *p_request, const struct nm_data_s *p_data)
peek for already received (unexpected) data
static int nm_sr_swait(nm_session_t p_session, nm_sr_request_t *p_request)
Wait for the completion of a non blocking send request.
static void nm_sr_recv_data_wait(nm_session_t p_session, nm_sr_request_t *p_request)
waits for first byte of data to be available, for a request posted without data descriptor
static int nm_sr_rwait(nm_session_t p_session, nm_sr_request_t *p_request)
Wait for the completion of a non blocking receive request.
static int nm_sr_recv_post(nm_session_t p_session, nm_sr_request_t *p_request)
posts the receive request to the scheduler
static void nm_sr_recv_match(nm_session_t p_session, nm_sr_request_t *p_request, nm_gate_t p_gate, nm_tag_t tag, nm_tag_t mask)
match the request with given gate/tag/mask
static void nm_sr_recv_unpack_contiguous(nm_session_t p_session, nm_sr_request_t *p_request, void *ptr, nm_len_t len)
static int nm_sr_isend(nm_session_t p_session, nm_gate_t p_gate, nm_tag_t tag, const void *data, nm_len_t len, nm_sr_request_t *p_request)
Post a non blocking send request.
#define NM_ANY_GATE
Definition nm_types.h:41
uint64_t nm_len_t
data length used by nmad
Definition nm_types.h:68
#define NM_TAG_MASK_FULL
tag mask that matches all bits
Definition nm_types.h:61
a data descriptor, used to pack/unpack data from app layout to/from contiguous buffers
Definition nm_data.h:196
internal defintion of the sendrecv request