netware.pp 3.3 KB

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