Added two small select() test programs. select_check select()s

stdin/out/err according the what was specified via arguments.
select_close_test select()s a file descriptor that is closed a little
later by another thread.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22390 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2007-10-01 00:39:38 +00:00
parent 242eff3d7b
commit f5ede4ec02
3 changed files with 95 additions and 2 deletions
+5 -2
View File
@@ -29,17 +29,20 @@ SimpleTest port_wakeup_test_7 : port_wakeup_test_7.cpp ;
SimpleTest port_wakeup_test_8 : port_wakeup_test_8.cpp ;
SimpleTest port_wakeup_test_9 : port_wakeup_test_9.cpp ;
SimpleTest select_check : select_check.cpp ;
SimpleTest select_close_test : select_close_test.cpp ;
SimpleTest syscall_time : syscall_time.cpp ;
SimpleTest transfer_area_test : transfer_area_test.cpp ;
SimpleTest yield_test : yield_test.cpp ;
SimpleTest wait_test_1 : wait_test_1.c ;
SimpleTest wait_test_2 : wait_test_2.cpp ;
SimpleTest wait_test_3 : wait_test_3.cpp ;
SimpleTest wait_test_4 : wait_test_4.cpp ;
SimpleTest yield_test : yield_test.cpp ;
SetSupportedPlatformsForTarget sigint_bug113_test
: $(HAIKU_BEOS_COMPATIBLE_PLATFORMS) ;
SimpleTest sigint_bug113_test : sigint_bug113_test.cpp ;
+46
View File
@@ -0,0 +1,46 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/select.h>
#include <unistd.h>
int
main(int argc, const char* const* argv)
{
const char* config[] = {
argc >= 2 ? argv[1] : "rwe",
argc >= 3 ? argv[2] : "rwe",
argc >= 4 ? argv[3] : "rwe"
};
fd_set readSet;
fd_set writeSet;
fd_set errorSet;
FD_ZERO(&readSet);
FD_ZERO(&writeSet);
FD_ZERO(&errorSet);
for (int fd = 0; fd < 3; fd++) {
if (strchr(config[fd], 'r'))
FD_SET(fd, &readSet);
if (strchr(config[fd], 'w'))
FD_SET(fd, &writeSet);
if (strchr(config[fd], 'e'))
FD_SET(fd, &errorSet);
}
int result = select(3, &readSet, &writeSet, &errorSet, NULL);
fprintf(stderr, "select(): %d\n", result);
for (int fd = 0; fd < 3; fd++) {
fprintf(stderr, "fd %d: %s%s%s\n", fd,
FD_ISSET(fd, &readSet) ? "r" : " ",
FD_ISSET(fd, &writeSet) ? "w" : " ",
FD_ISSET(fd, &errorSet) ? "e" : " ");
}
return 0;
}
@@ -0,0 +1,44 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/select.h>
#include <unistd.h>
#include <OS.h>
static status_t
close_fd(void* data)
{
int fd = int(data);
snooze(1000000);
close(fd);
fprintf(stderr, "fd %d closed\n", fd);
return B_OK;
}
int
main()
{
int fd = dup(0);
thread_id thread = spawn_thread(close_fd, "close fd", B_NORMAL_PRIORITY,
(void*)fd);
resume_thread(thread);
fd_set readSet;
FD_ZERO(&readSet);
FD_SET(0, &readSet);
FD_SET(fd, &readSet);
fprintf(stderr, "select({0, %d}, NULL, NULL, NULL) ...\n", fd);
int result = select(fd + 1, &readSet, NULL, NULL, NULL);
fprintf(stderr, "select(): %d\n", result);
fprintf(stderr, "fd %d: %s\n", 0, FD_ISSET(0, &readSet) ? "r" : " ");
fprintf(stderr, "fd %d: %s\n", fd, FD_ISSET(fd, &readSet) ? "r" : " ");
return 0;
}