[utils unit-tests] check more details for send/recv fd

personal/stbuehler/wip
Stefan Bühler 13 years ago
parent 77ad4a63d4
commit e3aad8f950

@ -339,10 +339,10 @@ static void angel_connection_io_cb(struct ev_loop *loop, ev_io *w, int revents)
send_item->value.fds.pos++;
continue;
case -1: /* Fatal error, connection has to be closed */
li_ev_safe_ref_and_stop(ev_async_stop, loop, &acon->out_notify_watcher);
li_ev_safe_ref_and_stop(ev_io_stop, loop, &acon->fd_watcher);
acon->close_cb(acon, NULL); /* TODO: set err */
return;
li_ev_safe_ref_and_stop(ev_async_stop, loop, &acon->out_notify_watcher);
li_ev_safe_ref_and_stop(ev_io_stop, loop, &acon->fd_watcher);
acon->close_cb(acon, NULL); /* TODO: set err */
return;
case -2: goto write_eagain;
}
}

@ -3,11 +3,13 @@
#define perror(msg) g_error("(%s:%i) %s failed: %s", __FILE__, __LINE__, msg, g_strerror(errno))
#if 0
static liChunkQueue* cq_from_str(const gchar *s, size_t len) {
liChunkQueue *cq = li_chunkqueue_new();
li_chunkqueue_append_mem(cq, s, len);
return cq;
}
#endif
static void cq_load_str(liChunkQueue *cq, const gchar *s, size_t len) {
li_chunkqueue_reset(cq);

@ -5,7 +5,7 @@
static void test_send_fd(void) {
int pipefds[2], sockfd[2], rfd = -1;
char buf[6];
char buf[5];
if (-1 == pipe(pipefds)) {
perror("pipe");
@ -15,26 +15,47 @@ static void test_send_fd(void) {
perror("socketpair");
}
/* try sending fd */
if (-1 == li_send_fd(sockfd[0], pipefds[0])) {
perror("li_send_fd");
}
/* check whether we still can send normal data after fd */
write(sockfd[0], CONST_STR_LEN("abcx"));
/* make sure we can close the fd before the other end received it */
close(pipefds[0]);
/* check receiving fd */
if (-1 == li_receive_fd(sockfd[1], &rfd)) {
perror("li_receive_fd");
}
write(pipefds[1], CONST_STR_LEN("test\0"));
/* check whether we still can receive normal data after fd */
buf[0] = '\0';
if (-1 == read(sockfd[1], buf, 5)) {
perror("read");
}
buf[4] = '\0';
g_test_message("received on socket: %s", buf);
g_assert_cmpstr(buf, ==, "abcx");
/* check whether pipe still works after receiving end was passed */
write(pipefds[1], CONST_STR_LEN("test"));
buf[0] = '\0';
if (-1 == read(rfd, buf, 5)) {
perror("read");
}
buf[4] = '\0';
buf[5] = '\0';
g_test_message("received: %s", buf);
g_test_message("received on pipe: %s", buf);
g_assert_cmpstr(buf, ==, "test");
close(pipefds[0]); close(pipefds[1]);
close(pipefds[1]);
close(sockfd[0]); close(sockfd[1]);
close(rfd);
}

Loading…
Cancel
Save