resource manager design issue?

Hi, I am trying to build a resource manager which interacts with the clients with following manner.

  1. clients can send commands to resourse manager asking it to read data from ISA device. clients is then blocked
  2. resource manager will then get bunch of data from the ISA device but will not send the data to the client. Instead, it will write to the shared memory and will acknowledge the client with the location of the data in the shared memory.
  3. client will be unblocked and will start reading from the shared memory location that the resource manager has given to the client.

As you can see client doesn’t need to use the normal POSIX method to communicate with the resource manager (ie read(), write(), etc…). Then what is the best communication method to implement this in resource manager?


Why not use read() and write()?

To implement what you suggest you could use ioctl calls. There is no data to send just an offset to get back, ioctl is fine for that.

I am not using read() and write() because resource manager don’t need to pass the data to the clients. There are alot of data and I figured using shared memory between the resource manager and client would be a better design. I will look in to ioctl function, thanks

how can I use ioctl() to send and receive data? can you give me a simple example of server code and client code? For example, if I do open() in client code and get a fd, and use ioctl(fd, …). I don’t know what request to put in. Also in the resource manager side, which io_func do I need to override? like if it was a read() then I would override

Anyways a simple example would be great help… thanks

Usually I try to stay away from share memory. In your case there will be a message for every transaction anyway, so unless you are talking bandwidth over 20Meg per seconds I would use messages (it all depends on the CPU you are using). Share memory are more of a pain to deal with. What if the client goes away, what if the server goes away, what happens to the share memory, what if you have multiple clients, what if your server is multithread etc…

To answer your question:

#include <sys/ioctl.h>

char **buffer;
int request;

request = _IOR( ‘g’, 1, sizeof( buffer ) );
ioctl (fd, request, &buffer )

Each ioctl requestis given a group and command number, here I picked ‘g’ for group and 1 for command number.

As for the resmgr side, there is a nice example in the doc. Look up “handling devctl() messages”.

Have fun.

what is the difference between using ioctl() VS. devctl() ?

Well devctl is simpler to use (no need to encode size), but then it’s not portable. ioctl is most probably built on top of devctl.

From the resmgr point of view their is no difference.