Hi all

We are facing quite a curious issue with ZMQ. A simple server is used to queue 
files to a client which process the files and queues the results back to the 
server. This setup works fine without our application code doing the actual 
processing, but once the application code is incorporated, there is an error in 
our device driver (part of
our application). What's mystifying is that our application works fine when ZMQ 
is not used and files are instead read from the disk.

When we run the program with the ZMQ, the system hangs. The debug messages 
report an error that is, "Unable to handle kernel paging request".
When we commented the memcpy() function call in the driver code it worked fine 
though we don't understand why a memcpy() function leads to a system crash.
The file that the server sends in is of 2KB.

We are currently working on the Debian distribution of Linux, the kernel 
version used being 2.6.39.The system configuration is as follows;

Intel Xeon E31245 processor @ 3.3GHz
4 GB RAM and a 250GB 6.0Gb/s SATA Hard Drive.

Can you please help us in finding out where the problem is.

Is it the ZMQ that is being used in our application?
Or is it the application that seems to be causing the problem( though we are 
clueless as to why it's causing a problem now when it worked fine when the 
files were read from the disk)?

I have attached the server and client programs for your reference.

Thank you.

Regards
Mahathi Prabhala
TIMES-7(Special)
IBG-Technology,Media&Entertainment
SDC,Bangalore
[cid:[email protected]]


________________________________

DISCLAIMER:
This email (including any attachments) is intended for the sole use of the 
intended recipient/s and may contain material that is CONFIDENTIAL AND PRIVATE 
COMPANY INFORMATION. Any review or reliance by others or copying or 
distribution or forwarding of any or all of the contents in this message is 
STRICTLY PROHIBITED. If you are not the intended recipient, please contact the 
sender by email and delete all copies; your cooperation in this regard is 
appreciated.

<<inline: image001.gif>>

//
// Hello World server
// Binds REP socket to tcp://*:5555
// Expects "Hello" from client, replies with "World"
//
#include <zmq.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h> 

void *socket;

static char *s_recv (void *socket) {
  zmq_msg_t message; 
  zmq_msg_init (&message);
  zmq_recv (socket, &message, 0);
  int size = zmq_msg_size (&message);
  char *string = malloc (size + 1);
  memcpy (string, zmq_msg_data (&message), size);
  zmq_msg_close (&message);
  string [size] = 0;
  return (string);
}

static int send_file (char *file_path) {
  int fd; struct stat s; int *buf;
  int rc = 1; zmq_msg_t message;

  if ((fd = open(file_path, O_RDONLY)) == -1) {printf("\nError opening file 
%s\n", file_path); exit(1);}
  else {
    if (fstat(fd, &s) == -1) {printf("\nError fstating file %s %d\n", 
file_path, fd); exit(1);}
    else {
      if ((buf = (int *)malloc(s.st_size)) == NULL) {printf("\nError malloc 
returned NULL\n"); exit(1);}
      else {
        if (s.st_size % 4 != 0) {printf("\nError cfg file size not mulitple of 
4 (%d)\n", s.st_size); exit(1);}
        else {
          zmq_msg_init_size (&message, s.st_size);
          if ((read(fd,zmq_msg_data (&message),s.st_size)) < (s.st_size))
            {printf("\nError reading file (less than %d)\n", s.st_size); 
exit(1);}
          else {
                    rc = zmq_send (socket, &message, 0);
                    zmq_msg_close (&message);
          }
        }
        free(buf);
      }
      if(close(fd) == -1) {printf("\nError closing file %s %d\n", file_path, 
fd); exit(1);}
    }
  }
  return (rc);
}


int main (void)
{
  int i; void *context = zmq_init (1);
 
  void *push = zmq_socket (context, ZMQ_PUSH);
  zmq_bind (push, "tcp://*:5555");
  socket=push;
  for(i=0; i<8; ++i)
    send_file("filename");
  zmq_close (push);

  void *pull = zmq_socket (context, ZMQ_PULL);
  zmq_bind (pull, "tcp://*:5556");

  for(i=0; i<8; ++i)
    printf("\n%s\n",s_recv(pull));
  zmq_close (pull);
  zmq_term (context);
  return 0;
}
//
// Hello World client
// Connects REQ socket to tcp://localhost:5555
// Sends "Hello" to server, expects "World" back
//
#include <zmq.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>

static char *s_recv (void *socket) {
  zmq_msg_t message; 
  zmq_msg_init (&message);
  zmq_recv (socket, &message, 0);
  int size = zmq_msg_size (&message);
  char *string = malloc (size + 1);
  memcpy (string, zmq_msg_data (&message), size);
  zmq_msg_close (&message);
  string [size] = 0;
  return (string);
}

static int s_send (void *socket, char *string) {
  int rc;
  zmq_msg_t message;
  zmq_msg_init_size (&message, strlen (string));
  memcpy (zmq_msg_data (&message), string, strlen (string));
  rc = zmq_send (socket, &message, 0);
  zmq_msg_close (&message);
  return (rc);
}

int main (void)
{
  int i; void *context = zmq_init (1);
  char *buf;
  void *pull = zmq_socket (context, ZMQ_PULL);
  zmq_connect (pull, "tcp://localhost:5555");
  
  void *push = zmq_socket (context, ZMQ_PUSH);
  zmq_connect (push, "tcp://localhost:5556");

  for(i=0; i<8; ++i) {
     buf=s_recv(pull);
    
//make device driver system calls to get the result
     s_send(push,result);
  }
  
  zmq_close (pull);

  zmq_close (push);

  zmq_term (context);
  return 0;
}
_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev

Reply via email to