+ add poll support for unix

git-svn-id: trunk@12128 -
This commit is contained in:
micha 2008-11-16 17:05:47 +00:00
parent 303d951c48
commit 4594758ae5
10 changed files with 176 additions and 0 deletions

1
.gitattributes vendored
View File

@ -7800,6 +7800,7 @@ tests/test/tparray7.pp svneol=native#text/plain
tests/test/tparray8.pp svneol=native#text/plain
tests/test/tparray9.pp svneol=native#text/plain
tests/test/tpftch1.pp svneol=native#text/plain
tests/test/tpoll.pp svneol=native#text/plain
tests/test/tprec1.pp svneol=native#text/plain
tests/test/tprec10.pp svneol=native#text/plain
tests/test/tprec11.pp svneol=native#text/plain

View File

@ -456,6 +456,11 @@ begin
fpSelect:=do_syscall(syscall_nr_select,n,TSysParam(readfds),TSysParam(writefds),TSysParam(exceptfds),TSysParam(timeout));
end;
function fpPoll(fds: ppollfd; nfds: cuint; timeout: clong): cint;
begin
fpPoll:=do_syscall(syscall_nr_poll,tsysparam(fds),tsysparam(nfds),tsysparam(timeout));
end;
Function fpLstat(path:pchar;Info:pstat):cint;
{
Get all information on a link (the link itself), and return it in info.

View File

@ -296,6 +296,29 @@ CONST
{$endif}
MAP_ANONYMOUS =$1000;
const
POLLIN = $0001;
POLLPRI = $0002;
POLLOUT = $0004;
POLLERR = $0008;
POLLHUP = $0010;
POLLNVAL = $0020;
{ XOpen, XPG 4.2 }
POLLRDNORM = $0040;
POLLRDBAND = $0080;
POLLWRNORM = POLLOUT;
POLLWRBAND = $0100;
type
pollfd = record
fd: cint;
events: cshort;
revents: cshort;
end;
tpollfd = pollfd;
ppollfd = ^pollfd;
{*************************************************************************}
{ SIGNALS }
{*************************************************************************}

View File

@ -364,3 +364,28 @@ const B_SYMBOL_TYPE_ANY = $5;
{ Constansts for MMAP }
const
MAP_ANONYMOUS =$1000;
const
POLLIN = $0001;
POLLOUT = $0002;
POLLERR = $0004;
POLLPRI = $0020;
POLLHUP = $0080;
POLLNVAL = $1000;
{ XOpen, XPG 4.2 }
POLLRDNORM = POLLIN;
POLLRDBAND = $0008;
POLLWRNORM = POLLOUT;
POLLWRBAND = $0010;
type
pollfd = record
fd: cint;
events: cshort;
revents: cshort;
end;
tpollfd = pollfd;
ppollfd = ^pollfd;

View File

@ -400,6 +400,11 @@ begin
{$endif bunxfunc_fpselect_implemented}
end;
function fpPoll(fds: ppollfd; nfds: cuint; timeout: clong): cint;
begin
fpPoll:=do_syscall(syscall_nr_poll,tsysparam(fds),tsysparam(nfds),tsysparam(timeout));
end;
Function fpLstat(path:pchar;Info:pstat):cint;
{
Get all information on a link (the link itself), and return it in info.

View File

@ -163,6 +163,29 @@ type
ptimezone =^timezone;
TTimeZone = timezone;
const
POLLIN = $0001;
POLLPRI = $0002;
POLLOUT = $0004;
POLLERR = $0008;
POLLHUP = $0010;
POLLNVAL = $0020;
{ XOpen, XPG 4.2 }
POLLRDNORM = $0040;
POLLRDBAND = $0080;
POLLWRNORM = $0100;
POLLWRBAND = $0200;
type
pollfd = record
fd: cint;
events: cshort;
revents: cshort;
end;
tpollfd = pollfd;
ppollfd = ^pollfd;
{***********************************************************************}
{ POSIX CONSTANT ROUTINE DEFINITIONS }
{***********************************************************************}

View File

@ -240,3 +240,28 @@ type
end;
TTms= tms;
pTms= ^tms;
const
POLLIN = $0001;
POLLPRI = $0002;
POLLOUT = $0004;
POLLERR = $0008;
POLLHUP = $0010;
POLLNVAL = $0020;
{ XOpen, XPG 4.2 }
POLLRDNORM = $0040;
POLLRDBAND = $0080;
POLLWRNORM = POLLOUT;
POLLWRBAND = $0100;
type
pollfd = record
fd: cint;
events: cshort;
revents: cshort;
end;
tpollfd = pollfd;
ppollfd = ^pollfd;

View File

@ -90,6 +90,7 @@ Type TGrpArr = Array [0..0] of TGid; { C style array workarounds}
Function FpFtruncate (fd : cInt; flength : TOff): cInt; external name 'FPC_SYSC_FTRUNCATE';
Function FPSigaction (sig: cInt; act : pSigActionRec; oact : pSigActionRec): cint; external name 'FPC_SYSC_SIGACTION';
Function FPSelect (N:cint;readfds,writefds,exceptfds:pfdSet;TimeOut:PTimeVal):cint;
Function FpPoll (fds: ppollfd; nfds: cuint; timeout: clong): cint;
Function FpIOCtl (Handle:cint;Ndx: TIOCtlRequest; Data: Pointer):cint; external name 'FPC_SYSC_IOCTL';
Function FpNanoSleep (req : ptimespec;rem : ptimespec):cint; external name 'FPC_SYSC_NANOSLEEP';
Function fpLstat(path:pchar;Info:pstat):cint;

View File

@ -86,11 +86,14 @@ const
{$ifdef beos}
{$ifdef haiku}
Function FPSelect (N:cint;readfds,writefds,exceptfds:pfdSet;TimeOut:PTimeVal):cint; cdecl; external 'network' name 'select';
Function FpPoll (fds: ppollfd; nfds: cuint; timeout: clong): cint; cdecl; external 'network' name 'poll';
{$else}
Function FPSelect (N:cint;readfds,writefds,exceptfds:pfdSet;TimeOut:PTimeVal):cint; cdecl; external 'net' name 'select';
Function FpPoll (fds: ppollfd; nfds: cuint; timeout: clong): cint; cdecl; external 'net' name 'poll';
{$endif}
{$else}
Function FPSelect (N:cint;readfds,writefds,exceptfds:pfdSet;TimeOut:PTimeVal):cint; cdecl; external clib name 'select';
Function FpPoll (fds: ppollfd; nfds: cuint; timeout: clong): cint; cdecl; external clib name 'poll';
{$endif}
function fpgetenv (name : pchar):pchar; cdecl; external clib name 'getenv';
Function FpKill (pid : TPid; sig: cInt): cInt; cdecl; external clib name 'kill';

65
tests/test/tpoll.pp Normal file
View File

@ -0,0 +1,65 @@
{%TARGET=darwin,haiku,linux,freebsd,netbsd,openbsd,solaris}
{$mode fpc}
uses
baseunix;
const
testbyte = '!';
var
pollfds: pollfd;
fds: array[0..1] of cint;
ret: cint;
x: char;
begin
fppipe(fds);
pollfds.fd := fds[0];
pollfds.events := POLLIN;
pollfds.revents := 0;
ret := fppoll(@pollfds, 1, 10);
if ret <> 0 then
begin
writeln('poll returned ', ret, ' (expected 0 = timeout), errno=', errno);
halt(1);
end;
x := testbyte;
ret := fpwrite(fds[1], x, 1);
if ret <> 1 then
begin
writeln('write returned ', ret, ' (expected 1 byte), errno=', errno);
halt(2);
end;
ret := fppoll(@pollfds, 1, 10);
if ret <> 1 then
begin
writeln('poll returned ', ret, ' (expected 1 = data ready), errno=', errno);
halt(3);
end;
if (pollfds.revents and POLLIN) = 0 then
begin
writeln('poll did not set POLLIN');
halt(4);
end;
x := #0;
ret := fpread(fds[0], @x, 1);
if ret <> 1 then
begin
writeln('read returned ', ret, ' (expected 1 byte), errno=', errno);
halt(5);
end;
if x <> testbyte then
begin
writeln('test byte is ''', x, ''' (expected ''', testbyte, ''')');
halt(6);
end;
ret := fppoll(@pollfds, 1, 10);
if ret <> 0 then
begin
writeln('poll returned ', ret, ' (expected 0 = timeout), errno=', errno);
halt(7);
end;
fpclose(fds[0]);
fpclose(fds[1]);
end.