test-eintr-handling.c
Go to the documentation of this file.
1 /* Copyright libuv project contributors. All rights reserved.
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to
5  * deal in the Software without restriction, including without limitation the
6  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7  * sell copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19  * IN THE SOFTWARE.
20  */
21 
22 #include "uv.h"
23 #include "task.h"
24 
25 #ifdef _WIN32
26 
27 TEST_IMPL(eintr_handling) {
28  RETURN_SKIP("Test not implemented on Windows.");
29 }
30 
31 #else /* !_WIN32 */
32 
33 #include <string.h>
34 #include <unistd.h>
35 
36 static uv_loop_t* loop;
38 static uv_buf_t iov;
39 
40 static char buf[32];
41 static char test_buf[] = "test-buffer\n";
42 int pipe_fds[2];
43 
44 struct thread_ctx {
46  int fd;
47 };
48 
49 static void thread_main(void* arg) {
50  int nwritten;
51  ASSERT(0 == kill(getpid(), SIGUSR1));
52 
53  do
54  nwritten = write(pipe_fds[1], test_buf, sizeof(test_buf));
55  while (nwritten == -1 && errno == EINTR);
56 
57  ASSERT(nwritten == sizeof(test_buf));
58 }
59 
60 static void sig_func(uv_signal_t* handle, int signum) {
62 }
63 
64 TEST_IMPL(eintr_handling) {
65  struct thread_ctx ctx;
68  int nread;
69 
70  iov = uv_buf_init(buf, sizeof(buf));
72 
74  ASSERT(0 == uv_signal_start(&signal, sig_func, SIGUSR1));
75 
76  ASSERT(0 == pipe(pipe_fds));
78 
79  nread = uv_fs_read(loop, &read_req, pipe_fds[0], &iov, 1, -1, NULL);
80 
81  ASSERT(nread == sizeof(test_buf));
82  ASSERT(0 == strcmp(buf, test_buf));
83 
85 
86  ASSERT(0 == close(pipe_fds[0]));
87  ASSERT(0 == close(pipe_fds[1]));
88  uv_close((uv_handle_t*) &signal, NULL);
89 
91  return 0;
92 }
93 
94 #endif /* !_WIN32 */
task.h
ctx
Definition: benchmark-async.c:30
test_buf
static char test_buf[]
Definition: test-eintr-handling.c:41
write
#define write
Definition: test-fs.c:47
uv_signal_init
UV_EXTERN int uv_signal_init(uv_loop_t *loop, uv_signal_t *handle)
Definition: unix/signal.c:317
string.h
buf
voidpf void * buf
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
ASSERT
#define ASSERT(expr)
Definition: task.h:102
thread_main
static void thread_main(void *arg)
Definition: test-eintr-handling.c:49
uv_run
UV_EXTERN int uv_run(uv_loop_t *, uv_run_mode mode)
Definition: unix/core.c:361
uv_fs_s
Definition: uv.h:1294
uv_close
UV_EXTERN void uv_close(uv_handle_t *handle, uv_close_cb close_cb)
Definition: unix/core.c:112
uv_default_loop
UV_EXTERN uv_loop_t * uv_default_loop(void)
Definition: uv-common.c:733
sig_func
static void sig_func(uv_signal_t *handle, int signum)
Definition: test-eintr-handling.c:60
signal
static void signal(notification *n)
Definition: alts_tsi_handshaker_test.cc:107
UV_RUN_DEFAULT
@ UV_RUN_DEFAULT
Definition: uv.h:254
pipe_fds
int pipe_fds[2]
Definition: test-eintr-handling.c:42
arg
Definition: cmdline.cc:40
close
#define close
Definition: test-fs.c:48
uv_thread_create
UV_EXTERN int uv_thread_create(uv_thread_t *tid, uv_thread_cb entry, void *arg)
Definition: libuv/src/unix/thread.c:209
uv_signal_stop
UV_EXTERN int uv_signal_stop(uv_signal_t *handle)
Definition: unix/signal.c:511
thread_ctx
Definition: libuv/src/win/thread.c:90
uv_fs_read
UV_EXTERN int uv_fs_read(uv_loop_t *loop, uv_fs_t *req, uv_file file, const uv_buf_t bufs[], unsigned int nbufs, int64_t offset, uv_fs_cb cb)
Definition: unix/fs.c:1826
uv.h
MAKE_VALGRIND_HAPPY
#define MAKE_VALGRIND_HAPPY()
Definition: task.h:229
uv_barrier_t
Definition: unix.h:154
uv_signal_s
Definition: uv.h:1561
uv_buf_t
Definition: unix.h:121
loop
static uv_loop_t * loop
Definition: test-eintr-handling.c:36
uv_buf_init
UV_EXTERN uv_buf_t uv_buf_init(char *base, unsigned int len)
Definition: uv-common.c:157
iov
static uv_buf_t iov
Definition: test-eintr-handling.c:38
read_req
static uv_fs_t read_req
Definition: test-eintr-handling.c:37
thread_ctx::barrier
uv_barrier_t barrier
Definition: test-eintr-handling.c:45
thread_ctx::fd
int fd
Definition: test-eintr-handling.c:46
RETURN_SKIP
#define RETURN_SKIP(explanation)
Definition: task.h:262
handle
static csh handle
Definition: test_arm_regression.c:16
uv_handle_s
Definition: uv.h:441
uv_thread_t
pthread_t uv_thread_t
Definition: unix.h:134
uv_loop_s
Definition: uv.h:1767
thread
static uv_thread_t thread
Definition: test-async-null-cb.c:29
TEST_IMPL
TEST_IMPL(eintr_handling)
Definition: test-eintr-handling.c:64
uv_signal_start
UV_EXTERN int uv_signal_start(uv_signal_t *handle, uv_signal_cb signal_cb, int signum)
Definition: unix/signal.c:338


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:26