Help on select( )

Hi

If I want a programmer to be able to do a select() on the file
descriptor of my device, then what is the
MajorFunction (IRP_MJ_???) I should have in my driver code ?

I currenlty have IRP_MJ_CREATE, …CLOSE, …READ and …WRITE only

Thanx
Kiran

On Windows select() only works with socket handles, it does NOT work with
any other form of descriptor.

If you want read/write notifications, think events, or overlapped I/O to
completion ports or completion functions.

Mark.

At 08:01 AM 10/17/2003, Kiran Bacche wrote:

Hi

If I want a programmer to be able to do a select() on the file
descriptor of my device, then what is the
MajorFunction (IRP_MJ_???) I should have in my driver code ?

I currenlty have IRP_MJ_CREATE, …CLOSE, …READ and …WRITE only

Thanx
Kiran

I tried to use select on STDIN and it worked. The sample code is…

Int fd;
fd_set readfs;
struct timeval timeout;

Fd = 0;
FD_ZERO(&readfs);
FD_SET(fd, &readfs);
timeout.tv_sec = 3;
timeout.tv_usec = 0;
select(fd + 1, &readfs, NULL, NULL, &timeout);

Now this code waits for 3 secs for a keystroke.
If I press a key within 3 secs, it comes out as expected.
And if I do not press a key, it timesout after 3 secs and comes out
again as expected.

So now if I want the same thing to work with my device descriptor, i.e.
fd = open(“\\.\kiran”, O_RDONLY);

Then what extra should I do in my device driver ?

As an anology, in Linux there is something like poll_wait that needs to
be written in the linux device driver along with dispatch_read,
dispatch_write, etc.

Does something like that hold good in windows also ?
Or is there any other mechanism ?

Thanx
Kiran

-----Original Message-----
From: Mark S. Edwards [mailto:xxxxx@muttsnuts.com]
Sent: Friday, October 17, 2003 2:58 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Re: Help on select( )

On Windows select() only works with socket handles, it does NOT work
with
any other form of descriptor.

If you want read/write notifications, think events, or overlapped I/O to

completion ports or completion functions.

Mark.

At 08:01 AM 10/17/2003, Kiran Bacche wrote:

Hi

If I want a programmer to be able to do a select() on the file
descriptor of my device, then what is the
MajorFunction (IRP_MJ_???) I should have in my driver code ?

I currenlty have IRP_MJ_CREATE, …CLOSE, …READ and …WRITE only

Thanx
Kiran


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@wipro.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Here’s a reply I posted on the Winsock2 list earlier this year to someone
who asked exactly the same problem.

As someone who was intimately involved in the creation of Winsock and
Winsock-2 I can guarantee that Windows select() ONLY operates on socket
handles.

I can’t speak for what any mapping libraries such as Cygwin might do, but
for native Win32/64 programmes, file handles are ignored by select.

Mark

At 02:12 AM 1/31/2003, Mark S. Edwards wrote:
>John,
>
>It’s quite simple. Windows is not UNIX. Windows select() is only valid
for socket handles created with socket() or WSASocket().
>
>You can not use select on file handles in Windows.
>
>If you want a history lesson, the reason is because the original Windows
ran on top of DOS and used DOS file handles for file I/O. WinSock was a
later bolt on addition to Windows to provide a common API to the plethora
of TSR TCP/IP stacks in the days before Microsoft had heard of TCP/IP. The
socket handle could only ever be a logical entity and not tied into the
file system. For compatibility and other reasons this remained the same
for WinSock 2.0 and thereafter. Also, because select() was potentially CPU
intensive Microsoft never wished to tie the file system into it, especially
when they already had their own efficient mechanisms such as Overlapped I/O.
>
>Mark.
>
>
>At 04:27 AM 1/31/2003, xxxxx@agilent.com wrote:
>>Hi,
>>
>>I am new to the Winsock API and I am trying to run this code:
>>
>>#include
>>#include <assert.h>
>>#include <winsock2.h>
>>
>>#define STDIN 0 // file descriptor for standard input
>>
>>int main(void)
>>{
>>#ifdef WIN32
>> WSADATA wsaData; // if this doesn’t work
>> if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
>> {
>> cerr << “WSAStartup failed.\n”;
>> exit(1);
>> }
>>#endif
>>
>> struct timeval tv;
>> fd_set readfds;
>>
>> tv.tv_sec = 5;
>> tv.tv_usec = 0;
>>
>> FD_ZERO(&readfds);
>> FD_SET(STDIN, &readfds);
>>
>> // don’t care about writefds and exceptfds:
>> select(STDIN + 1, &readfds, NULL, NULL, &tv);
>>
>> cout << “what error: " << WSAGetLastError() << endl;
>>
>> if (FD_ISSET(STDIN, &readfds))
>> printf(“A key was pressed!\n”);
>> else
>> printf(“Timed out.\n”);
>>#ifdef WIN32
>> WSACleanup();
>>#endif
>> return 0;
>>}
>>
>>“A key was pressed” is always printed to the screen, though I expected a
time-out when I didn’t press anything.
>>
>>WSAGetLastError() always reports 10038, which I’ve looked up to mean
operating on a non-socket.
>>I’m guessing this is because 0 is not the correct file descriptor for STDIN?
>>If so, what is the correct number?
>>
>>Thanks,

