/* * Copyright 2009 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /* Helper to test linux pipe's */ #include #include #include #include #include #include #include static void print_events(int events) { if (events & POLLIN) printf("POLLIN "); if (events & POLLPRI) printf("POLLPRI "); if (events & POLLOUT) printf("POLLOUT "); if (events & POLLERR) printf("POLLERR "); if (events & POLLHUP) printf("POLLHUP "); if (events & POLLNVAL) printf("POLLNVAL "); printf("\n"); } static int _socketpair(int fd[2]) { int ret; printf("%d: socketpair()\n", gettid()); ret = socketpair(AF_UNIX, SOCK_STREAM, 0, fd); printf("%d: socketpair() = %d\n", gettid(), ret); if (ret) printf("\terr %d (%s)\n", errno, strerror(errno)); return ret; } static int _close(int fd) { int ret; printf("%d: close(%d)\n", gettid(), fd); ret = close(fd); printf("%d: close(%d) = %d\n", gettid(), fd, ret); if (ret) printf("\terr %d (%s)\n", errno, strerror(errno)); return ret; } static int _poll(struct pollfd *ufds, nfds_t nfds, int timeout) { int ret; unsigned int i; printf("%d: poll()\n", gettid()); ret = poll(ufds, nfds, timeout); printf("%d: poll() = %d\n", gettid(), ret); if (ret < 0) printf("\terr %d (%s)\n", errno, strerror(errno)); if (ret > 0) { for (i=0; i