NewMadeleine

Documentation

nm_pack_headers.c
/*
* NewMadeleine
* Copyright (C) 2006-2022 (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 "../common/nm_examples_helper.h"
#define SIZE (64 * 1024)
#define NHEADERS 40
int main(int argc, char**argv)
{
nm_examples_init(&argc, argv);
char*buf = malloc(SIZE + 1);
{
int i;
int h[NHEADERS];
for(i = 0; i < NHEADERS; i++)
{
/* note: we use an array here and don't reuse the same local variable
for each pack, since data must remain untouched until nm_end_packing().
*/
h[i] = i;
nm_pack_express(&cnx, &h[i], sizeof(h[i]));
}
nm_pack(&cnx, buf, SIZE);
}
else
{
int i;
for(i = 0; i < NHEADERS; i++)
{
int h = -1;
nm_unpack_express(&cnx, &h, sizeof(h));
printf("received h[%d] = %d\n", i, h);
if(h != i)
{
NM_WARN("corrupted header: expected = %d; received = %d\n", i, h);
}
}
nm_unpack(&cnx, buf, SIZE);
}
free(buf);
return 0;
}
int nm_pack(nm_pack_cnx_t *p_cnx, const void *ptr, nm_len_t len)
Append a data fragment to the current message.
int nm_end_packing(nm_pack_cnx_t *p_cnx)
End building and send the current message.
int nm_end_unpacking(nm_pack_cnx_t *p_cnx)
End receiving and flush extraction of the current message.
int nm_begin_unpacking(nm_session_t p_session, nm_gate_t p_gate, nm_tag_t tag, nm_pack_cnx_t *p_cnx)
Start receiving and extracting a new message.
int nm_begin_packing(nm_session_t p_session, nm_gate_t p_gate, nm_tag_t tag, nm_pack_cnx_t *p_cnx)
Start building a new message for sending.
int nm_unpack(nm_pack_cnx_t *p_cnx, void *ptr, nm_len_t len)
Extract a data fragment from the current message; data will actually be available after end_unpacking...
int nm_unpack_express(nm_pack_cnx_t *p_cnx, void *ptr, nm_len_t len)
Extract a data fragment from the current message in express mode: data will be available upon functio...
int nm_pack_express(nm_pack_cnx_t *p_cnx, const void *ptr, nm_len_t len)
Append a data fragment to the current message, in express mode: data will be aavailable immediately a...
without even the implied warranty of !MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU !General Public License for more details !mpif h
Definition: mpif.h:19
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
#define NM_WARN(format,...)
Definition: nm_log.h:34
Content for the request in the pack interface.