mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-12 10:49:07 +02:00
+ add poll support for unix
git-svn-id: trunk@12128 -
This commit is contained in:
parent
303d951c48
commit
4594758ae5
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -7800,6 +7800,7 @@ tests/test/tparray7.pp svneol=native#text/plain
|
|||||||
tests/test/tparray8.pp svneol=native#text/plain
|
tests/test/tparray8.pp svneol=native#text/plain
|
||||||
tests/test/tparray9.pp svneol=native#text/plain
|
tests/test/tparray9.pp svneol=native#text/plain
|
||||||
tests/test/tpftch1.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/tprec1.pp svneol=native#text/plain
|
||||||
tests/test/tprec10.pp svneol=native#text/plain
|
tests/test/tprec10.pp svneol=native#text/plain
|
||||||
tests/test/tprec11.pp svneol=native#text/plain
|
tests/test/tprec11.pp svneol=native#text/plain
|
||||||
|
@ -456,6 +456,11 @@ begin
|
|||||||
fpSelect:=do_syscall(syscall_nr_select,n,TSysParam(readfds),TSysParam(writefds),TSysParam(exceptfds),TSysParam(timeout));
|
fpSelect:=do_syscall(syscall_nr_select,n,TSysParam(readfds),TSysParam(writefds),TSysParam(exceptfds),TSysParam(timeout));
|
||||||
end;
|
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;
|
Function fpLstat(path:pchar;Info:pstat):cint;
|
||||||
{
|
{
|
||||||
Get all information on a link (the link itself), and return it in info.
|
Get all information on a link (the link itself), and return it in info.
|
||||||
|
@ -296,6 +296,29 @@ CONST
|
|||||||
{$endif}
|
{$endif}
|
||||||
MAP_ANONYMOUS =$1000;
|
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 }
|
{ SIGNALS }
|
||||||
{*************************************************************************}
|
{*************************************************************************}
|
||||||
|
@ -364,3 +364,28 @@ const B_SYMBOL_TYPE_ANY = $5;
|
|||||||
{ Constansts for MMAP }
|
{ Constansts for MMAP }
|
||||||
const
|
const
|
||||||
MAP_ANONYMOUS =$1000;
|
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;
|
||||||
|
|
||||||
|
|
||||||
|
@ -400,6 +400,11 @@ begin
|
|||||||
{$endif bunxfunc_fpselect_implemented}
|
{$endif bunxfunc_fpselect_implemented}
|
||||||
end;
|
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;
|
Function fpLstat(path:pchar;Info:pstat):cint;
|
||||||
{
|
{
|
||||||
Get all information on a link (the link itself), and return it in info.
|
Get all information on a link (the link itself), and return it in info.
|
||||||
|
@ -163,6 +163,29 @@ type
|
|||||||
ptimezone =^timezone;
|
ptimezone =^timezone;
|
||||||
TTimeZone = 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 }
|
{ POSIX CONSTANT ROUTINE DEFINITIONS }
|
||||||
{***********************************************************************}
|
{***********************************************************************}
|
||||||
|
@ -240,3 +240,28 @@ type
|
|||||||
end;
|
end;
|
||||||
TTms= tms;
|
TTms= tms;
|
||||||
pTms= ^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;
|
||||||
|
|
||||||
|
|
||||||
|
@ -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 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 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 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 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 FpNanoSleep (req : ptimespec;rem : ptimespec):cint; external name 'FPC_SYSC_NANOSLEEP';
|
||||||
Function fpLstat(path:pchar;Info:pstat):cint;
|
Function fpLstat(path:pchar;Info:pstat):cint;
|
||||||
|
@ -86,11 +86,14 @@ const
|
|||||||
{$ifdef beos}
|
{$ifdef beos}
|
||||||
{$ifdef haiku}
|
{$ifdef haiku}
|
||||||
Function FPSelect (N:cint;readfds,writefds,exceptfds:pfdSet;TimeOut:PTimeVal):cint; cdecl; external 'network' name 'select';
|
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}
|
{$else}
|
||||||
Function FPSelect (N:cint;readfds,writefds,exceptfds:pfdSet;TimeOut:PTimeVal):cint; cdecl; external 'net' name 'select';
|
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}
|
{$endif}
|
||||||
{$else}
|
{$else}
|
||||||
Function FPSelect (N:cint;readfds,writefds,exceptfds:pfdSet;TimeOut:PTimeVal):cint; cdecl; external clib name 'select';
|
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}
|
{$endif}
|
||||||
function fpgetenv (name : pchar):pchar; cdecl; external clib name 'getenv';
|
function fpgetenv (name : pchar):pchar; cdecl; external clib name 'getenv';
|
||||||
Function FpKill (pid : TPid; sig: cInt): cInt; cdecl; external clib name 'kill';
|
Function FpKill (pid : TPid; sig: cInt): cInt; cdecl; external clib name 'kill';
|
||||||
|
65
tests/test/tpoll.pp
Normal file
65
tests/test/tpoll.pp
Normal 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.
|
Loading…
Reference in New Issue
Block a user