Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
LSH
lsh
Commits
75c3ade0
Commit
75c3ade0
authored
Oct 13, 1998
by
Niels Möller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New files
Rev: src/jpoll.c:1.1 Rev: src/jpoll.h:1.1
parent
4488b530
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
0 deletions
+86
-0
src/jpoll.c
src/jpoll.c
+61
-0
src/jpoll.h
src/jpoll.h
+25
-0
No files found.
src/jpoll.c
0 → 100644
View file @
75c3ade0
/*
* AUTHOR: Sean Reifschneider <jafo@tummy.com>
* DATE: 1998-10-10
* Copyright (c) 1998 Sean Reifschneider
*
* This code emulates a minimal poll() function, and can be used as a drop-in
* replacement for the SVID3 implementation. Note that at this time it only
* emulates the POLLIN and POLLOUT events.
*/
#include <stdio.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include "jpoll.h"
int
poll
(
struct
pollfd
*
fdlist
,
nfds_t
count
,
int
timeoutInMS
)
{
struct
timeval
timeout
,
*
to
;
fd_set
readfdset
,
writefdset
;
nfds_t
i
;
int
ret
,
fdcount
=
0
;
int
tsize
=
getdtablesize
();
if
(
timeoutInMS
<
0
)
to
=
NULL
;
else
{
to
=
&
timeout
;
timeout
.
tv_sec
=
timeoutInMS
/
1000
;
timeout
.
tv_usec
=
(
timeoutInMS
%
1000
)
*
1000
;
}
FD_ZERO
(
&
readfdset
);
FD_ZERO
(
&
writefdset
);
for
(
i
=
0
;
i
<
count
;
i
++
)
{
if
(
fdlist
[
i
].
fd
<
0
)
continue
;
if
(
fdlist
[
i
].
events
&
POLLIN
)
FD_SET
(
fdlist
[
i
].
fd
,
&
readfdset
);
if
(
fdlist
[
i
].
events
&
POLLOUT
)
FD_SET
(
fdlist
[
i
].
fd
,
&
writefdset
);
fdcount
++
;
}
/* spec says that if all FDs are negative, then *ONLY* return zero */
if
(
fdcount
==
0
)
return
(
0
);
/* clear all events */
for
(
i
=
0
;
i
<
count
;
i
++
)
fdlist
[
i
].
revents
=
0
;
if
((
ret
=
select
(
tsize
,
&
readfdset
,
&
writefdset
,
NULL
,
&
timeout
))
==
-
1
)
return
(
-
1
);
for
(
i
=
0
;
i
<
count
;
i
++
)
{
if
(
FD_ISSET
(
fdlist
[
i
].
fd
,
&
readfdset
))
fdlist
[
i
].
revents
|=
POLLIN
;
if
(
FD_ISSET
(
fdlist
[
i
].
fd
,
&
writefdset
))
fdlist
[
i
].
revents
|=
POLLOUT
;
printf
(
"Set FD %d = %d
\n
"
,
fdlist
[
i
].
revents
);
}
printf
(
"Returning %d
\n
"
,
ret
);
return
(
ret
);
}
src/jpoll.h
0 → 100644
View file @
75c3ade0
/*
* AUTHOR: Sean Reifschneider <jafo@tummy.com>
* DATE: 1998-10-10
* Copyright (c) 1998 Sean Reifschneider
*
* Header file for my poll() SVID3 emulation function.
*/
#ifndef JPOLL_H_INCLUDED
#define JPOLL_H_INCLUDED
#define POLLIN 0x0001
/* check for input */
#define POLLOUT 0x0004
/* check for output */
struct
pollfd
{
int
fd
;
/* file descriptor to poll */
short
events
;
/* events we are interested in */
short
revents
;
/* events that occured */
};
typedef
unsigned
int
nfds_t
;
int
poll
(
struct
pollfd
*
fdlist
,
nfds_t
count
,
int
timeoutInMS
);
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment