2
0

netware.pp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. {
  2. <partof>
  3. Copyright (c) 1998 by <yourname>
  4. <infoline>
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. unit netware;
  12. interface
  13. const
  14. NlmLib = 'nlmlib.nlm';
  15. type
  16. fdSet=array[0..7] of longint;{=256 bits}
  17. pfdset=^fdset;
  18. TFDSet=fdset;
  19. timeval = packed record
  20. sec,usec:longint
  21. end;
  22. ptimeval=^timeval;
  23. TTimeVal=timeval;
  24. Function Select(N:longint;readfds,writefds,exceptfds:PFDSet;TimeOut:PTimeVal):longint; CDECL; EXTERNAL NlmLib NAME 'select';
  25. Function Select(N:longint;readfds,writefds,exceptfds:PFDSet;TimeOut:Longint):longint;
  26. Function SelectText(var T:Text;TimeOut :PTimeVal):Longint;
  27. Procedure FD_Zero(var fds:fdSet);
  28. Procedure FD_Clr(fd:longint;var fds:fdSet);
  29. Procedure FD_Set(fd:longint;var fds:fdSet);
  30. Function FD_IsSet(fd:longint;var fds:fdSet):boolean;
  31. Function GetFS (var T:Text):longint;
  32. Function GetFS(Var F:File):longint;
  33. implementation
  34. Function Select(N:longint;readfds,writefds,exceptfds:PFDSet;TimeOut:Longint):longint;
  35. {
  36. Select checks whether the file descriptor sets in readfs/writefs/exceptfs
  37. have changed.
  38. This function allows specification of a timeout as a longint.
  39. }
  40. var
  41. p : PTimeVal;
  42. tv : TimeVal;
  43. begin
  44. if TimeOut=-1 then
  45. p:=nil
  46. else
  47. begin
  48. tv.Sec:=Timeout div 1000;
  49. tv.Usec:=(Timeout mod 1000)*1000;
  50. p:=@tv;
  51. end;
  52. Select:=Select(N,Readfds,WriteFds,ExceptFds,p);
  53. end;
  54. Function SelectText(var T:Text;TimeOut :PTimeval):Longint;
  55. Var
  56. F:FDSet;
  57. begin
  58. if textrec(t).mode=fmclosed then
  59. begin
  60. {LinuxError:=Sys_EBADF;}
  61. exit(-1);
  62. end;
  63. FD_Zero(f);
  64. FD_Set(textrec(T).handle,f);
  65. if textrec(T).mode=fminput then
  66. SelectText:=select(textrec(T).handle+1,@f,nil,nil,TimeOut)
  67. else
  68. SelectText:=select(textrec(T).handle+1,nil,@f,nil,TimeOut);
  69. end;
  70. {--------------------------------
  71. FiledescriptorSets
  72. --------------------------------}
  73. Procedure FD_Zero(var fds:fdSet);
  74. {
  75. Clear the set of filedescriptors
  76. }
  77. begin
  78. FillChar(fds,sizeof(fdSet),0);
  79. end;
  80. Procedure FD_Clr(fd:longint;var fds:fdSet);
  81. {
  82. Remove fd from the set of filedescriptors
  83. }
  84. begin
  85. fds[fd shr 5]:=fds[fd shr 5] and (not (1 shl (fd and 31)));
  86. end;
  87. Procedure FD_Set(fd:longint;var fds:fdSet);
  88. {
  89. Add fd to the set of filedescriptors
  90. }
  91. begin
  92. fds[fd shr 5]:=fds[fd shr 5] or (1 shl (fd and 31));
  93. end;
  94. Function FD_IsSet(fd:longint;var fds:fdSet):boolean;
  95. {
  96. Test if fd is part of the set of filedescriptors
  97. }
  98. begin
  99. FD_IsSet:=((fds[fd shr 5] and (1 shl (fd and 31)))<>0);
  100. end;
  101. Function GetFS (var T:Text):longint;
  102. {
  103. Get File Descriptor of a text file.
  104. }
  105. begin
  106. if textrec(t).mode=fmclosed then
  107. exit(-1)
  108. else
  109. GETFS:=textrec(t).Handle
  110. end;
  111. Function GetFS(Var F:File):longint;
  112. {
  113. Get File Descriptor of an unTyped file.
  114. }
  115. begin
  116. { Handle and mode are on the same place in textrec and filerec. }
  117. if filerec(f).mode=fmclosed then
  118. exit(-1)
  119. else
  120. GETFS:=filerec(f).Handle
  121. end;
  122. end.