From owner-freebsd-hackers@FreeBSD.ORG Tue Apr 3 12:37:01 2007 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 7219016A402 for ; Tue, 3 Apr 2007 12:37:01 +0000 (UTC) (envelope-from jcarroll@gmail.com) Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.245]) by mx1.freebsd.org (Postfix) with ESMTP id 34AAB13C480 for ; Tue, 3 Apr 2007 12:37:01 +0000 (UTC) (envelope-from jcarroll@gmail.com) Received: by an-out-0708.google.com with SMTP id c24so1658726ana for ; Tue, 03 Apr 2007 05:37:00 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:reply-to:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=rkVdY5+50UH8C6u/4sW9ICoE30ljFW4NivzLpZKv3d8lb9a9CFmRksXCUeYN8jThGCuyQDVTFmP0rcM/wTaux3RyosY78sNbNyj+cVisYCAszFedhIHgJ/Hooaq9CeSdgNXHE7qN/AhRihecEvX2exnMvlpblobPxq6ohg7embQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=CDI6PiLgzg0bLLXoiuPR25PCkBciWZcIp15c7nRkxVIQyq6RAHevLwUN8UltnSpDHq5cyDMpWiP7obxeDPZEUBNuTPoiO/mK1g+3i1KLhYU4BUeiFXAuRrL96y3DKB8hpYPJ3AkRj4GZIjahVQXhVtsS97CMweN4obIdBpPpeg0= Received: by 10.100.140.6 with SMTP id n6mr4270589and.1175602255915; Tue, 03 Apr 2007 05:10:55 -0700 (PDT) Received: by 10.100.13.5 with HTTP; Tue, 3 Apr 2007 05:10:55 -0700 (PDT) Message-ID: Date: Tue, 3 Apr 2007 08:10:55 -0400 From: "Jason Carroll" To: freebsd-hackers@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Subject: kevent and unix dgram socket problem X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: jason@hudson-trading.com List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Apr 2007 12:37:01 -0000 Hi everyone-- I'm working on an application that is attempting to use kqueues to detect data arriving at a unix domain datagram socket, but kevents don't appear to get delivered when a datagram arrives. Using poll() for the same purpose appears to work fine. Also, if I switch the socket to the AF_INET domain, I see the correct behavior with kevent(). I distilled the problem into two files that I included. listen.cc creates a unix socket and blocks for data on a kevent() call. write.cc sends a brief message to the same unix socket. I've seen the problem on 6-STABLE and 4.5-RELEASE. Anyone have any thoughts or comments? Thanks, Jason // ================ listen.cc ================= #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define LISTENQ 2 #define UN_PATH_LEN sizeof(((struct sockaddr_un*)0)->sun_path) int main(int argc, char *argv[]) { // new socket int fd = socket(AF_LOCAL, SOCK_DGRAM, 0); assert(fd >= 0); // make sure there isn't something in it's way unlink("usock"); // create the local address, bind & listen struct sockaddr_un addr; memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_LOCAL; strncpy(addr.sun_path, "usock", UN_PATH_LEN - 1); assert(bind(fd, (sockaddr*) &addr, sizeof(sockaddr_un)) == 0); assert(listen(fd, LISTENQ) == 0); char buf[1024]; int nread; // uncomment this line to prove my socket is set up correctly // nread = read(fd, buf, sizeof(buf)); // printf("read %d bytes\n", nread); int kqueueFD; kqueueFD = kqueue(); struct kevent event; EV_SET(&event, fd, EVFILT_READ, EV_ADD, 0, 0, 0); assert(kevent(kqueueFD, &event, 1, 0, 0, 0) == 0); struct pollfd pfd; pfd.fd = fd; pfd.events = POLLIN; pfd.revents = 0; int r; // uncomment the following two lines to see poll behavior // while ((r = poll(&pfd, 1, INFTIM)) >= 0) { // printf("poll returned %d\n", r); // uncomment the following two lines to see kqueue behavior while ((r = kevent(kqueueFD, 0, 0, &event, 1, 0)) >= 0) { printf("kevent returned %d\n", r); nread = read(fd, buf, sizeof(buf)); printf("read %d bytes\n", nread); } } // ================ write.cc ================= #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define LISTENQ 2 #define UN_PATH_LEN sizeof(((struct sockaddr_un*)0)->sun_path) int main(int argc, char *argv[]) { int fd = socket(AF_LOCAL, SOCK_DGRAM, 0); assert(fd >= 0); // create the local address & "connect" struct sockaddr_un addr; memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_LOCAL; strncpy(addr.sun_path, "usock", UN_PATH_LEN - 1); assert(connect(fd, (sockaddr*) &addr, sizeof(sockaddr_un)) == 0); const char *msg = "this is the message\n"; write(fd, msg, strlen(msg)); }