select_attach

a question about select_attach:

so i am using a device driver for a CAN bus, and i want to execute a
callback function everytime a message arrives on the CAN bus.

the CAN driver works by using a file descriptor. to read a message you just
read from the file descriptor using read().

correct me if i’m wrong, but i should be able to use select_attach() on this
file descriptor and it should call a function everytime there is a message
waiting to be read, right? as of the moment, the callback function is never
called.

any ideas on how to solve this? i’d appreciate it more than i can say!!
thanks, sutin

sutin chen <sutinchen@yahoo.com> wrote:

a question about select_attach:

so i am using a device driver for a CAN bus, and i want to execute a
callback function everytime a message arrives on the CAN bus.

the CAN driver works by using a file descriptor. to read a message you just
read from the file descriptor using read().

Ok.

correct me if i’m wrong, but i should be able to use select_attach() on this
file descriptor and it should call a function everytime there is a message
waiting to be read, right? as of the moment, the callback function is never
called.

That depends.

Who wrote the CAN bus resource manager, and did they implement the
underlying support to make select() work?

select(), select_attach(), and io_notify() all use the _IO_NOTIFY
message, and if the resource manager for the CAN bus doesn’t handle
_IO_NOTIFY, then you will never unblock in your select_attach handler.

(You might want to make sure you’re using select_attach() properly
by testing against a resource manager where you know it is
implemented, e.g. a serial port, TCP/IP socket, or pseudo-tty.)

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

so i checked out the driver code, and the default io_notify() function is
being used.

when i run the loop:

while(1){
printf("here\n ");
ctp_ret = dispatch_block(ctp);
if(ctp_ret){
printf(“dispatch handler\n”);
dispatch_handler(ctp);
} else {
fprintf(stderr, “dispatch_block: failure\n”);
return EXIT_FAILURE;
}
}
printf(“closing server\n”);
return EXIT_SUCCESS;

i get the following output:
the line “here” is printed
and then the program terminates, returning the value 0 without printing
anything else.

any ideas?


“David Gibbs” <dagibbs@qnx.com> wrote in message
news:adikqg$80s$2@nntp.qnx.com

sutin chen <> sutinchen@yahoo.com> > wrote:
a question about select_attach:

so i am using a device driver for a CAN bus, and i want to execute a
callback function everytime a message arrives on the CAN bus.

the CAN driver works by using a file descriptor. to read a message you
just
read from the file descriptor using read().

Ok.

correct me if i’m wrong, but i should be able to use select_attach() on
this
file descriptor and it should call a function everytime there is a
message
waiting to be read, right? as of the moment, the callback function is
never
called.

That depends.

Who wrote the CAN bus resource manager, and did they implement the
underlying support to make select() work?

select(), select_attach(), and io_notify() all use the _IO_NOTIFY
message, and if the resource manager for the CAN bus doesn’t handle
_IO_NOTIFY, then you will never unblock in your select_attach handler.

(You might want to make sure you’re using select_attach() properly
by testing against a resource manager where you know it is
implemented, e.g. a serial port, TCP/IP socket, or pseudo-tty.)

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

sutin chen <sutinchen@yahoo.com> wrote:

so i checked out the driver code, and the default io_notify() function is
being used.

And, similar to the default io_read(), and io_write() functions, the
default io_notify() function doesn’t really do anything. If you want
select()/ionotify()/select_attach() to work, you have to implement
this on the driver side.

Take a look at the Programmer’s Guide, Writing a Resource Manager,
Handling ionotify()/select() section.


when i run the loop:

while(1){
printf("here\n ");
ctp_ret = dispatch_block(ctp);
if(ctp_ret){
printf(“dispatch handler\n”);
dispatch_handler(ctp);
} else {
fprintf(stderr, “dispatch_block: failure\n”);
return EXIT_FAILURE;
}
}
printf(“closing server\n”);
return EXIT_SUCCESS;

i get the following output:
the line “here” is printed
and then the program terminates, returning the value 0 without printing
anything else.

any ideas?

I’m not sure which program this is – the one calling select_attach()
or the one that you’re trying to select_attach() to. But, that
dispatch_block() is returning 0 should be unrelated on the implementing
side as to whether or not you’ve implemented ionotify() handling.

If this is the side calling select_attach(), did you check the return
on select_attach()? Is it failing? If it is failing, have you done
any other xxx_attach() function that succeeded? If there has been
no successful xxx_attach() function, then I expect that your
dispatch_block() has nothing to block on. In any case, it is probably
worth checking errno after the dispatch_block() fails to see why it
failed.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

Did this question ever get resolved? The way I read the question,
dispatch_block never returned at all, but rather exited the program. I find
this interesting because we’re having a similar problem with select_attach and
the thread_pool functions.

Murf

David Gibbs wrote:

sutin chen <> sutinchen@yahoo.com> > wrote:
so i checked out the driver code, and the default io_notify() function is
being used.

And, similar to the default io_read(), and io_write() functions, the
default io_notify() function doesn’t really do anything. If you want
select()/ionotify()/select_attach() to work, you have to implement
this on the driver side.

Take a look at the Programmer’s Guide, Writing a Resource Manager,
Handling ionotify()/select() section.

when i run the loop:

while(1){
printf("here\n ");
ctp_ret = dispatch_block(ctp);
if(ctp_ret){
printf(“dispatch handler\n”);
dispatch_handler(ctp);
} else {
fprintf(stderr, “dispatch_block: failure\n”);
return EXIT_FAILURE;
}
}
printf(“closing server\n”);
return EXIT_SUCCESS;

i get the following output:
the line “here” is printed
and then the program terminates, returning the value 0 without printing
anything else.

any ideas?

I’m not sure which program this is – the one calling select_attach()
or the one that you’re trying to select_attach() to. But, that
dispatch_block() is returning 0 should be unrelated on the implementing
side as to whether or not you’ve implemented ionotify() handling.

If this is the side calling select_attach(), did you check the return
on select_attach()? Is it failing? If it is failing, have you done
any other xxx_attach() function that succeeded? If there has been
no successful xxx_attach() function, then I expect that your
dispatch_block() has nothing to block on. In any case, it is probably
worth checking errno after the dispatch_block() fails to see why it
failed.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.