Skip to content

Instantly share code, notes, and snippets.

@mhowlett
Last active December 23, 2015 05:58
Show Gist options
  • Save mhowlett/6590217 to your computer and use it in GitHub Desktop.
Save mhowlett/6590217 to your computer and use it in GitHub Desktop.
nanomsg large message problem on Ubuntu 12.04
#include <stdio.h>
#include "nanomsg/nn.h"
#include "nanomsg/reqrep.h"
// On Ubuntu 12.04, the final lines printed by the server are all 0 (or quite possibly garbage) instead
// of cycling through numbers 0 to 126. For smaller values of N there is no problem. The Vagrantfile in
// https://github.com/mhowlett/NNanomsg should produce an environment in which this happens.
// Under Windows I think there is no problem (based on running a more complex application on both platforms).
// The problem seems to occur with the current master as well as v0.1
int main(int argc, char **argv)
{
char *address = "tcp://127.0.0.1:5115";
const int N = 127000;
int i;
int rc;
if (argv[1][0] == 'c')
{
int req = nn_socket(AF_SP, NN_REQ);
nn_connect(req, address);
char buf[N];
for (i=0; i<N; ++i)
{
buf[i] = (char)(i%127);
}
rc = nn_send(req, buf, N, 0);
if (rc < 0)
{
perror(NULL);
}
sleep(10000);
}
else if (argv[1][0] == 's')
{
int rep = nn_socket(AF_SP, NN_REP);
nn_bind(rep, address);
char *data;
rc = nn_recv(rep, &data, NN_MSG, 0);
if (rc < 0)
{
perror(NULL);
}
else
{
for (i=0; i<N; ++i)
{
printf("%d\n", data[i]);
}
printf("# bytes: %d\n", rc);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment