commit 00535cc35b555152fe0014de52c932880cf7fb6e
parent 4beccd39d13c030c788334349728bf5c60642c36
Author: Commit-Bot <unknown>
Date:   Fri, 17 Sep 2010 13:17:20 +0000
Automatic commit from picoLisp.tgz, From: Fri, 17 Sep 2010 13:17:20 GMT
Diffstat:
4 files changed, 198 insertions(+), 182 deletions(-)
diff --git a/lib/tags b/lib/tags
@@ -29,7 +29,7 @@ adr (613 . "@src64/main.l")
 alarm (487 . "@src64/main.l")
 all (772 . "@src64/sym.l")
 and (1643 . "@src64/flow.l")
-any (3778 . "@src64/io.l")
+any (3801 . "@src64/io.l")
 append (1329 . "@src64/subr.l")
 apply (597 . "@src64/apply.l")
 arg (2243 . "@src64/main.l")
@@ -82,11 +82,11 @@ cdddr (245 . "@src64/subr.l")
 cddr (79 . "@src64/subr.l")
 cdr (17 . "@src64/subr.l")
 chain (1132 . "@src64/subr.l")
-char (3260 . "@src64/io.l")
+char (3283 . "@src64/io.l")
 chop (1093 . "@src64/sym.l")
 circ (816 . "@src64/subr.l")
 clip (1786 . "@src64/subr.l")
-close (4166 . "@src64/io.l")
+close (4189 . "@src64/io.l")
 cmd (2846 . "@src64/main.l")
 cnt (1297 . "@src64/apply.l")
 co (2566 . "@src64/flow.l")
@@ -97,7 +97,7 @@ cond (1938 . "@src64/flow.l")
 connect (201 . "@src64/net.l")
 cons (747 . "@src64/subr.l")
 copy (1216 . "@src64/subr.l")
-ctl (4106 . "@src64/io.l")
+ctl (4129 . "@src64/io.l")
 ctty (2644 . "@src64/main.l")
 cut (1797 . "@src64/sym.l")
 date (2358 . "@src64/main.l")
@@ -114,13 +114,13 @@ dir (2777 . "@src64/main.l")
 dm (561 . "@src64/flow.l")
 do (2158 . "@src64/flow.l")
 e (2932 . "@src64/flow.l")
-echo (4197 . "@src64/io.l")
+echo (4220 . "@src64/io.l")
 env (625 . "@src64/main.l")
-eof (3337 . "@src64/io.l")
-eol (3328 . "@src64/io.l")
+eof (3360 . "@src64/io.l")
+eol (3351 . "@src64/io.l")
 errno (1358 . "@src64/main.l")
 eval (208 . "@src64/flow.l")
-ext (4926 . "@src64/io.l")
+ext (4949 . "@src64/io.l")
 ext? (1034 . "@src64/sym.l")
 extern (900 . "@src64/sym.l")
 extra (1284 . "@src64/flow.l")
@@ -135,13 +135,13 @@ find (1206 . "@src64/apply.l")
 fish (1497 . "@src64/apply.l")
 flg? (2419 . "@src64/subr.l")
 flip (1686 . "@src64/subr.l")
-flush (4901 . "@src64/io.l")
+flush (4924 . "@src64/io.l")
 fold (3343 . "@src64/sym.l")
 for (2247 . "@src64/flow.l")
 fork (3276 . "@src64/flow.l")
 format (2089 . "@src64/big.l")
 free (2042 . "@src64/db.l")
-from (3356 . "@src64/io.l")
+from (3379 . "@src64/io.l")
 full (1066 . "@src64/subr.l")
 fun? (734 . "@src64/sym.l")
 gc (439 . "@src64/gc.l")
@@ -153,14 +153,14 @@ glue (1234 . "@src64/sym.l")
 gt0 (2702 . "@src64/big.l")
 head (1807 . "@src64/subr.l")
 heap (542 . "@src64/main.l")
-hear (3078 . "@src64/io.l")
+hear (3082 . "@src64/io.l")
 host (184 . "@src64/net.l")
 id (1027 . "@src64/db.l")
 idx (2037 . "@src64/sym.l")
 if (1824 . "@src64/flow.l")
 if2 (1843 . "@src64/flow.l")
 ifn (1884 . "@src64/flow.l")
