• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/ucode/tests/custom/06_lib_uloop/07_handle_closed_fd

  1 Deleting a handle whose descriptor the script already closed must not
  2 unregister another handle that now uses the same descriptor number.
  3 
  4 -- Testcase --
  5 {%
  6         import * as uloop from 'uloop';
  7         import * as fs from 'fs';
  8 
  9         uloop.init();
 10 
 11         let old_fds = fs.pipe();
 12         let old_handle = uloop.handle(old_fds[0], () => null, uloop.ULOOP_READ);
 13         let old_fileno = old_handle.fileno();
 14 
 15         old_fds[0].close();
 16         old_fds[1].close();
 17 
 18         let fds = fs.pipe();
 19         let events = 0;
 20 
 21         uloop.handle(fds[0], function(flags) {
 22                 events++;
 23                 fds[0].read(1);
 24                 uloop.end();
 25         }, uloop.ULOOP_READ);
 26 
 27         printf("reused: %s\n", fds[0].fileno() == old_fileno);
 28         printf("delete: %s\n", old_handle.delete());
 29 
 30         fds[1].write('x');
 31         fds[1].flush();
 32 
 33         uloop.timer(200, () => uloop.end());
 34         uloop.run();
 35 
 36         printf("events: %d\n", events);
 37 
 38         uloop.done();
 39 %}
 40 -- End --
 41 
 42 -- Expect stdout --
 43 reused: true
 44 delete: true
 45 events: 1
 46 -- End --
 47 
 48 
 49 If another descriptor keeps the file open after the script closed its own,
 50 the file stays in epoll. Deleting or dropping the handle, or an error on the
 51 file, must not leave the event loop with a pointer to a freed handle.
 52 
 53 -- Testcase --
 54 {%
 55         import * as uloop from 'uloop';
 56         import * as fs from 'fs';
 57 
 58         uloop.init();
 59 
 60         function run(msecs) {
 61                 uloop.timer(msecs, () => uloop.end());
 62                 uloop.run();
 63         }
 64 
 65         let fds = fs.pipe();
 66         let events = 0;
 67         let handle = uloop.handle(fds[0], () => events++, uloop.ULOOP_READ);
 68 
 69         fs.dup2(fds[0].fileno(), 100);
 70         fds[0].close();
 71 
 72         printf("delete: %s\n", handle.delete());
 73         handle = null;
 74         gc();
 75 
 76         fds[1].write('x');
 77         fds[1].flush();
 78         run(20);
 79 
 80         fds = fs.pipe();
 81         handle = uloop.handle(fds[0], () => events++, uloop.ULOOP_READ);
 82 
 83         fs.dup2(fds[0].fileno(), 101);
 84         fds[0].close();
 85         fds[1].close();
 86         run(20);
 87 
 88         handle = null;
 89         gc();
 90         run(20);
 91 
 92         printf("events: %d\n", events);
 93 
 94         fs.fdopen(100).close();
 95         fs.fdopen(101).close();
 96 
 97         uloop.done();
 98 %}
 99 -- End --
100 
101 -- Expect stdout --
102 delete: true
103 events: 1
104 -- End --
105 
106 -- Platform --
107 Linux
108 -- End --

This page was automatically generated by LXR 0.3.1.  •  OpenWrt