1 module during.tests.poll; 2 3 import during; 4 import during.tests.base; 5 6 import core.sys.linux.errno; 7 import core.sys.linux.sys.eventfd; 8 import core.sys.posix.unistd; 9 10 import std.algorithm : among; 11 12 @("poll add/remove") 13 unittest 14 { 15 Uring io; 16 long res = io.setup(); 17 assert(res >= 0, "Error initializing IO"); 18 19 auto evt = eventfd(0, EFD_NONBLOCK); 20 assert(evt != -1, "eventfd()"); 21 22 res = io 23 .putWith!((ref SubmissionEntry e, ref const(int) evt) 24 { 25 e.prepPollAdd(evt, PollEvents.IN); 26 e.setUserData(evt); // to identify poll operation later 27 })(evt) 28 .submit(0); 29 assert(res == 1); 30 31 ulong val = 1; 32 res = write(evt, cast(ubyte*)&val, 8); 33 assert(res == 8); 34 io.wait(1); 35 36 assert(!io.empty); 37 assert(io.front.res == 1); // one event available from poll() 38 io.popFront(); 39 40 res = read(evt, cast(ubyte*)&val, 8); 41 assert(res == 8); 42 43 // try to remove it - should fail with ENOENT as we've consumed it already 44 res = io.putWith!((ref SubmissionEntry e, ref const(int) evt) => e.prepPollRemove(evt))(evt).submit(1); 45 assert(res == 1); 46 assert(io.front.res == -ENOENT); 47 io.popFront(); 48 49 // add it again 50 res = io 51 .putWith!((ref SubmissionEntry e, ref const(int) evt) 52 { 53 e.prepPollAdd(evt, PollEvents.IN); 54 e.setUserData(evt); // to identify poll operation later 55 })(evt) 56 .submit(0); 57 assert(res == 1); 58 59 // and remove/cancel it - now should pass ok 60 res = io.putWith!((ref SubmissionEntry e, ref const(int) evt) => e.prepPollRemove(evt))(evt).submit(1); 61 assert(res == 1); 62 63 io.wait(2); 64 foreach (_; 0..2) 65 { 66 if (io.front.user_data == cast(ulong)cast(void*)&evt) 67 assert(io.front.res == -ECANCELED); 68 else assert(!io.front.res); 69 io.popFront(); 70 } 71 }