-in (4002 . "@src64/io.l")
+in (4025 . "@src64/io.l")
 inc (2256 . "@src64/big.l")
 index (2611 . "@src64/subr.l")
 info (2681 . "@src64/main.l")
@@ -169,21 +169,21 @@ ipid (3221 . "@src64/flow.l")
 isa (978 . "@src64/flow.l")
 job (1448 . "@src64/flow.l")
 journal (970 . "@src64/db.l")
-key (3187 . "@src64/io.l")
+key (3210 . "@src64/io.l")
 kill (3253 . "@src64/flow.l")
 last (2031 . "@src64/subr.l")
 length (2687 . "@src64/subr.l")
 let (1498 . "@src64/flow.l")
 let? (1559 . "@src64/flow.l")
 lieu (1156 . "@src64/db.l")
-line (3512 . "@src64/io.l")
-lines (3665 . "@src64/io.l")
+line (3535 . "@src64/io.l")
+lines (3688 . "@src64/io.l")
 link (1163 . "@src64/subr.l")
 lisp (1921 . "@src64/main.l")
 list (887 . "@src64/subr.l")
 listen (151 . "@src64/net.l")
 lit (183 . "@src64/flow.l")
-load (3979 . "@src64/io.l")
+load (4002 . "@src64/io.l")
 lock (1184 . "@src64/db.l")
 loop (2190 . "@src64/flow.l")
 low? (3215 . "@src64/sym.l")
@@ -233,31 +233,31 @@ offset (2651 . "@src64/subr.l")
 on (1583 . "@src64/sym.l")
 onOff (1613 . "@src64/sym.l")
 one (1646 . "@src64/sym.l")
-open (4128 . "@src64/io.l")
+open (4151 . "@src64/io.l")
 opid (3237 . "@src64/flow.l")
 opt (2967 . "@src64/main.l")
 or (1659 . "@src64/flow.l")
-out (4022 . "@src64/io.l")
+out (4045 . "@src64/io.l")
 pack (1144 . "@src64/sym.l")
 pair (2381 . "@src64/subr.l")
 pass (638 . "@src64/apply.l")
 pat? (720 . "@src64/sym.l")
 path (1200 . "@src64/io.l")
-peek (3244 . "@src64/io.l")
+peek (3267 . "@src64/io.l")
 pick (1253 . "@src64/apply.l")
 pid (157 . "@src64/flow.l")
-pipe (4043 . "@src64/io.l")
-poll (3140 . "@src64/io.l")
+pipe (4066 . "@src64/io.l")
+poll (3154 . "@src64/io.l")
 pool (648 . "@src64/db.l")
 pop (1773 . "@src64/sym.l")
 port (5 . "@src64/net.l")
-pr (5017 . "@src64/io.l")
+pr (5040 . "@src64/io.l")
 pre? (1411 . "@src64/sym.l")
-prin (4825 . "@src64/io.l")
-prinl (4839 . "@src64/io.l")
-print (4865 . "@src64/io.l")
-println (4896 . "@src64/io.l")
-printsp (4881 . "@src64/io.l")
+prin (4848 . "@src64/io.l")
+prinl (4862 . "@src64/io.l")
+print (4888 . "@src64/io.l")
+println (4919 . "@src64/io.l")
+printsp (4904 . "@src64/io.l")
 prog (1779 . "@src64/flow.l")
 prog1 (1787 . "@src64/flow.l")
 prog2 (1804 . "@src64/flow.l")
@@ -276,15 +276,15 @@ rand (2959 . "@src64/big.l")
 range (988 . "@src64/subr.l")
 rank (2970 . "@src64/subr.l")
 raw (465 . "@src64/main.l")
-rd (4943 . "@src64/io.l")
+rd (4966 . "@src64/io.l")
 read (2532 . "@src64/io.l")
 replace (1490 . "@src64/subr.l")
 rest (2272 . "@src64/main.l")
 reverse (1665 . "@src64/subr.l")
-rewind (4909 . "@src64/io.l")
+rewind (4932 . "@src64/io.l")
 rollback (1886 . "@src64/db.l")
 rot (848 . "@src64/subr.l")
-rpc (5050 . "@src64/io.l")
+rpc (5073 . "@src64/io.l")
 run (331 . "@src64/flow.l")
 sect (2515 . "@src64/subr.l")
 seed (2944 . "@src64/big.l")
@@ -295,31 +295,31 @@ set (1482 . "@src64/sym.l")
 setq (1515 . "@src64/sym.l")
 sigio (503 . "@src64/main.l")
 size (2752 . "@src64/subr.l")
-skip (3314 . "@src64/io.l")
+skip (3337 . "@src64/io.l")
 sort (3869 . "@src64/subr.l")
 sp? (711 . "@src64/sym.l")
-space (4843 . "@src64/io.l")
+space (4866 . "@src64/io.l")
 split (1579 . "@src64/subr.l")
 stack (571 . "@src64/main.l")
 state (2028 . "@src64/flow.l")
 stem (1976 . "@src64/subr.l")
-str (3832 . "@src64/io.l")
+str (3855 . "@src64/io.l")
 str? (1013 . "@src64/sym.l")
 strip (1563 . "@src64/subr.l")
 sub? (1444 . "@src64/sym.l")
 sum (1344 . "@src64/apply.l")
 super (1237 . "@src64/flow.l")
-sym (3818 . "@src64/io.l")
+sym (3841 . "@src64/io.l")
 sym? (2408 . "@src64/subr.l")
-sync (3040 . "@src64/io.l")
+sync (3044 . "@src64/io.l")
 sys (3073 . "@src64/flow.l")
 t (1770 . "@src64/flow.l")
 tail (1898 . "@src64/subr.l")
-tell (3110 . "@src64/io.l")
+tell (3114 . "@src64/io.l")
 text (1272 . "@src64/sym.l")
 throw (2510 . "@src64/flow.l")
 tick (3189 . "@src64/flow.l")
-till (3423 . "@src64/io.l")
+till (3446 . "@src64/io.l")
 time (2491 . "@src64/main.l")
 touch (1049 . "@src64/sym.l")
 trim (1746 . "@src64/subr.l")
@@ -336,12 +336,12 @@ use (1592 . "@src64/flow.l")
 usec (2596 . "@src64/main.l")
 val (1463 . "@src64/sym.l")
 version (2981 . "@src64/main.l")
-wait (3002 . "@src64/io.l")
+wait (3006 . "@src64/io.l")
 when (1903 . "@src64/flow.l")
 while (2080 . "@src64/flow.l")
 wipe (3090 . "@src64/sym.l")
 with (1349 . "@src64/flow.l")
-wr (5034 . "@src64/io.l")
+wr (5057 . "@src64/io.l")
 xchg (1538 . "@src64/sym.l")
 xor (1720 . "@src64/flow.l")
 x| (2871 . "@src64/big.l")
diff --git a/src64/io.l b/src64/io.l
@@ -1,4 +1,4 @@
-# 15sep10abu
+# 17sep10abu
 # (c) Software Lab. Alexander Burger
 
 # Close file descriptor
@@ -2567,38 +2567,65 @@
    ret
 
 # Check if input channel has data
