]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/test/inet/tst-sock-nonblock.c
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / test / inet / tst-sock-nonblock.c
1 /* vi: set sw=4 ts=4 sts=4: */
2 /*
3  * Nonblocking socket test for uClibc
4  * Copyright (C) 2012 by Kevin Cernekee <cernekee@gmail.com>
5  *
6  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
7  */
8
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <unistd.h>
13 #include <errno.h>
14 #include <error.h>
15 #include <sys/types.h>
16 #include <sys/socket.h>
17 #include <sys/un.h>
18 #include <sys/fcntl.h>
19
20 static int
21 do_test(void)
22 {
23         int fd, ret, result = 0;
24         struct sockaddr_un sa;
25         char buf;
26
27         fd = socket(AF_UNIX, SOCK_DGRAM | SOCK_NONBLOCK, 0);
28         if (fd < 0) {
29                 perror("socket()");
30                 result = 1;
31         }
32
33         memset(&sa, 0, sizeof(sa));
34         sa.sun_family = AF_UNIX;
35         strcpy(sa.sun_path, "socktest");
36         unlink("socktest");
37         if (bind(fd, (const struct sockaddr *)&sa, sizeof(sa)) < 0) {
38                 perror("bind()");
39                 result = 1;
40         }
41
42         ret = read(fd, &buf, sizeof(buf));
43         if (ret != -1 || errno != EAGAIN) {
44                 error(0, 0, "Nonblocking read returned %d", ret);
45                 result = 1;
46         }
47
48         return result;
49 }
50
51 #define TIMEOUT 5
52 #define TEST_FUNCTION do_test ()
53 #include "../test-skeleton.c"