At 10:52 AM 10/17/2003, Kiran Bacche wrote:
>I tried to use select on STDIN and it worked. The sample code is…
>
>Int fd;
>fd_set readfs;
>struct timeval timeout;
>
>Fd = 0;
>FD_ZERO(&readfs);
>FD_SET(fd, &readfs);
>timeout.tv_sec = 3;
>timeout.tv_usec = 0;
>select(fd + 1, &readfs, NULL, NULL, &timeout);
>
>Now this code waits for 3 secs for a keystroke.
>If I press a key within 3 secs, it comes out as expected.
>And if I do not press a key, it timesout after 3 secs and comes out
>again as expected.
>
>So now if I want the same thing to work with my device descriptor, i.e.
>fd = open(”\\.\kiran", O_RDONLY);
>
>Then what extra should I do in my device driver ?
>
>As an anology, in Linux there is something like poll_wait that needs to
>be written in the linux device driver along with dispatch_read,
>dispatch_write, etc.
>
>Does something like that hold good in windows also ?
>Or is there any other mechanism ?
>
>Thanx
> Kiran
>
>
>
>-----Original Message-----
>From: Mark S. Edwards [mailto:xxxxx@muttsnuts.com]
>Sent: Friday, October 17, 2003 2:58 PM
>To: Windows System Software Devs Interest List
>Subject: [ntdev] Re: Help on select( )
>
>
>On Windows select() only works with socket handles, it does NOT work
>with
>any other form of descriptor.
>
>If you want read/write notifications, think events, or overlapped I/O to
>
>completion ports or completion functions.
>
>Mark.
>
>
>At 08:01 AM 10/17/2003, Kiran Bacche wrote:
> >Hi
> >
> > If I want a programmer to be able to do a select() on the file
> >descriptor of my device, then what is the
> >MajorFunction (IRP_MJ_???) I should have in my driver code ?
> >
> >I currenlty have IRP_MJ_CREATE, …CLOSE, …READ and …WRITE only
> >
> >Thanx
> > Kiran
>
>
>—
>Questions? First check the Kernel Driver FAQ at
>http://www.osronline.com/article.cfm?id=256
>
>You are currently subscribed to ntdev as: xxxxx@wipro.com
>To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>—
>Questions? First check the Kernel Driver FAQ at
>http://www.osronline.com/article.cfm?id=256
>
>You are currently subscribed to ntdev as: xxxxx@muttsnuts.com
>To unsubscribe send a blank email to xxxxx@lists.osr.com</winsock2.h></assert.h>

So does it mean that there is no mechanism to achieve the required
functionality in WINDOWS?

Thanx
Kiran

-----Original Message-----
From: Mark S. Edwards [mailto:xxxxx@muttsnuts.com]
Sent: Friday, October 17, 2003 4:10 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Re: Help on select( )

Here’s a reply I posted on the Winsock2 list earlier this year to
someone
who asked exactly the same problem.

As someone who was intimately involved in the creation of Winsock and
Winsock-2 I can guarantee that Windows select() ONLY operates on socket
handles.

I can’t speak for what any mapping libraries such as Cygwin might do,
but
for native Win32/64 programmes, file handles are ignored by select.

Mark

At 02:12 AM 1/31/2003, Mark S. Edwards wrote:
>John,
>
>It’s quite simple. Windows is not UNIX. Windows select() is only
valid
for socket handles created with socket() or WSASocket().
>
>You can not use select on file handles in Windows.
>
>If you want a history lesson, the reason is because the original
Windows
ran on top of DOS and used DOS file handles for file I/O. WinSock was a

later bolt on addition to Windows to provide a common API to the
plethora
of TSR TCP/IP stacks in the days before Microsoft had heard of TCP/IP.
The
socket handle could only ever be a logical entity and not tied into the
file system. For compatibility and other reasons this remained the same

for WinSock 2.0 and thereafter. Also, because select() was potentially
CPU
intensive Microsoft never wished to tie the file system into it,
especially
when they already had their own efficient mechanisms such as Overlapped
I/O.
>
>Mark.
>
>
>At 04:27 AM 1/31/2003, xxxxx@agilent.com wrote:
>>Hi,
>>
>>I am new to the Winsock API and I am trying to run this code:
>>
>>#include
>>#include <assert.h>
>>#include <winsock2.h>
>>
>>#define STDIN 0 // file descriptor for standard input
>>
>>int main(void)
>>{
>>#ifdef WIN32
>> WSADATA wsaData; // if this doesn’t work
>> if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
>> {
>> cerr << “WSAStartup failed.\n”;
>> exit(1);
>> }
>>#endif
>>
>> struct timeval tv;
>> fd_set readfds;
>>
>> tv.tv_sec = 5;
>> tv.tv_usec = 0;
>>
>> FD_ZERO(&readfds);
>> FD_SET(STDIN, &readfds);
>>
>> // don’t care about writefds and exceptfds:
>> select(STDIN + 1, &readfds, NULL, NULL, &tv);
>>
>> cout << “what error: " << WSAGetLastError() << endl;
>>
>> if (FD_ISSET(STDIN, &readfds))
>> printf(“A key was pressed!\n”);
>> else
>> printf(“Timed out.\n”);
>>#ifdef WIN32
>> WSACleanup();
>>#endif
>> return 0;
>>}
>>
>>“A key was pressed” is always printed to the screen, though I
expected a
time-out when I didn’t press anything.
>>
>>WSAGetLastError() always reports 10038, which I’ve looked up to mean
operating on a non-socket.
>>I’m guessing this is because 0 is not the correct file descriptor for
STDIN?
>>If so, what is the correct number?
>>
>>Thanks,

At 10:52 AM 10/17/2003, Kiran Bacche wrote:
>I tried to use select on STDIN and it worked. The sample code is…
>
>Int fd;
>fd_set readfs;
>struct timeval timeout;
>
>Fd = 0;
>FD_ZERO(&readfs);
>FD_SET(fd, &readfs);
>timeout.tv_sec = 3;
>timeout.tv_usec = 0;
>select(fd + 1, &readfs, NULL, NULL, &timeout);
>
>Now this code waits for 3 secs for a keystroke.
>If I press a key within 3 secs, it comes out as expected.
>And if I do not press a key, it timesout after 3 secs and comes out
>again as expected.
>
>So now if I want the same thing to work with my device descriptor, i.e.
>fd = open(”\\.\kiran", O_RDONLY);
>
>Then what extra should I do in my device driver ?
>
>As an anology, in Linux there is something like poll_wait that needs to
>be written in the linux device driver along with dispatch_read,
>dispatch_write, etc.
>
>Does something like that hold good in windows also ?
>Or is there any other mechanism ?
>
>Thanx
> Kiran
>
>
>
>-----Original Message-----
>From: Mark S. Edwards [mailto:xxxxx@muttsnuts.com]
>Sent: Friday, October 17, 2003 2:58 PM
>To: Windows System Software Devs Interest List
>Subject: [ntdev] Re: Help on select( )
>
>
>On Windows select() only works with socket handles, it does NOT work
>with
>any other form of descriptor.
>
>If you want read/write notifications, think events, or overlapped I/O
to
>
>completion ports or completion functions.
>
>Mark.
>
>
>At 08:01 AM 10/17/2003, Kiran Bacche wrote:
> >Hi
> >
> > If I want a programmer to be able to do a select() on the file
> >descriptor of my device, then what is the
> >MajorFunction (IRP_MJ_???) I should have in my driver code ?
> >
> >I currenlty have IRP_MJ_CREATE, …CLOSE, …READ and …WRITE only
> >
> >Thanx
> > Kiran
>
>
>—
>Questions? First check the Kernel Driver FAQ at
>http://www.osronline.com/article.cfm?id=256
>
>You are currently subscribed to ntdev as: xxxxx@wipro.com
>To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>—
>Questions? First check the Kernel Driver FAQ at
>http://www.osronline.com/article.cfm?id=256
>
>You are currently subscribed to ntdev as: xxxxx@muttsnuts.com
>To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@wipro.com
To unsubscribe send a blank email to xxxxx@lists.osr.com</winsock2.h></assert.h>

Of course there is. WaitForMultipleObjects, plus a cast of dozens of other
alternatives.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Kiran Bacche
Sent: Friday, October 17, 2003 7:08 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Re: Help on select( )

So does it mean that there is no mechanism to achieve the required
functionality in WINDOWS?

Thanx
Kiran

-----Original Message-----
From: Mark S. Edwards [mailto:xxxxx@muttsnuts.com]
Sent: Friday, October 17, 2003 4:10 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Re: Help on select( )

Here’s a reply I posted on the Winsock2 list earlier this year to someone
who asked exactly the same problem.

As someone who was intimately involved in the creation of Winsock and
Winsock-2 I can guarantee that Windows select() ONLY operates on socket
handles.

I can’t speak for what any mapping libraries such as Cygwin might do, but
for native Win32/64 programmes, file handles are ignored by select.

Mark

At 02:12 AM 1/31/2003, Mark S. Edwards wrote:
>John,
>
>It’s quite simple. Windows is not UNIX. Windows select() is only valid
for socket handles created with socket() or WSASocket().
>
>You can not use select on file handles in Windows.
>
>If you want a history lesson, the reason is because the original Windows
ran on top of DOS and used DOS file handles for file I/O. WinSock was a

later bolt on addition to Windows to provide a common API to the plethora
of TSR TCP/IP stacks in the days before Microsoft had heard of TCP/IP. The
socket handle could only ever be a logical entity and not tied into the
file system. For compatibility and other reasons this remained the same

for WinSock 2.0 and thereafter. Also, because select() was potentially CPU
intensive Microsoft never wished to tie the file system into it, especially
when they already had their own efficient mechanisms such as Overlapped I/O.

>Mark. > > >At 04:27 AM 1/31/2003, xxxxx@agilent.com wrote:
>Hi, >> >>I am new to the Winsock API and I am trying to run this code:
> >>#include >>#include <assert.h> >>#include <winsock2.h>
>> >>#define STDIN 0 // file descriptor for standard input >> >>int
main(void) >>{ >>#ifdef WIN32
>> WSADATA wsaData; // if this doesn’t work
>> if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
>> {
>> cerr << “WSAStartup failed.\n”;
>> exit(1);
>> }
>>#endif
>>
>> struct timeval tv;
>> fd_set readfds;
>>
>> tv.tv_sec = 5;
>> tv.tv_usec = 0;
>>
>> FD_ZERO(&readfds);
>> FD_SET(STDIN, &readfds);
>>
>> // don’t care about writefds and exceptfds:
>> select(STDIN + 1, &readfds, NULL, NULL, &tv);
>>
>> cout << “what error: " << WSAGetLastError() << endl;
>>
>> if (FD_ISSET(STDIN, &readfds))
>> printf(“A key was pressed!\n”);
>> else
>> printf(“Timed out.\n”);
>>#ifdef WIN32
>> WSACleanup();
>>#endif
>> return 0;
>>}
>>
>>“A key was pressed” is always printed to the screen, though I expected a
time-out when I didn’t press anything.
>>
>>WSAGetLastError() always reports 10038, which I’ve looked up to mean
operating on a non-socket.
>>I’m guessing this is because 0 is not the correct file descriptor for
STDIN? >>If so, what is the correct number? >> >>Thanks,

At 10:52 AM 10/17/2003, Kiran Bacche wrote:
>I tried to use select on STDIN and it worked. The sample code is…
>
>Int fd;
>fd_set readfs;
>struct timeval timeout;
>
>Fd = 0;
>FD_ZERO(&readfs);
>FD_SET(fd, &readfs);
>timeout.tv_sec = 3;
>timeout.tv_usec = 0;
>select(fd + 1, &readfs, NULL, NULL, &timeout);
>
>Now this code waits for 3 secs for a keystroke.
>If I press a key within 3 secs, it comes out as expected.
>And if I do not press a key, it timesout after 3 secs and comes out
>again as expected.
>
>So now if I want the same thing to work with my device descriptor, i.e.
>fd = open(”\\.\kiran", O_RDONLY);
>
>Then what extra should I do in my device driver ?
>
>As an anology, in Linux there is something like poll_wait that needs to
>be written in the linux device driver along with dispatch_read,
>dispatch_write, etc.
>
>Does something like that hold good in windows also ?
>Or is there any other mechanism ?
>
>Thanx
> Kiran
>
>
>
>-----Original Message-----
>From: Mark S. Edwards [mailto:xxxxx@muttsnuts.com]
>Sent: Friday, October 17, 2003 2:58 PM
>To: Windows System Software Devs Interest List
>Subject: [ntdev] Re: Help on select( )
>
>
>On Windows select() only works with socket handles, it does NOT work
>with any other form of descriptor.
>
>If you want read/write notifications, think events, or overlapped I/O
to
>
>completion ports or completion functions.
>
>Mark.
>
>
>At 08:01 AM 10/17/2003, Kiran Bacche wrote:
> >Hi
> >
> > If I want a programmer to be able to do a select() on the file
> >descriptor of my device, then what is the MajorFunction (IRP_MJ_???)
> >I should have in my driver code ?
> >
> >I currenlty have IRP_MJ_CREATE, …CLOSE, …READ and …WRITE only
> >
> >Thanx
> > Kiran
>
>
>—
>Questions? First check the Kernel Driver FAQ at
>http://www.osronline.com/article.cfm?id=256
>
>You are currently subscribed to ntdev as: xxxxx@wipro.com To
>unsubscribe send a blank email to xxxxx@lists.osr.com
>
>—
>Questions? First check the Kernel Driver FAQ at
>http://www.osronline.com/article.cfm?id=256
>
>You are currently subscribed to ntdev as: xxxxx@muttsnuts.com To
>unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@wipro.com To
unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@dchbk.us
To unsubscribe send a blank email to xxxxx@lists.osr.com</winsock2.h></assert.h>

Does it mean I use WaitForXXX API on the file handle returned by
CreateFile ???
Can you please give a saple pseudo-code ??

Main() {

myfilehandle = CrateFile(“\\.\kiran”, …);

Now if I want to wait for 3 secs for any input to come from “kiran”
device whhat code I should use here ???
Also what extra support/function I should have in my device driver
file?

}

Thanx
Kiran

-----Original Message-----
From: benson [mailto:xxxxx@dchbk.us]
Sent: Friday, October 17, 2003 4:53 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Re: Help on select( )

Of course there is. WaitForMultipleObjects, plus a cast of dozens of
other
alternatives.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Kiran Bacche
Sent: Friday, October 17, 2003 7:08 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Re: Help on select( )

So does it mean that there is no mechanism to achieve the required
functionality in WINDOWS?

Thanx
Kiran

-----Original Message-----
From: Mark S. Edwards [mailto:xxxxx@muttsnuts.com]
Sent: Friday, October 17, 2003 4:10 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Re: Help on select( )

Here’s a reply I posted on the Winsock2 list earlier this year to
someone
who asked exactly the same problem.

As someone who was intimately involved in the creation of Winsock and
Winsock-2 I can guarantee that Windows select() ONLY operates on socket
handles.

I can’t speak for what any mapping libraries such as Cygwin might do,
but
for native Win32/64 programmes, file handles are ignored by select.

Mark

At 02:12 AM 1/31/2003, Mark S. Edwards wrote:
>John,
>
>It’s quite simple. Windows is not UNIX. Windows select() is only
valid
for socket handles created with socket() or WSASocket().
>
>You can not use select on file handles in Windows.
>
>If you want a history lesson, the reason is because the original
Windows
ran on top of DOS and used DOS file handles for file I/O. WinSock was a

later bolt on addition to Windows to provide a common API to the
plethora
of TSR TCP/IP stacks in the days before Microsoft had heard of TCP/IP.
The
socket handle could only ever be a logical entity and not tied into the
file system. For compatibility and other reasons this remained the same

for WinSock 2.0 and thereafter. Also, because select() was potentially
CPU
intensive Microsoft never wished to tie the file system into it,
especially
when they already had their own efficient mechanisms such as Overlapped
I/O.

>Mark. > > >At 04:27 AM 1/31/2003, xxxxx@agilent.com wrote:
>Hi, >> >>I am new to the Winsock API and I am trying to run this
code:
> >>#include >>#include <assert.h> >>#include
<winsock2.h>
>> >>#define STDIN 0 // file descriptor for standard input >> >>int
main(void) >>{ >>#ifdef WIN32
>> WSADATA wsaData; // if this doesn’t work
>> if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
>> {
>> cerr << “WSAStartup failed.\n”;
>> exit(1);
>> }
>>#endif
>>
>> struct timeval tv;
>> fd_set readfds;
>>
>> tv.tv_sec = 5;
>> tv.tv_usec = 0;
>>
>> FD_ZERO(&readfds);
>> FD_SET(STDIN, &readfds);
>>
>> // don’t care about writefds and exceptfds:
>> select(STDIN + 1, &readfds, NULL, NULL, &tv);
>>
>> cout << “what error: " << WSAGetLastError() << endl;
>>
>> if (FD_ISSET(STDIN, &readfds))
>> printf(“A key was pressed!\n”);
>> else
>> printf(“Timed out.\n”);
>>#ifdef WIN32
>> WSACleanup();
>>#endif
>> return 0;
>>}
>>
>>“A key was pressed” is always printed to the screen, though I
expected a
time-out when I didn’t press anything.
>>
>>WSAGetLastError() always reports 10038, which I’ve looked up to mean
operating on a non-socket.
>>I’m guessing this is because 0 is not the correct file descriptor for
STDIN? >>If so, what is the correct number? >> >>Thanks,

At 10:52 AM 10/17/2003, Kiran Bacche wrote:
>I tried to use select on STDIN and it worked. The sample code is…
>
>Int fd;
>fd_set readfs;
>struct timeval timeout;
>
>Fd = 0;
>FD_ZERO(&readfs);
>FD_SET(fd, &readfs);
>timeout.tv_sec = 3;
>timeout.tv_usec = 0;
>select(fd + 1, &readfs, NULL, NULL, &timeout);
>
>Now this code waits for 3 secs for a keystroke.
>If I press a key within 3 secs, it comes out as expected.
>And if I do not press a key, it timesout after 3 secs and comes out
>again as expected.
>
>So now if I want the same thing to work with my device descriptor, i.e.

>fd = open(”\\.\kiran", O_RDONLY);
>
>Then what extra should I do in my device driver ?
>
>As an anology, in Linux there is something like poll_wait that needs to

>be written in the linux device driver along with dispatch_read,
>dispatch_write, etc.
>
>Does something like that hold good in windows also ?
>Or is there any other mechanism ?
>
>Thanx
> Kiran
>
>
>
>-----Original Message-----
>From: Mark S. Edwards [mailto:xxxxx@muttsnuts.com]
>Sent: Friday, October 17, 2003 2:58 PM
>To: Windows System Software Devs Interest List
>Subject: [ntdev] Re: Help on select( )
>
>
>On Windows select() only works with socket handles, it does NOT work
>with any other form of descriptor.
>
>If you want read/write notifications, think events, or overlapped I/O
to
>
>completion ports or completion functions.
>
>Mark.
>
>
>At 08:01 AM 10/17/2003, Kiran Bacche wrote:
> >Hi
> >
> > If I want a programmer to be able to do a select() on the file
> >descriptor of my device, then what is the MajorFunction (IRP_MJ_???)
> >I should have in my driver code ?
> >
> >I currenlty have IRP_MJ_CREATE, …CLOSE, …READ and …WRITE only
> >
> >Thanx
> > Kiran
>
>
>—
>Questions? First check the Kernel Driver FAQ at
>http://www.osronline.com/article.cfm?id=256
>
>You are currently subscribed to ntdev as: xxxxx@wipro.com To
>unsubscribe send a blank email to xxxxx@lists.osr.com
>
>—
>Questions? First check the Kernel Driver FAQ at
>http://www.osronline.com/article.cfm?id=256
>
>You are currently subscribed to ntdev as: xxxxx@muttsnuts.com To
>unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@wipro.com To
unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@dchbk.us
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@wipro.com
To unsubscribe send a blank email to xxxxx@lists.osr.com</winsock2.h></assert.h>

Windows supports select() on sockets only.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “Kiran Bacche”
To: “Windows System Software Devs Interest List”
Sent: Friday, October 17, 2003 11:01 AM
Subject: [ntdev] Help on select( )

> Hi
>
> If I want a programmer to be able to do a select() on the file
> descriptor of my device, then what is the
> MajorFunction (IRP_MJ_???) I should have in my driver code ?
>
> I currenlty have IRP_MJ_CREATE, …CLOSE, …READ and …WRITE only
>
> Thanx
> Kiran
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

> As an anology, in Linux there is something like poll_wait that needs to

be written in the linux device driver along with dispatch_read,
dispatch_write, etc.

Does something like that hold good in windows also ?

No, Windows has no architecture for doing this. Use overlapped IO and
completion ports instead.

stdin is not a kernel file in Windows - it is a hook to the LPC port which
sends messages to CSRSS.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

Async IO will provide the nearly same functionality, but only nearly.
select() allows you to poll without reading any data. In Windows, you will need
to read at least 1 byte of data to do the same, using overlapped IO and
completion ports.

So, your code must be properly designed and compartmentalized to be
portable across UNIX/Windows in this respect. Define a routine of
PollHandlesAndRead() and implement it using select()/read() on UNIX, and using
overlapped ReadFile and a completion port on Windows.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “Kiran Bacche”
To: “Windows System Software Devs Interest List”
Sent: Friday, October 17, 2003 3:07 PM
Subject: [ntdev] Re: Help on select( )

> So does it mean that there is no mechanism to achieve the required
> functionality in WINDOWS?
>
>
> Thanx
> Kiran
>
>
>
>
>
>
>
>
>
> -----Original Message-----
> From: Mark S. Edwards [mailto:xxxxx@muttsnuts.com]
> Sent: Friday, October 17, 2003 4:10 PM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] Re: Help on select( )
>
>
> Here’s a reply I posted on the Winsock2 list earlier this year to
> someone
> who asked exactly the same problem.
>
> As someone who was intimately involved in the creation of Winsock and
> Winsock-2 I can guarantee that Windows select() ONLY operates on socket
> handles.
>
> I can’t speak for what any mapping libraries such as Cygwin might do,
> but
> for native Win32/64 programmes, file handles are ignored by select.
>
> Mark
>
>
> At 02:12 AM 1/31/2003, Mark S. Edwards wrote:
> >John,
> >
> >It’s quite simple. Windows is not UNIX. Windows select() is only
> valid
> for socket handles created with socket() or WSASocket().
> >
> >You can not use select on file handles in Windows.
> >
> >If you want a history lesson, the reason is because the original
> Windows
> ran on top of DOS and used DOS file handles for file I/O. WinSock was a
>
> later bolt on addition to Windows to provide a common API to the
> plethora
> of TSR TCP/IP stacks in the days before Microsoft had heard of TCP/IP.
> The
> socket handle could only ever be a logical entity and not tied into the
> file system. For compatibility and other reasons this remained the same
>
> for WinSock 2.0 and thereafter. Also, because select() was potentially
> CPU
> intensive Microsoft never wished to tie the file system into it,
> especially
> when they already had their own efficient mechanisms such as Overlapped
> I/O.
> >
> >Mark.
> >
> >
> >At 04:27 AM 1/31/2003, xxxxx@agilent.com wrote:
> >>Hi,
> >>
> >>I am new to the Winsock API and I am trying to run this code:
> >>
> >>#include
> >>#include <assert.h>
> >>#include <winsock2.h>
> >>
> >>#define STDIN 0 // file descriptor for standard input
> >>
> >>int main(void)
> >>{
> >>#ifdef WIN32
> >> WSADATA wsaData; // if this doesn’t work
> >> if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
> >> {
> >> cerr << “WSAStartup failed.\n”;
> >> exit(1);
> >> }
> >>#endif
> >>
> >> struct timeval tv;
> >> fd_set readfds;
> >>
> >> tv.tv_sec = 5;
> >> tv.tv_usec = 0;
> >>
> >> FD_ZERO(&readfds);
> >> FD_SET(STDIN, &readfds);
> >>
> >> // don’t care about writefds and exceptfds:
> >> select(STDIN + 1, &readfds, NULL, NULL, &tv);
> >>
> >> cout << “what error: " << WSAGetLastError() << endl;
> >>
> >> if (FD_ISSET(STDIN, &readfds))
> >> printf(“A key was pressed!\n”);
> >> else
> >> printf(“Timed out.\n”);
> >>#ifdef WIN32
> >> WSACleanup();
> >>#endif
> >> return 0;
> >>}
> >>
> >>“A key was pressed” is always printed to the screen, though I
> expected a
> time-out when I didn’t press anything.
> >>
> >>WSAGetLastError() always reports 10038, which I’ve looked up to mean
> operating on a non-socket.
> >>I’m guessing this is because 0 is not the correct file descriptor for
> STDIN?
> >>If so, what is the correct number?
> >>
> >>Thanks,
>
>
>
> At 10:52 AM 10/17/2003, Kiran Bacche wrote:
> >I tried to use select on STDIN and it worked. The sample code is…
> >
> >Int fd;
> >fd_set readfs;
> >struct timeval timeout;
> >
> >Fd = 0;
> >FD_ZERO(&readfs);
> >FD_SET(fd, &readfs);
> >timeout.tv_sec = 3;
> >timeout.tv_usec = 0;
> >select(fd + 1, &readfs, NULL, NULL, &timeout);
> >
> >Now this code waits for 3 secs for a keystroke.
> >If I press a key within 3 secs, it comes out as expected.
> >And if I do not press a key, it timesout after 3 secs and comes out
> >again as expected.
> >
> >So now if I want the same thing to work with my device descriptor, i.e.
> >fd = open(”\\.\kiran", O_RDONLY);
> >
> >Then what extra should I do in my device driver ?
> >
> >As an anology, in Linux there is something like poll_wait that needs to
> >be written in the linux device driver along with dispatch_read,
> >dispatch_write, etc.
> >
> >Does something like that hold good in windows also ?
> >Or is there any other mechanism ?
> >
> >Thanx
> > Kiran
> >
> >
> >
> >-----Original Message-----
> >From: Mark S. Edwards [mailto:xxxxx@muttsnuts.com]
> >Sent: Friday, October 17, 2003 2:58 PM
> >To: Windows System Software Devs Interest List
> >Subject: [ntdev] Re: Help on select( )
> >
> >
> >On Windows select() only works with socket handles, it does NOT work
> >with
> >any other form of descriptor.
> >
> >If you want read/write notifications, think events, or overlapped I/O
> to
> >
> >completion ports or completion functions.
> >
> >Mark.
> >
> >
> >At 08:01 AM 10/17/2003, Kiran Bacche wrote:
> > >Hi
> > >
> > > If I want a programmer to be able to do a select() on the file
> > >descriptor of my device, then what is the
> > >MajorFunction (IRP_MJ_???) I should have in my driver code ?
> > >
> > >I currenlty have IRP_MJ_CREATE, …CLOSE, …READ and …WRITE only
> > >
> > >Thanx
> > > Kiran
> >
> >
> >—
> >Questions? First check the Kernel Driver FAQ at
> >http://www.osronline.com/article.cfm?id=256
> >
> >You are currently subscribed to ntdev as: xxxxx@wipro.com
> >To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
> >—
> >Questions? First check the Kernel Driver FAQ at
> >http://www.osronline.com/article.cfm?id=256
> >
> >You are currently subscribed to ntdev as: xxxxx@muttsnuts.com
> >To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@wipro.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
></winsock2.h></assert.h>

Thanx very much for this vital information.

  • Kiran

-----Original Message-----
From: Maxim S. Shatskih [mailto:xxxxx@storagecraft.com]
Sent: Friday, October 17, 2003 6:15 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Re: Help on select( )

Async IO will provide the nearly same functionality, but only
nearly.
select() allows you to poll without reading any data. In Windows, you
will need
to read at least 1 byte of data to do the same, using overlapped IO and
completion ports.

So, your code must be properly designed and compartmentalized to be
portable across UNIX/Windows in this respect. Define a routine of
PollHandlesAndRead() and implement it using select()/read() on UNIX, and
using
overlapped ReadFile and a completion port on Windows.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “Kiran Bacche”
To: “Windows System Software Devs Interest List”
Sent: Friday, October 17, 2003 3:07 PM
Subject: [ntdev] Re: Help on select( )

> So does it mean that there is no mechanism to achieve the required
> functionality in WINDOWS?
>
>
> Thanx
> Kiran
>
>
>
>
>
>
>
>
>
> -----Original Message-----
> From: Mark S. Edwards [mailto:xxxxx@muttsnuts.com]
> Sent: Friday, October 17, 2003 4:10 PM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] Re: Help on select( )
>
>
> Here’s a reply I posted on the Winsock2 list earlier this year to
> someone
> who asked exactly the same problem.
>
> As someone who was intimately involved in the creation of Winsock and
> Winsock-2 I can guarantee that Windows select() ONLY operates on
socket
> handles.
>
> I can’t speak for what any mapping libraries such as Cygwin might do,
> but
> for native Win32/64 programmes, file handles are ignored by select.
>
> Mark
>
>
> At 02:12 AM 1/31/2003, Mark S. Edwards wrote:
> >John,
> >
> >It’s quite simple. Windows is not UNIX. Windows select() is only
> valid
> for socket handles created with socket() or WSASocket().
> >
> >You can not use select on file handles in Windows.
> >
> >If you want a history lesson, the reason is because the original
> Windows
> ran on top of DOS and used DOS file handles for file I/O. WinSock was
a
>
> later bolt on addition to Windows to provide a common API to the
> plethora
> of TSR TCP/IP stacks in the days before Microsoft had heard of TCP/IP.
> The
> socket handle could only ever be a logical entity and not tied into
the
> file system. For compatibility and other reasons this remained the
same
>
> for WinSock 2.0 and thereafter. Also, because select() was
potentially
> CPU
> intensive Microsoft never wished to tie the file system into it,
> especially
> when they already had their own efficient mechanisms such as
Overlapped
> I/O.
> >
> >Mark.
> >
> >
> >At 04:27 AM 1/31/2003, xxxxx@agilent.com wrote:
> >>Hi,
> >>
> >>I am new to the Winsock API and I am trying to run this code:
> >>
> >>#include
> >>#include <assert.h>
> >>#include <winsock2.h>
> >>
> >>#define STDIN 0 // file descriptor for standard input
> >>
> >>int main(void)
> >>{
> >>#ifdef WIN32
> >> WSADATA wsaData; // if this doesn’t work
> >> if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
> >> {
> >> cerr << “WSAStartup failed.\n”;
> >> exit(1);
> >> }
> >>#endif
> >>
> >> struct timeval tv;
> >> fd_set readfds;
> >>
> >> tv.tv_sec = 5;
> >> tv.tv_usec = 0;
> >>
> >> FD_ZERO(&readfds);
> >> FD_SET(STDIN, &readfds);
> >>
> >> // don’t care about writefds and exceptfds:
> >> select(STDIN + 1, &readfds, NULL, NULL, &tv);
> >>
> >> cout << “what error: " << WSAGetLastError() << endl;
> >>
> >> if (FD_ISSET(STDIN, &readfds))
> >> printf(“A key was pressed!\n”);
> >> else
> >> printf(“Timed out.\n”);
> >>#ifdef WIN32
> >> WSACleanup();
> >>#endif
> >> return 0;
> >>}
> >>
> >>“A key was pressed” is always printed to the screen, though I
> expected a
> time-out when I didn’t press anything.
> >>
> >>WSAGetLastError() always reports 10038, which I’ve looked up to
mean
> operating on a non-socket.
> >>I’m guessing this is because 0 is not the correct file descriptor
for
> STDIN?
> >>If so, what is the correct number?
> >>
> >>Thanks,
>
>
>
> At 10:52 AM 10/17/2003, Kiran Bacche wrote:
> >I tried to use select on STDIN and it worked. The sample code is…
> >
> >Int fd;
> >fd_set readfs;
> >struct timeval timeout;
> >
> >Fd = 0;
> >FD_ZERO(&readfs);
> >FD_SET(fd, &readfs);
> >timeout.tv_sec = 3;
> >timeout.tv_usec = 0;
> >select(fd + 1, &readfs, NULL, NULL, &timeout);
> >
> >Now this code waits for 3 secs for a keystroke.
> >If I press a key within 3 secs, it comes out as expected.
> >And if I do not press a key, it timesout after 3 secs and comes out
> >again as expected.
> >
> >So now if I want the same thing to work with my device descriptor,
i.e.
> >fd = open(”\\.\kiran", O_RDONLY);
> >
> >Then what extra should I do in my device driver ?
> >
> >As an anology, in Linux there is something like poll_wait that needs
to
> >be written in the linux device driver along with dispatch_read,
> >dispatch_write, etc.
> >
> >Does something like that hold good in windows also ?
> >Or is there any other mechanism ?
> >
> >Thanx
> > Kiran
> >
> >
> >
> >-----Original Message-----
> >From: Mark S. Edwards [mailto:xxxxx@muttsnuts.com]
> >Sent: Friday, October 17, 2003 2:58 PM
> >To: Windows System Software Devs Interest List
> >Subject: [ntdev] Re: Help on select( )
> >
> >
> >On Windows select() only works with socket handles, it does NOT work
> >with
> >any other form of descriptor.
> >
> >If you want read/write notifications, think events, or overlapped I/O
> to
> >
> >completion ports or completion functions.
> >
> >Mark.
> >
> >
> >At 08:01 AM 10/17/2003, Kiran Bacche wrote:
> > >Hi
> > >
> > > If I want a programmer to be able to do a select() on the file
> > >descriptor of my device, then what is the
> > >MajorFunction (IRP_MJ_???) I should have in my driver code ?
> > >
> > >I currenlty have IRP_MJ_CREATE, …CLOSE, …READ and …WRITE only
> > >
> > >Thanx
> > > Kiran
> >
> >
> >—
> >Questions? First check the Kernel Driver FAQ at
> >http://www.osronline.com/article.cfm?id=256
> >
> >You are currently subscribed to ntdev as: xxxxx@wipro.com
> >To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
> >—
> >Questions? First check the Kernel Driver FAQ at
> >http://www.osronline.com/article.cfm?id=256
> >
> >You are currently subscribed to ntdev as: xxxxx@muttsnuts.com
> >To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@wipro.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@wipro.com
To unsubscribe send a blank email to xxxxx@lists.osr.com</winsock2.h></assert.h>