LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-12-2013, 05:25 AM   #1
subashpatel
LQ Newbie
 
Registered: Jul 2013
Posts: 3

Rep: Reputation: Disabled
Select Call in char driver


Hi
I am trying to write my first char driver and i am trying to support a select interface for it as well. But I don't see any select option in fops. I found some links indicating that select() needs to be implemented through poll() and all. Tried some experiments and none seems to be yielding any postive feedback.

Can you guys explain the concept or point me to some sample codes or text that will be helpful.

Thanks in Advance

Subash
 
Old 07-12-2013, 08:49 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,785

Rep: Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159
Quote:
Originally Posted by subashpatel View Post
Hi
I am trying to write my first char driver and i am trying to support a select interface for it as well. But I don't see any select option in fops. I found some links indicating that select() needs to be implemented through poll() and all. Tried some experiments and none seems to be yielding any postive feedback.

Can you guys explain the concept or point me to some sample codes or text that will be helpful.
Google can point you to sample codes, if you tried to look. Putting "linux char driver example code" in pulls up this as the first three hits:
http://www.codeproject.com/Articles/...r-for-Linux-OS
http://linux.die.net/lkmpg/x569.html
http://www.linuxforu.com/2011/02/lin...acter-drivers/

...which have code examples and full explanations.
 
1 members found this post helpful.
Old 07-14-2013, 11:45 PM   #3
subashpatel
LQ Newbie
 
Registered: Jul 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
Talking

Thanks TBOne. I checked the links provided. But none of them describes about implementation of select interface. Is it that char drivers are not supposed to implement select. I am confused.
 
Old 07-15-2013, 08:28 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,785

Rep: Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159
Quote:
Originally Posted by subashpatel View Post
Thanks TBOne. I checked the links provided. But none of them describes about implementation of select interface. Is it that char drivers are not supposed to implement select. I am confused.
If you're confused, then read the second link I posted. It is the Linux Kernel Module programming guide, which explains such things.
 
Old 07-23-2013, 03:35 AM   #5
subashpatel
LQ Newbie
 
Registered: Jul 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
Hi

I have tried the following over the weekend, and I am still not able to understand where I am going wrong. LDD section 6.3 describes about poll and select and I am quoting it here.

=====================================
Support for any of these calls requires support from the device driver. This support (for all three calls) is provided through the driver's poll method. This method has the following prototype:

unsigned int (*poll) (struct file *filp, poll_table *wait);

The driver method is called whenever the user-space program performs a poll, select, or epoll system call involving a file descriptor associated with the driver. Support for any of these calls requires support from the device driver. This support (for all three calls) is provided through the driver's poll method. This method has the following prototype:

unsigned int (*poll) (struct file *filp, poll_table *wait);

The driver method is called whenever the user-space program performs a poll, select, or epoll system call involving a file descriptor associated with the driver.
=====================================


So the next step I did was to write a dummy poll function with just a debug print and add it to the fops.
=====================================
unsigned int dummy_poll( struct file *filp, poll_table *wait )
{
printk("### Inside dummy poll");
return 0;
}


struct file_operations dummy_fops = {
.owner = THIS_MODULE,
.open = dummy_open,
.release = dummy_close,
.poll = dummy_poll,
};

=====================================


From the driver I expose a node /dev/dummynode. From the application, the open call is called and that is successful. I called a write function and that is successful as well.

=====================================
struct timeval time;
time.tv_sec = 2;
time.tv_usec = 0;
fd = open("/dev/dummynode" , O_RDWR );
FD_ZERO( &fdset );
FD_SET( fd , &fdset );
write(fd,"Test", 4);
select( 1, &fdset, NULL, NULL,&time );
=====================================

The select call blocks for 2 seconds and then returns a zero. Has someone gone through the same set of problems.

Thanks
Subash
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] System call select() abhishekgit Linux - Newbie 1 02-06-2012 07:43 PM
[SOLVED] In C, select() call does not wait archieval Programming 3 07-22-2010 05:28 AM
return value of select() call sinu_nayak2001 Programming 9 10-09-2009 05:33 AM
Question about SQL: Can you do this, select records depending on the value of a char? vxc69 Programming 3 12-18-2008 08:11 PM
help passing char* to function call PTBmilo Programming 4 03-16-2003 07:05 PM


All times are GMT -5. The time now is 11:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration