From owner-freebsd-hackers@freebsd.org Fri Dec 28 01:14:32 2018 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5C9131429D72 for ; Fri, 28 Dec 2018 01:14:32 +0000 (UTC) (envelope-from wjw@digiware.nl) Received: from smtp.digiware.nl (smtp.digiware.nl [176.74.240.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 348BD6D04A for ; Fri, 28 Dec 2018 01:14:30 +0000 (UTC) (envelope-from wjw@digiware.nl) Received: from router.digiware.nl (localhost.digiware.nl [127.0.0.1]) by smtp.digiware.nl (Postfix) with ESMTP id B52A5AEF1C; Fri, 28 Dec 2018 02:14:28 +0100 (CET) X-Virus-Scanned: amavisd-new at digiware.com Received: from smtp.digiware.nl ([127.0.0.1]) by router.digiware.nl (router.digiware.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ZG33nXwRMOuC; Fri, 28 Dec 2018 02:14:27 +0100 (CET) Received: from [192.168.11.152] (unknown [192.168.11.152]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.digiware.nl (Postfix) with ESMTPSA id B536BAEF12 for ; Fri, 28 Dec 2018 02:14:27 +0100 (CET) To: FreeBSD Hackers From: Willem Jan Withagen Subject: Using kqueue with aio_read/write Message-ID: <8753521a-4555-ec2a-5efc-dee2660b4d9b@digiware.nl> Date: Fri, 28 Dec 2018 02:14:28 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: nl X-Rspamd-Queue-Id: 348BD6D04A X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; spf=pass (mx1.freebsd.org: domain of wjw@digiware.nl designates 176.74.240.9 as permitted sender) smtp.mailfrom=wjw@digiware.nl X-Spamd-Result: default: False [-3.94 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; FROM_HAS_DN(0.00)[]; R_SPF_ALLOW(-0.20)[+mx]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-hackers@freebsd.org]; DMARC_NA(0.00)[digiware.nl]; RCPT_COUNT_ONE(0.00)[1]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; RCVD_COUNT_THREE(0.00)[4]; RCVD_TLS_LAST(0.00)[]; TO_DN_ALL(0.00)[]; RCVD_IN_DNSWL_MED(-0.20)[9.240.74.176.list.dnswl.org : 127.0.9.2]; MX_GOOD(-0.01)[cached: smtp.digiware.nl]; NEURAL_HAM_SHORT(-0.76)[-0.760,0]; IP_SCORE(-0.67)[asn: 28878(-3.39), country: NL(0.02)]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:28878, ipnet:176.74.224.0/19, country:NL]; MID_RHS_MATCH_FROM(0.00)[] X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Dec 2018 01:14:32 -0000 Hi, Im trying to understand why I cannot get so code to work. This is the smallest extract I can make to show my problem. I would expect the kevent() call to return every timeo tick. Even if I tell it NOT to time-out I get these spurts of errors Since there is nothing to trigger the AIO-event, I would expect kqueue to hold indefinitly. But it does not generate anything other than errors And instead it repeatedly complains that there is a permission error:   get_events_kevent: EV_Error(1) kevent(): Operation not permitted But I'm not getting where that would the case... Surely a pilot error, but I do overlook it al the time. So suggestions are welcome. Thanx, --WjW #include #include #include #include #include #include #include #include #include #define BUFFER_SIZE     512 #define MAX_EVENTS 32 #define FILENAME "/tmp/aio_test" char filename[256]; int fd; int done = 0; void get_events_kevent(int fd, int kq) {     printf("get_events function fd = %d, kq = %d\n", fd, kq);     int i = 0, errcnt = 0, err, ret, reterr, rev;     int search = 1;     int timeout_ms = 10;     struct timespec timeo = {         timeout_ms / 1000,         (timeout_ms % 1000) * 1000 * 1000     };     struct kevent filter[16];     struct kevent changed[16];     EV_SET(&filter[0], fd, EVFILT_AIO,             EV_ADD,             0, 0, 0 );     while (!done) {         printf("+");         rev = kevent(kq, filter, 1, changed, 16, 0); //&timeo);         if (rev < 0) {             perror("kevent error");         } else if (rev == 0) {             printf("T");         } else {             printf("rev(%d)\n", rev);             if (changed[0].flags == EV_ERROR) {                 errno = changed[0].data;                 printf( "%s: EV_Error(%d) kevent(): %s\n", __func__, errno,                     strerror(errno));                 memset(&changed[0], 0, sizeof(struct kevent));             } else {                 err = aio_error((struct aiocb*)changed[0].udata);                 ret = aio_return((struct aiocb*)changed[0].udata);                 if (ret < 0 )                     reterr = errno;                 if (err != 0) {                     printf( "%s: slot: %d, Error(%d) at aio_error(): %s\n", __func__, i, err, strerror (err));                     errcnt++;                     if (errcnt > 50) {                         exit(3);                     }                 }             }         }     } } int main() {     (void) strcpy(filename, FILENAME);     unlink(filename);     fd = open(filename, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);     if (fd == -1) {         printf( "%s: Error at open(): %s\n", __func__, strerror(errno));         exit(1);     }     int kq = kqueue();     if (fd == -1) {         printf( "%s: Error at kqueue(): %s\n", __func__, strerror(errno));         exit(1);     }     get_events_kevent( fd, kq);     close(kq);     close(fd);     return 0; }