netware.pp 3.2 KB

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