-(code 'inFilesA_FC 0)
-   ld C A
-   shl C 3  # Vector index
-   add C (InFiles)  # Get vector
-   ld C (C)  # Slot?
-   null C  # Any?
-   ret
-
-(code 'inReadyA_FC 0)
-   ld C A
-   shl C 3  # Vector index
-   cmp C (InFDs)  # 'fd' >= 'InFDs'?
+(code 'inReadyC_F 0)
+   ld A C
+   shl A 3  # Vector index
+   cmp A (InFDs)  # 'fd' >= 'InFDs'?
    jge ret  # No
-   add C (InFiles)  # Get vector
-   ld C (C)  # Slot?
-   null C  # Any?
+   add A (InFiles)  # Get vector
+   ld A (A)  # Slot?
+   null A  # Any?
    jz ret  # No
-   cmp (C I) (C II)  # Data in buffer ('ix' < 'cnt')?
+   cmp (A I) (A II)  # Data in buffer ('ix' < 'cnt')?
    ret  # Yes: Return 'c'
 
-(code 'rdSetRdyAL_F 0)  # Z
-   ld C A
-   shl C 3  # Vector index
-   cmp C (InFDs)  # 'fd' >= 'InFDs'?
-   jge rdSetAL_F  # Yes
-   add C (InFiles)  # Get vector
-   ld C (C)  # Slot?
-   null C  # Any?
-   jz rdSetAL_F  # No
-   cmp (C I) (C II)  # Data in buffer ('ix' < 'cnt')?
+(code 'fdSetCL_X 0)
+   ld X C  # Get fd
+   and C 7  # Shift count
+   ld B 1  # Bit mask
+   shl B C  # Shift it
+   shr X 3  # Offset
+   add X L  # Point to byte
+   ret
+
+(code 'fdRdSetCZL 0)  # X
+   cmp Z C  # Maintain maximum
+   ldc Z C
+   call fdSetCL_X
+   or (X (- (+ V FD_SET))) B  # FD_SET in RdSet
+   ret
+
+(code 'fdWrSetCZL 0)  # X
+   cmp Z C  # Maintain maximum
+   ldc Z C
+   call fdSetCL_X
+   or (X (- (+ V FD_SET FD_SET))) B  # FD_SET in WrSet
+   ret
+
+(code 'rdSetCL_F 0)  # X
+   call fdSetCL_X
+   test (X (- (+ V FD_SET))) B  # FD_SET in RdSet
+   ret  # Return 'nz'
+
+(code 'wrSetCL_F 0)  # X
+   call fdSetCL_X
+   test (X (- (+ V FD_SET FD_SET))) B  # FD_SET in WrSet
+   ret  # Return 'nz'
+
+(code 'rdSetRdyCL_F 0)  # X
+   ld A C
+   shl A 3  # Vector index
+   cmp A (InFDs)  # 'fd' >= 'InFDs'?
+   jge rdSetCL_F  # Yes
+   add A (InFiles)  # Get vector
+   ld A (A)  # Slot?
+   null A  # Any?
+   jz rdSetCL_F  # No
+   cmp (A I) (A II)  # Data in buffer ('ix' < 'cnt')?
    if z  # No
-      call rdSetAL_F
+      push A
+      call rdSetCL_F
+      pop C
       if nz  # Yes
          call slowNbC_FA  # Try non-blocking read
          jge retnz
@@ -2607,30 +2634,6 @@
    end
    ret
 
-(code 'rdSetAL_F 0)  # Z
-   lea Z (L -V)  # Beyond last 'poll' structure
-   do
-      cmp Z (L -V)  # More structures?
-      jeq ret  # No: 'z'
-      sub Z POLLFD  # Next structure
-      cmp4 (Z)  # Found 'fd'?
-   until eq  # Yes
-   ld2 (Z POLL_REVENTS)  # 'revents'
-   test A (| POLLIN POLLHUP)  # Ready?
-   ret  # Return 'nz'
-
-(code 'wrSetAL_F 0)  # Z
-   lea Z (L -V)  # Beyond last 'poll' structure
-   do
-      cmp Z (L -V)  # More structures?
-      jeq ret  # No: 'z'
-      sub Z POLLFD  # Next structure
-      cmp4 (Z)  # Found 'fd'?
-   until eq  # Yes
-   ld2 (Z POLL_REVENTS)  # 'revents'
-   test A (| POLLOUT POLLHUP)  # Ready?
-   ret  # Return 'nz'
-
 (code 'waitFdCEX_A)
    push Y
    push Z
@@ -2642,19 +2645,25 @@
    push C  # <L -I> File descriptor
    push E  # <L -II> Milliseconds
    push E  # <L -III> Timeout
-   sub S II  # <L -IV> Drain flag, <L -V> Poll array
+   sub S (+ II FD_SET FD_SET)  # <L -IV> Microseconds, Drain
+                               # <L -V> Seconds
+                               # <L - (V + FD_SET)> RdSet
+                               # <L - (V + FD_SET - FD_SET)> WrSet
+   cmp S (StkLimit)  # Stack check
+   jlt stkErrX
    do
-      ld A (L -I)  # File descriptor
-      null A  # Positive?
+      ld B 0  # Zero fd sets
+      mset (S) (+ FD_SET FD_SET)
+      push X  # Save context
+      ld Z 0  # Maximum fd
+      ld C (L -I)  # File descriptor
+      null C  # Positive?
       if ns  # Yes
-         call inReadyA_FC  # Ready?
+         call inReadyC_F  # Ready?
          if c  # Yes
             ld (L -III) 0  # Timeout = 0
          else
-            sub S POLLFD  # Create 'poll' structure
-            st4 (S)  # Store 'fd'
-            ld A POLLIN  # Poll input
-            st2 (S POLL_EVENTS)  # Store 'events'
+            call fdRdSetCZL
          end
       end
       ld Y (Run)  # Get '*Run'
@@ -2672,8 +2681,8 @@
             jeq 10  # Yes: Skip
             ld A (A CDR)
          loop
-         ld A (E)  # Get fd or timeout value
-         shr A 4  # Negative?
+         ld C (E)  # Get fd or timeout value
+         shr C 4  # Negative?
          if c  # Yes
             ld A ((E CDR))  # Get CADR
             shr A 4  # Normalize
@@ -2682,47 +2691,42 @@
                ld (L -III) A  # Set new timeout
             end
          else
-            cmp A (L -I)  # Different from argument-fd?
+            cmp C (L -I)  # Different from argument-fd?
             if ne  # Yes
-               call inReadyA_FC  # Ready?
+               call inReadyC_F  # Ready?
                if c  # Yes
                   ld (L -III) 0  # Timeout = 0
                else
-                  sub S POLLFD  # Create 'poll' structure
-                  st4 (S)  # Store 'fd'
-                  ld A POLLIN  # Poll input
-                  st2 (S POLL_EVENTS)  # Store 'events'
+                  call fdRdSetCZL
                end
             end
          end
 10       ld Y (Y CDR)
       loop
-      ld A (Hear)  # RPC listener?
-      null A
+      ld C (Hear)  # RPC listener?
+      null C
       if nz  # Yes
-         cmp A (L -I)  # Different from argument-fd?
+         cmp C (L -I)  # Different from argument-fd?
          if ne  # Yes
-            call inFilesA_FC  # Still open?
+            ld A C  # Still open?
+            shl A 3  # Vector index
+            add A (InFiles)  # Get vector
+            ld A (A)  # Slot?
+            null A  # Any?
             if nz  # Yes
-               cmp (C I) (C II)  # Data in buffer ('ix' < 'cnt')?
+               cmp (A I) (A II)  # Data in buffer ('ix' < 'cnt')?
                if nz  # Yes
                   ld (L -III) 0  # Timeout = 0
                else
-                  sub S POLLFD  # Create 'poll' structure
-                  st4 (S)  # Store 'Hear'
-                  ld A POLLIN  # Poll input
-                  st2 (S POLL_EVENTS)  # Store 'events'
+                  call fdRdSetCZL
                end
             end
          end
       end
-      ld A (Spkr)  # Speaker open?
-      null A
+      ld C (Spkr)  # Speaker open?
+      null C
       if nz  # Yes
-         sub S POLLFD  # Create 'poll' structure
-         st4 (S)  # Store 'Spkr'
-         ld A POLLIN  # Poll input
-         st2 (S POLL_EVENTS)  # Store 'events'
+         call fdRdSetCZL
       end
       ld Y (Child)  # Iterate children
       ld E (Children)  # Count
@@ -2731,32 +2735,33 @@
       while ge  # Yes
          null (Y)  # 'pid'?
          if nz  # Yes
-            sub S POLLFD  # Create 'poll' structure
-            ld A (Y I)  # Store child's 'hear' fd
-            st4 (S)
-            ld A POLLIN  # Poll input
-            st2 (S POLL_EVENTS)  # Store 'events'
+            ld C (Y I)  # Child's 'hear' fd
+            call fdRdSetCZL
             null (Y IV)  # Child's buffer count?
             if nz  # Yes
-               sub S POLLFD  # Create 'poll' structure
-               ld A (Y II)  # Store child's 'tell' fd
-               st4 (S)
-               ld A POLLOUT  # Poll output
-               st2 (S POLL_EVENTS)  # Store 'events'
+               ld C (Y II)  # Child's 'tell' fd
+               call fdWrSetCZL
             end
          end
          add Y VI  # Increment by sizeof(child)
       loop
-      cmp S (StkLimit)  # Stack check
-      jlt stkErrX
-      lea C (L -V)  # Set poll array pointer
-      ld (C) S
-      sub C S  # Calculate poll count
-      shr C POLLFD_SH
+      pop X  # Restore context
+      inc Z  # Maximum fd + 1
+      ld C 0  # Timeval structure pointer
+      ld A (L -III)  # Timeout value?
+      null A
+      if ns  # Yes
+         div 1000  # Calculate seconds (C is zero)
+         ld (L -V) A
+         ld A C  # and microseconds
+         mul 1000
+         ld (L -IV) A
+         lea C (L -V)
+      end
       call msec_A  # Get milliseconds
       ld E A  # into E
       do
-         cc poll(S C (L -III))  # Wait for event or timeout
+         cc select(Z &(S FD_SET) S 0 C)  # Wait for event or timeout
          nul4  # OK?
       while s  # No
          call errno_A
@@ -2776,15 +2781,15 @@
       set (L -IV) 0  # Guarantee drained pipes
       ld Y (Child)  # Iterate children
       ld Z (Children)  # Count
-      push X  # Save context
+      push X  # Save context again
       do
          sub Z VI  # More?
       while ge  # Yes
          null (Y)  # 'pid'?
          if nz  # Yes
             push Z  # Outer loop count
-            ld A (Y I)  # Get child's 'hear' fd
-            call rdSetAL_F  # Ready?
+            ld C (Y I)  # Get child's 'hear' fd
+            call rdSetCL_F  # Ready?
             if nz  # Yes
                ld C (Y I)  # Get 'hear' fd again
                ld E 2  # Size of count
@@ -2830,8 +2835,8 @@
                   add S PIPE_BUF  # Drop 'tell' buffer
                end
             end
-            ld A (Y II)  # Get child's 'tell' fd
-            call wrSetAL_F  # Ready?
+            ld C (Y II)  # Get child's 'tell' fd
+            call wrSetCL_F  # Ready?
             if nz  # Yes
                ld C (Y II)  # Get 'tell' fd again
                ld X (Y V)  # Get buffer pointer
@@ -2871,10 +2876,10 @@
       loop
       nul (L -IV)  # All pipes drained?
       if z  # Yes
-         ld A (Spkr)  # Speaker open?
-         null A
+         ld C (Spkr)  # Speaker open?
+         null C
          if nz  # Yes
-            call rdSetAL_F  # Ready?
+            call rdSetCL_F  # Ready?
             if nz  # Yes
                ld C (Spkr)  # Get fd
                ld E I  # Size of slot
@@ -2893,12 +2898,12 @@
             end
          end
       end
-      ld A (Hear)  # RPC listener?
-      null A
+      ld C (Hear)  # RPC listener?
+      null C
       if nz  # Yes
-         cmp A (L -I)  # Different from argument-fd?
+         cmp C (L -I)  # Different from argument-fd?
          if ne  # Yes
-            call rdSetRdyAL_F  # Ready?
+            call rdSetRdyCL_F  # Ready?
             if nz  # Yes
                call rdHear_FE  # Read expression?
                if nc  # Yes
@@ -2913,6 +2918,7 @@
                      drop
                   end
                else
+                  ld A (Hear)
                   call closeAX  # Close 'Hear'
                   ld A (Hear)
                   call closeInFileA
@@ -2936,8 +2942,8 @@
             jeq 30  # Yes: Skip
             ld A (A CDR)
          loop
-         ld A (E)  # Get fd or timeout value
-         shr A 4  # Negative?
+         ld C (E)  # Get fd or timeout value
+         shr C 4  # Negative?
          if c  # Yes
             ld C (E CDR)  # Get CDR
             ld A (C)  # and CADR
@@ -2955,9 +2961,9 @@
                prog Z
             end
          else
-            cmp A (L -I)  # Different from argument-fd?
+            cmp C (L -I)  # Different from argument-fd?
             if ne  # Yes
-               call rdSetRdyAL_F  # Ready?
+               call rdSetRdyCL_F  # Ready?
                if nz  # Yes
                   ld (At) (E)  # Set to fd
                   ld Z (E CDR)  # Run body
@@ -2983,13 +2989,11 @@
       end
    while nz  # Milliseconds non-zero
       ld (L -III) A  # Set timeout
-      ld A (L -I)  # File descriptor
-      null A  # Positive?
+      ld C (L -I)  # File descriptor
+      null C  # Positive?
    while ns  # Yes
-      call rdSetRdyAL_F  # Ready?
-   while z  # No
-      lea S (L -V)  # Drop 'poll' structures
-   loop
+      call rdSetRdyCL_F  # Ready?
+   until nz  # Yes
    ld (At) (L II)  # Restore '@'
    ld A (L -II)  # Return milliseconds
    drop
@@ -3136,6 +3140,16 @@
    pop X
    ret
 
+(code 'fdSetC_Y 0)
+   ld Y (C)  # Get fd
+   and Y 7  # Shift count
+   ld B 1  # Bit mask
+   shl B Y  # Shift it
+   ld Y (C)  # Get fd again
+   shr Y 3  # Offset
+   add Y S  # Pointer to byte minus I
+   ret
+
 # (poll 'cnt) -> cnt | NIL
 (code 'doPoll 2)
    push X
@@ -3151,18 +3165,26 @@
    shl C 3  # Vector index
    cmp C (InFDs)  # 'fd' >= 'InFDs'?
    jge badFdErrEX  # Yes
-   call inFilesA_FC  # Readable input file?
+   ld C A  # Readable input file?
+   shl C 3  # Vector index
+   add C (InFiles)  # Get vector
+   ld C (C)  # Slot?
+   null C  # Any?
    ldz E Nil  # No: Return NIL
    if nz
+      push Y
+      sub S (+ II FD_SET)  # <S FD_SET> Timeval, <S> RdSet
       do
          cmp (C I) (C II)  # Data in buffer ('ix' < 'cnt')?
       while z  # No
-         sub S POLLFD  # Create 'poll' structure
-         st4 (S)  # Store 'fd'
-         ld A POLLIN  # Poll input
-         st2 (S POLL_EVENTS)  # Store 'events'
+         ld B 0  # Zero fd set and timeval
+         mset (S) (+ II FD_SET)
+         call fdSetC_Y
+         or (Y I) B  # FD_SET in RdSet
+         ld Y (C)  # fd + 1
+         inc Y
          do
-            cc poll(S 1 0)  # Check
+            cc select(Y S 0 &(S FD_SET))  # Check
             nul4  # OK?
          while s  # No
             call errno_A
@@ -3172,13 +3194,14 @@
                jmp selectErrX
             end
          loop
-         ld2 (S POLL_REVENTS)  # 'revents'
-         add S POLLFD  # Drop 'poll' structure
-         test A (| POLLIN POLLHUP)  # Ready?
+         call fdSetC_Y
+         test (Y I) B  # FD_SET in RdSet
          ldz E Nil  # No: Return NIL
       while nz
          call slowNbC_FA  # Try non-blocking read
       until ge
+      add S (+ II FD_SET)
+      pop Y
    end
    pop X
    ret
diff --git a/src64/sys/linux.defs.l b/src64/sys/linux.defs.l
@@ -1,4 +1,4 @@
-# 05sep10abu
+# 17sep10abu
 # (c) Software Lab. Alexander Burger
 
 # errno
@@ -105,15 +105,8 @@
 (equ WNOHANG 1)
 (equ WUNTRACED 2)
 
-# poll
-(equ POLLFD 8)  # Should be multiple of 8
-(equ POLLFD_SH 3)  # Shift size (log2 POLLFD)
-(equ POLL_EVENTS 4)  # 2
-(equ POLL_REVENTS 6)  # 2
-(equ POLLIN 1)
-(equ POLLOUT 4)
-(equ POLLHUP 16)
-(equ POLLNVAL 32)
+# select
+(equ FD_SET 128)  # 1024 bit
 
 # time
 (equ TM_SEC 0)
diff --git a/src64/version.l b/src64/version.l
@@ -1,6 +1,6 @@
-# 14sep10abu
+# 17sep10abu
 # (c) Software Lab. Alexander Burger
 
-(de *Version 3 0 3 21)
+(de *Version 3 0 3 22)
 
 # vi:et:ts=3:sw=3