|
From: <mat...@us...> - 2014-04-07 04:05:51
|
Revision: 543
http://sourceforge.net/p/cgreen/code/543
Author: matt_hargett
Date: 2014-04-07 04:05:43 +0000 (Mon, 07 Apr 2014)
Log Message:
-----------
apply patch 27 from the tracker with minor changes. thanks to Steven Lang.
Modified Paths:
--------------
trunk/cgreen/src/posix_cgreen_pipe.c
trunk/cgreen/tests/messaging_tests.c
Modified: trunk/cgreen/src/posix_cgreen_pipe.c
===================================================================
--- trunk/cgreen/src/posix_cgreen_pipe.c 2014-04-07 02:30:25 UTC (rev 542)
+++ trunk/cgreen/src/posix_cgreen_pipe.c 2014-04-07 04:05:43 UTC (rev 543)
@@ -1,7 +1,9 @@
#include "cgreen/internal/cgreen_pipe.h"
+#include <errno.h>
#include <fcntl.h>
+#include <signal.h>
+#include <stdio.h>
#include <unistd.h>
-#include <stdio.h>
#ifndef O_ASYNC
# define O_ASYNC FASYNC
@@ -17,7 +19,22 @@
int cgreen_pipe_open(int pipes[2])
{
- return pipe(pipes);
+ int pipe_open_result;
+ int pipe_nonblock_result;
+
+ pipe_open_result = pipe(pipes);
+
+ if (pipe_open_result != 0) {
+ return pipe_open_result;
+ }
+
+ pipe_nonblock_result = fcntl(pipes[1], F_SETFL, O_NONBLOCK);
+
+ if (pipe_nonblock_result != 0) {
+ return pipe_open_result;
+ }
+
+ return 0;
}
void cgreen_pipe_close(int p)
@@ -32,11 +49,22 @@
return -1;
}
- return read(p,buf,count);
+ return read(p, buf, count);
}
ssize_t cgreen_pipe_write(int p, const void *buf, size_t count)
{
+ int pipe_write_result = write(p, buf, count);
+ if (pipe_write_result < 0) {
+ if (errno == EWOULDBLOCK) {
+ fprintf(stderr, "\tToo many assertions (> 8192) within a single test.\n");
+ } else if (errno != EPIPE) {
+ fprintf(stderr, "\tError reporting from test case process to reporter\n");
+ }
+
+ kill(getpid(), SIGPIPE);
+ }
+
return write(p,buf,count);
}
Modified: trunk/cgreen/tests/messaging_tests.c
===================================================================
--- trunk/cgreen/tests/messaging_tests.c 2014-04-07 02:30:25 UTC (rev 542)
+++ trunk/cgreen/tests/messaging_tests.c 2014-04-07 04:05:43 UTC (rev 543)
@@ -29,9 +29,22 @@
assert_equal(receive_cgreen_message(messaging), 99);
}
+Ensure(failure_reported_when_messaging_would_block) {
+ int messaging = start_cgreen_messaging(33);
+ int loop;
+ for (loop = 0; loop < 65536; loop++) {
+ send_cgreen_message(messaging, 99);
+ }
+
+ fail_test("This test should be killed due to too many messages before it gets here");
+}
+
TestSuite *messaging_tests() {
TestSuite *suite = create_test_suite();
add_suite(suite, highly_nested_test_suite());
add_test(suite, can_send_message);
+#ifndef WIN32 // TODO: win32 needs non-blocking pipes like posix for this to pass
+ add_test(suite, failure_reported_when_messaging_would_block);
+#endif
return suite;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|