Changes since version 1.19.1: * test: fix incorrect asserts (cjihrig) * test: fix a typo in test-fork.c (Felix Yan) * build: remove long-obsolete gyp workarounds (Ben Noordhuis) * build: split off tests into separate gyp file (Ben Noordhuis) * test: check uv_cond_timedwait more carefully (Jamie Davis) * include,src: introduce UV__ERR() macro (Mason X) * build: add url field to libuv.pc (Ben Noordhuis) * doc: mark IBM i as Tier 3 support (Jesse Gorzinski) * win,build: correct C2059 errors (Michael Fero) * zos: fix timeout for condition variable (jBarz) * win: CREATE_NO_WINDOW when stdio is not inherited (Nick Logan) * build: fix commmon.gypi comment (Ryuichi KAWAMATA) * doc: document uv_timer_start() on an active timer (Vladimír Čunát) * doc: add note about handle movability (Bartosz Sosnowski) * doc: fix syntax error in loop documentation (Bartosz Sosnowski) * osx,stream: retry sending handle on EMSGSIZE error (Santiago Gimeno) * unix: delay fs req register until after validation (cjihrig) * test: add tests for bad inputs (Joyee Cheung) * unix,win: ensure req->bufs is freed (cjihrig) * test: add additional fs memory management checks (cjihrig) -----BEGIN PGP SIGNATURE----- Comment: GPGTools - https://gpgtools.org iQIcBAABCgAGBQJajdXDAAoJEHQ0OQvb6bnF+gkQAIYnk1ujKETakcu/O8M/d+yu gZkLAnqkMYD5X5rTEFkaHrzrQMD85twxme+GgegSFweUDvhqVQWveeNG5zRJ8/ri HsysKioqBsMfzCtJw4W+wDLIL7ltja2vcZooTTyvrIArLd2zQ8sn0nHe/eTq2uKl wMPhup9qxl10THpevdab3AMr1jEJ3KSsFaNUaVLySf6DJJqY4pRV+ekDGQVrkNZU XzH67YN2XWP5dsavAVX0GsnQraX8kNWgYjcDK93D55hj93iyq+38ZYstEhNqIGF9 9StzptoUyqK5KD5tyDYC2WmgwBJd9eAodmjCdq+ZP0td/irxEhQoRAX7aoAjBGzY j3vTb0JXhvvEghivap86mkxPhAQ6rmbGZkG/yOi6eexL/es1GwhGmfzE3NgUexCx nyKVCWqVo4IjL53+jndaX3wE4AIKpo0geah7f82v7cIJJqYN8DtaNN9imwZO3r7p WFUx2ujOYGuFcz1xbFNyLzBH0Rda2JnsvtAstGvWXSoXzCNSEU5PZ6rpn3jcOVU5 mDjQ9z/x3kp25qp014+wxHD+mltZzcL8H8fJfQ9JkGWdYE+R3brzwib07GctdlKP 3/PGH6vbDyiiCEiwfwjhjZpZWyJcaEuGegEc7J80uEm+/yq1/4HrdaFbI20D2heB NIj8XaaPt8Vqsafp0ZWp =Aa+M -----END PGP SIGNATURE----- gpgsig -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEYS8OrZQBYiN530QC8ow8jaM8A74FAlqRjUEACgkQ8ow8jaM8 A77UBw//b71/tAhf1ZOEwouhCjuoy17PNrgfmpQFw8NbaJc6YALe2oQ+1+gc/GPp 9kaPfjDLSlZwYJMVtiTmKaQoqYNj3Y6ZJatZYambZ89/3XCBjd4WbK2IMnpth+xU tLzvjd5RlNMNpyrdrlEXneZi5ql7/QeRLj85k2790LSSajODK8A4VoZZoRmfBL4S rnngc5BFI2MGNOyUcc4HBtAcusvt6KIZWxhiRHLa0vpNmrnUAcXqruxzp36+ct+3 efy+9cx6uzbnqg7dv8WHljre+2we4NaHcH4W2zCkNuf0JrO9reJMjojBb3+NsVIt HBHonkVLvRf8eTv8VFoKQPqeMStVj2FtVRmuKqcZ8l/fZNH/Fz2R2tO2ZaLCrSax TkAiuLi7uOY32oBNNyI6GGwcJAD52ROl+UCBEoRCOpYVx6PWjZnun7zP7bYq+oJt h1qL7avrGfp7vG+ggDxfeEOlWZKeXBN6/uh+KnTFryxMwZ9GFNu46s2EttS2lATg eKvPXTPBF9xKVCxckDph5sBhT420SBt2xa8neeMMdEKXPaDPtyj9kMau6HeU84cO bcnGytFhlhx7qUv1sEO0gHp/fYkvdUYUhzsY5lWeVdz3U3j/YhQO+ErzBzhIOU+E arC+ldYO9eWzdgRxodOcHX6YFAEnHFeyXs5KfOKbUNdqD0dLNJQ= =lWVS -----END PGP SIGNATURE----- Merge tag 'v1.19.2' into merge_1.19.2 PR-URL: https://github.com/libuv/libuv/pull/1753 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
206 lines
5.9 KiB
C
206 lines
5.9 KiB
C
/* Copyright libuv project contributors. All rights reserved.
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to
|
|
* deal in the Software without restriction, including without limitation the
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
* sell copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
* IN THE SOFTWARE.
|
|
*/
|
|
|
|
#if !defined(_WIN32)
|
|
|
|
#include "uv.h"
|
|
#include "task.h"
|
|
|
|
#include <errno.h>
|
|
#include <sys/socket.h>
|
|
#include <sys/ioctl.h>
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
|
|
static uv_tcp_t server_handle;
|
|
static uv_tcp_t client_handle;
|
|
static uv_tcp_t peer_handle;
|
|
static uv_poll_t poll_req[2];
|
|
static uv_idle_t idle;
|
|
static uv_os_fd_t client_fd;
|
|
static uv_os_fd_t server_fd;
|
|
static int ticks;
|
|
static const int kMaxTicks = 10;
|
|
static int cli_pr_check = 0;
|
|
static int cli_rd_check = 0;
|
|
static int srv_rd_check = 0;
|
|
|
|
static int got_eagain(void) {
|
|
return errno == EAGAIN
|
|
|| errno == EINPROGRESS
|
|
#ifdef EWOULDBLOCK
|
|
|| errno == EWOULDBLOCK
|
|
#endif
|
|
;
|
|
}
|
|
|
|
static void idle_cb(uv_idle_t* idle) {
|
|
uv_sleep(100);
|
|
if (++ticks < kMaxTicks)
|
|
return;
|
|
|
|
uv_poll_stop(&poll_req[0]);
|
|
uv_poll_stop(&poll_req[1]);
|
|
uv_close((uv_handle_t*) &server_handle, NULL);
|
|
uv_close((uv_handle_t*) &client_handle, NULL);
|
|
uv_close((uv_handle_t*) &peer_handle, NULL);
|
|
uv_close((uv_handle_t*) idle, NULL);
|
|
}
|
|
|
|
static void poll_cb(uv_poll_t* handle, int status, int events) {
|
|
char buffer[5];
|
|
int n;
|
|
int fd;
|
|
|
|
ASSERT(0 == uv_fileno((uv_handle_t*)handle, &fd));
|
|
memset(buffer, 0, 5);
|
|
|
|
if (events & UV_PRIORITIZED) {
|
|
do
|
|
n = recv(client_fd, &buffer, 5, MSG_OOB);
|
|
while (n == -1 && errno == EINTR);
|
|
ASSERT(n >= 0 || errno != EINVAL);
|
|
cli_pr_check = 1;
|
|
ASSERT(0 == uv_poll_stop(&poll_req[0]));
|
|
ASSERT(0 == uv_poll_start(&poll_req[0],
|
|
UV_READABLE | UV_WRITABLE,
|
|
poll_cb));
|
|
}
|
|
if (events & UV_READABLE) {
|
|
if (fd == client_fd) {
|
|
do
|
|
n = recv(client_fd, &buffer, 5, 0);
|
|
while (n == -1 && errno == EINTR);
|
|
ASSERT(n >= 0 || errno != EINVAL);
|
|
if (cli_rd_check == 1) {
|
|
ASSERT(strncmp(buffer, "world", n) == 0);
|
|
ASSERT(5 == n);
|
|
cli_rd_check = 2;
|
|
}
|
|
if (cli_rd_check == 0) {
|
|
ASSERT(n == 4);
|
|
ASSERT(strncmp(buffer, "hello", n) == 0);
|
|
cli_rd_check = 1;
|
|
do {
|
|
do
|
|
n = recv(server_fd, &buffer, 5, 0);
|
|
while (n == -1 && errno == EINTR);
|
|
if (n > 0) {
|
|
ASSERT(n == 5);
|
|
ASSERT(strncmp(buffer, "world", n) == 0);
|
|
cli_rd_check = 2;
|
|
}
|
|
} while (n > 0);
|
|
|
|
ASSERT(got_eagain());
|
|
}
|
|
}
|
|
if (fd == server_fd) {
|
|
do
|
|
n = recv(server_fd, &buffer, 3, 0);
|
|
while (n == -1 && errno == EINTR);
|
|
ASSERT(n >= 0 || errno != EINVAL);
|
|
ASSERT(3 == n);
|
|
ASSERT(strncmp(buffer, "foo", n) == 0);
|
|
srv_rd_check = 1;
|
|
uv_poll_stop(&poll_req[1]);
|
|
}
|
|
}
|
|
if (events & UV_WRITABLE) {
|
|
do {
|
|
n = send(client_fd, "foo", 3, 0);
|
|
} while (n < 0 && errno == EINTR);
|
|
ASSERT(3 == n);
|
|
}
|
|
}
|
|
|
|
static void connection_cb(uv_stream_t* handle, int status) {
|
|
int r;
|
|
|
|
ASSERT(0 == status);
|
|
ASSERT(0 == uv_accept(handle, (uv_stream_t*) &peer_handle));
|
|
ASSERT(0 == uv_fileno((uv_handle_t*) &peer_handle, &server_fd));
|
|
ASSERT(0 == uv_poll_init(uv_default_loop(), &poll_req[0], client_fd));
|
|
ASSERT(0 == uv_poll_init(uv_default_loop(), &poll_req[1], server_fd));
|
|
ASSERT(0 == uv_poll_start(&poll_req[0],
|
|
UV_PRIORITIZED | UV_READABLE | UV_WRITABLE,
|
|
poll_cb));
|
|
ASSERT(0 == uv_poll_start(&poll_req[1],
|
|
UV_READABLE,
|
|
poll_cb));
|
|
do {
|
|
r = send(server_fd, "hello", 5, MSG_OOB);
|
|
} while (r < 0 && errno == EINTR);
|
|
ASSERT(5 == r);
|
|
|
|
do {
|
|
r = send(server_fd, "world", 5, 0);
|
|
} while (r < 0 && errno == EINTR);
|
|
ASSERT(5 == r);
|
|
|
|
ASSERT(0 == uv_idle_start(&idle, idle_cb));
|
|
}
|
|
|
|
|
|
TEST_IMPL(poll_oob) {
|
|
struct sockaddr_in addr;
|
|
int r = 0;
|
|
uv_loop_t* loop;
|
|
|
|
ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr));
|
|
loop = uv_default_loop();
|
|
|
|
ASSERT(0 == uv_tcp_init(loop, &server_handle));
|
|
ASSERT(0 == uv_tcp_init(loop, &client_handle));
|
|
ASSERT(0 == uv_tcp_init(loop, &peer_handle));
|
|
ASSERT(0 == uv_idle_init(loop, &idle));
|
|
ASSERT(0 == uv_tcp_bind(&server_handle, (const struct sockaddr*) &addr, 0));
|
|
ASSERT(0 == uv_listen((uv_stream_t*) &server_handle, 1, connection_cb));
|
|
|
|
/* Ensure two separate packets */
|
|
ASSERT(0 == uv_tcp_nodelay(&client_handle, 1));
|
|
|
|
client_fd = socket(PF_INET, SOCK_STREAM, 0);
|
|
ASSERT(client_fd >= 0);
|
|
do {
|
|
errno = 0;
|
|
r = connect(client_fd, (const struct sockaddr*)&addr, sizeof(addr));
|
|
} while (r == -1 && errno == EINTR);
|
|
ASSERT(r == 0);
|
|
|
|
ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT));
|
|
|
|
ASSERT(ticks == kMaxTicks);
|
|
|
|
/* Did client receive the POLLPRI message */
|
|
ASSERT(cli_pr_check == 1);
|
|
/* Did client receive the POLLIN message */
|
|
ASSERT(cli_rd_check == 2);
|
|
/* Could we write with POLLOUT and did the server receive our POLLOUT message
|
|
* through POLLIN.
|
|
*/
|
|
ASSERT(srv_rd_check == 1);
|
|
|
|
MAKE_VALGRIND_HAPPY();
|
|
return 0;
|
|
}
|
|
#endif
|