doc: make sample cross-platform build (#3592)
Co-authored-by: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
parent
69ebb2d720
commit
a78671543b
32
.github/workflows/CI-sample.yml
vendored
Normal file
32
.github/workflows/CI-sample.yml
vendored
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
name: ci-sample
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
paths:
|
||||||
|
- '**'
|
||||||
|
- '!docs/**'
|
||||||
|
- '!.**'
|
||||||
|
- '.github/workflows/CI-sample.yml'
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- v[0-9].*
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [macos-latest, ubuntu-latest, windows-latest]
|
||||||
|
runs-on: ${{matrix.os}}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: setup
|
||||||
|
run: cmake -E make_directory ${{runner.workspace}}/libuv/docs/code/build
|
||||||
|
- name: configure
|
||||||
|
# you may like use Ninja on unix-like OS, but for windows, the only easy way is to use Visual Studio if you want Ninja
|
||||||
|
run: cmake ..
|
||||||
|
working-directory: ${{runner.workspace}}/libuv/docs/code/build
|
||||||
|
- name: build
|
||||||
|
run: cmake --build .
|
||||||
|
working-directory: ${{runner.workspace}}/libuv/docs/code/build
|
||||||
51
docs/code/CMakeLists.txt
Normal file
51
docs/code/CMakeLists.txt
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
|
||||||
|
project(libuv_sample)
|
||||||
|
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
|
add_subdirectory("../../" build)
|
||||||
|
|
||||||
|
set(SIMPLE_SAMPLES
|
||||||
|
cgi
|
||||||
|
helloworld
|
||||||
|
dns
|
||||||
|
detach
|
||||||
|
default-loop
|
||||||
|
idle-basic
|
||||||
|
idle-compute
|
||||||
|
interfaces
|
||||||
|
locks
|
||||||
|
onchange
|
||||||
|
pipe-echo-server
|
||||||
|
ref-timer
|
||||||
|
spawn
|
||||||
|
tcp-echo-server
|
||||||
|
thread-create
|
||||||
|
udp-dhcp
|
||||||
|
uvcat
|
||||||
|
uvstop
|
||||||
|
uvtee
|
||||||
|
)
|
||||||
|
IF (NOT WIN32)
|
||||||
|
list(APPEND SIMPLE_SAMPLES
|
||||||
|
signal
|
||||||
|
progress
|
||||||
|
queue-cancel
|
||||||
|
queue-work
|
||||||
|
tty
|
||||||
|
tty-gravity
|
||||||
|
)
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
|
foreach (X IN LISTS SIMPLE_SAMPLES)
|
||||||
|
add_executable(${X} ${X}/main.c)
|
||||||
|
target_link_libraries(${X} uv_a)
|
||||||
|
endforeach ()
|
||||||
|
|
||||||
|
|
||||||
|
FIND_PACKAGE(CURL)
|
||||||
|
IF(CURL_FOUND)
|
||||||
|
add_executable(uvwget uvwget/main.c)
|
||||||
|
target_link_libraries(uvwget uv_a ${CURL_LIBRARIES})
|
||||||
|
ENDIF(CURL_FOUND)
|
||||||
@ -15,8 +15,8 @@ void cleanup_handles(uv_process_t *req, int64_t exit_status, int term_signal) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void invoke_cgi_script(uv_tcp_t *client) {
|
void invoke_cgi_script(uv_tcp_t *client) {
|
||||||
size_t size = 500;
|
char path[500];
|
||||||
char path[size];
|
size_t size = sizeof(path);
|
||||||
uv_exepath(path, &size);
|
uv_exepath(path, &size);
|
||||||
strcpy(path + (strlen(path) - strlen("cgi")), "tick");
|
strcpy(path + (strlen(path) - strlen("cgi")), "tick");
|
||||||
|
|
||||||
|
|||||||
@ -11,17 +11,17 @@ int main() {
|
|||||||
|
|
||||||
printf("Number of interfaces: %d\n", count);
|
printf("Number of interfaces: %d\n", count);
|
||||||
while (i--) {
|
while (i--) {
|
||||||
uv_interface_address_t interface = info[i];
|
uv_interface_address_t interface_a = info[i];
|
||||||
|
|
||||||
printf("Name: %s\n", interface.name);
|
printf("Name: %s\n", interface_a.name);
|
||||||
printf("Internal? %s\n", interface.is_internal ? "Yes" : "No");
|
printf("Internal? %s\n", interface_a.is_internal ? "Yes" : "No");
|
||||||
|
|
||||||
if (interface.address.address4.sin_family == AF_INET) {
|
if (interface_a.address.address4.sin_family == AF_INET) {
|
||||||
uv_ip4_name(&interface.address.address4, buf, sizeof(buf));
|
uv_ip4_name(&interface_a.address.address4, buf, sizeof(buf));
|
||||||
printf("IPv4 address: %s\n", buf);
|
printf("IPv4 address: %s\n", buf);
|
||||||
}
|
}
|
||||||
else if (interface.address.address4.sin_family == AF_INET6) {
|
else if (interface_a.address.address4.sin_family == AF_INET6) {
|
||||||
uv_ip6_name(&interface.address.address6, buf, sizeof(buf));
|
uv_ip6_name(&interface_a.address.address6, buf, sizeof(buf));
|
||||||
printf("IPv6 address: %s\n", buf);
|
printf("IPv6 address: %s\n", buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include <uv.h>
|
#include <uv.h>
|
||||||
|
|
||||||
@ -7,7 +6,7 @@ void hare(void *arg) {
|
|||||||
int tracklen = *((int *) arg);
|
int tracklen = *((int *) arg);
|
||||||
while (tracklen) {
|
while (tracklen) {
|
||||||
tracklen--;
|
tracklen--;
|
||||||
sleep(1);
|
uv_sleep(1000);
|
||||||
fprintf(stderr, "Hare ran another step\n");
|
fprintf(stderr, "Hare ran another step\n");
|
||||||
}
|
}
|
||||||
fprintf(stderr, "Hare done running!\n");
|
fprintf(stderr, "Hare done running!\n");
|
||||||
@ -18,7 +17,7 @@ void tortoise(void *arg) {
|
|||||||
while (tracklen) {
|
while (tracklen) {
|
||||||
tracklen--;
|
tracklen--;
|
||||||
fprintf(stderr, "Tortoise ran another step\n");
|
fprintf(stderr, "Tortoise ran another step\n");
|
||||||
sleep(3);
|
uv_sleep(3000);
|
||||||
}
|
}
|
||||||
fprintf(stderr, "Tortoise done running!\n");
|
fprintf(stderr, "Tortoise done running!\n");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -53,7 +53,8 @@ uv_buf_t make_discover_msg() {
|
|||||||
// HOPS
|
// HOPS
|
||||||
buffer.base[3] = 0x0;
|
buffer.base[3] = 0x0;
|
||||||
// XID 4 bytes
|
// XID 4 bytes
|
||||||
buffer.base[4] = (unsigned int) random();
|
if (uv_random(NULL, NULL, &buffer.base[4], 4, 0, NULL))
|
||||||
|
abort();
|
||||||
// SECS
|
// SECS
|
||||||
buffer.base[8] = 0x0;
|
buffer.base[8] = 0x0;
|
||||||
// FLAGS
|
// FLAGS
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <uv.h>
|
#include <uv.h>
|
||||||
|
|
||||||
void on_read(uv_fs_t *req);
|
void on_read(uv_fs_t *req);
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user