diff options
author | David Leonard <d@cvs.openbsd.org> | 1998-09-03 11:04:48 +0000 |
---|---|---|
committer | David Leonard <d@cvs.openbsd.org> | 1998-09-03 11:04:48 +0000 |
commit | 19238dc05c5b501a685537b1fcb0b54f9d8bdf5a (patch) | |
tree | eae5c85762af12da5994ab4524ee73f6d6ba678e /lib/libc_r/TEST/test_sock_2a.c | |
parent | 542ab5713f06e4f89b3d17d7a1458a4214fa1bb9 (diff) |
libpthread tests modified for uthreads
Diffstat (limited to 'lib/libc_r/TEST/test_sock_2a.c')
-rw-r--r-- | lib/libc_r/TEST/test_sock_2a.c | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/lib/libc_r/TEST/test_sock_2a.c b/lib/libc_r/TEST/test_sock_2a.c new file mode 100644 index 00000000000..7ff73bcfc76 --- /dev/null +++ b/lib/libc_r/TEST/test_sock_2a.c @@ -0,0 +1,87 @@ +/* ==== test_sock_1.c ========================================================= + * Copyright (c) 1993 by Chris Provenzano, proven@athena.mit.edu + * + * Description : Test pthread_create() and pthread_exit() calls. + * + * 1.00 93/08/03 proven + * -Started coding this file. + */ + +#include <pthread.h> +#include <errno.h> +#include <stdio.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> + +struct sockaddr_in a_sout; + +#define MESSAGE5 "This should be message #5" +#define MESSAGE6 "This should be message #6" + +void * sock_connect(void* arg) +{ + char buf[1024]; + int fd, tmp; + short port; + + port = 3276; + a_sout.sin_family = AF_INET; + a_sout.sin_port = htons(port); + a_sout.sin_addr.s_addr = htonl(0x7f000001); /* loopback */ + + if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { + perror("Error: sock_connect:socket()"); + exit(1); + } + + printf("This should be message #2\n"); + if (connect(fd, (struct sockaddr *) &a_sout, sizeof(a_sout)) < 0) { + perror("Error: sock_connect:connect()"); + exit(1); + } + close(fd); + + if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { + perror("Error: sock_connect:socket()"); + exit(1); + } + + printf("This should be message #3\n"); + + if (connect(fd, (struct sockaddr *) &a_sout, sizeof(a_sout)) < 0) { + perror("Error: sock_connect:connect()"); + exit(1); + } + + /* Ensure sock_read runs again */ + + if ((tmp = read(fd, buf, 1024)) <= 0) { + printf("Error: sock_connect:read() == %d %s\n", tmp, strerror(errno)); + exit(1); + } + write(fd, MESSAGE6, sizeof(MESSAGE6)); + printf("%s\n", buf); + close(fd); +} + +main(int argc, char **argv) +{ + pthread_t thread; + int i; + + if (argv[1] && (!strcmp(argv[1], "fork okay"))) { + sleep(1); + setbuf(stdout, NULL); + setbuf(stderr, NULL); + + if (pthread_create(&thread, NULL, sock_connect, (void *)0xdeadbeaf)) { + perror("Error: main:pthread_create(sock_connect)"); + exit(1); + } + pthread_exit(NULL); + } + printf("test_sock_2a needs to be execed from test_sock_2.\n"); + printf("It is not a stand alone test.\n"); + exit(1); +} |