feat: publish Android 1.0.1 candidate source and acceptance evidence
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
============================================================================
|
||||
Name : call.c
|
||||
Author : Heiher <r@hev.cc>
|
||||
Copyright : Copyright (c) 2020 everyone.
|
||||
Description :
|
||||
============================================================================
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <hev-task.h>
|
||||
#include <hev-task-call.h>
|
||||
#include <hev-task-system.h>
|
||||
|
||||
static void
|
||||
call_entry (HevTaskCall *call)
|
||||
{
|
||||
void *ptr;
|
||||
|
||||
printf ("call %p on stack %p\n", call, &ptr);
|
||||
hev_task_call_set_retval (call, &ptr);
|
||||
}
|
||||
|
||||
static void
|
||||
task_entry (void *data)
|
||||
{
|
||||
HevTaskCall *call;
|
||||
|
||||
call = hev_task_call_new (sizeof (HevTaskCall), 8192);
|
||||
hev_task_call_jump (call, call_entry);
|
||||
hev_task_call_destroy (call);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
HevTask *task;
|
||||
|
||||
hev_task_system_init ();
|
||||
|
||||
task = hev_task_new (-1);
|
||||
hev_task_run (task, task_entry, NULL);
|
||||
|
||||
hev_task_system_run ();
|
||||
|
||||
hev_task_system_fini ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
============================================================================
|
||||
Name : channel.c
|
||||
Author : Heiher <r@hev.cc>
|
||||
Copyright : Copyright (c) 2019 everyone.
|
||||
Description :
|
||||
============================================================================
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <hev-task.h>
|
||||
#include <hev-task-system.h>
|
||||
#include <hev-task-channel.h>
|
||||
|
||||
typedef struct _TaskArgs TaskArgs;
|
||||
|
||||
struct _TaskArgs
|
||||
{
|
||||
int type;
|
||||
char *command;
|
||||
};
|
||||
|
||||
static void
|
||||
task_entry1 (void *data)
|
||||
{
|
||||
HevTaskChannel *chan = data;
|
||||
TaskArgs args;
|
||||
|
||||
hev_task_channel_read (chan, &args, sizeof (args));
|
||||
printf ("type: %d command: %s\n", args.type, args.command);
|
||||
|
||||
args.type = 2;
|
||||
args.command = "world";
|
||||
hev_task_channel_write (chan, &args, sizeof (args));
|
||||
|
||||
hev_task_channel_destroy (chan);
|
||||
}
|
||||
|
||||
static void
|
||||
task_entry2 (void *data)
|
||||
{
|
||||
HevTaskChannel *chan = data;
|
||||
TaskArgs args = {
|
||||
.type = 1,
|
||||
.command = "hello",
|
||||
};
|
||||
|
||||
hev_task_channel_write (chan, &args, sizeof (args));
|
||||
hev_task_channel_read (chan, &args, sizeof (args));
|
||||
printf ("type: %d command: %s\n", args.type, args.command);
|
||||
|
||||
hev_task_channel_destroy (chan);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
HevTask *task;
|
||||
HevTaskChannel *chan1, *chan2;
|
||||
|
||||
hev_task_system_init ();
|
||||
|
||||
hev_task_channel_new (&chan1, &chan2);
|
||||
|
||||
task = hev_task_new (-1);
|
||||
hev_task_set_priority (task, 1);
|
||||
hev_task_run (task, task_entry1, chan1);
|
||||
|
||||
task = hev_task_new (-1);
|
||||
hev_task_set_priority (task, 2);
|
||||
hev_task_run (task, task_entry2, chan2);
|
||||
|
||||
hev_task_system_run ();
|
||||
|
||||
hev_task_system_fini ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
============================================================================
|
||||
Name : curl.c
|
||||
Author : Heiher <r@hev.cc>
|
||||
Copyright : Copyright (c) 2017 everyone.
|
||||
Description :
|
||||
============================================================================
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
#include <poll.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include <hev-task.h>
|
||||
#include <hev-task-system.h>
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
typedef int (*posix_poll_func) (struct pollfd[], nfds_t, int);
|
||||
|
||||
static posix_poll_func posix_poll;
|
||||
|
||||
int
|
||||
poll (struct pollfd fds[], nfds_t nfds, int timeout)
|
||||
{
|
||||
HevTask *task = hev_task_self ();
|
||||
int res;
|
||||
|
||||
if (!task)
|
||||
return posix_poll (fds, nfds, timeout);
|
||||
|
||||
if (timeout == 0) {
|
||||
res = posix_poll (fds, nfds, 0);
|
||||
} else {
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < nfds; i++) {
|
||||
if (hev_task_mod_fd (task, fds[i].fd, fds[i].events) < 0)
|
||||
hev_task_add_fd (task, fds[i].fd, fds[i].events);
|
||||
}
|
||||
|
||||
if (timeout > 0) {
|
||||
do {
|
||||
timeout = hev_task_sleep (timeout);
|
||||
res = posix_poll (fds, nfds, 0);
|
||||
} while (timeout > 0 && res == 0);
|
||||
} else {
|
||||
do {
|
||||
hev_task_yield (HEV_TASK_WAITIO);
|
||||
res = posix_poll (fds, nfds, 0);
|
||||
} while (res == 0);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static void
|
||||
task_socket_entry (void *data)
|
||||
{
|
||||
const char *url = data;
|
||||
CURL *curl;
|
||||
FILE *fp;
|
||||
static int index = 0;
|
||||
char path[32];
|
||||
|
||||
curl = curl_easy_init ();
|
||||
if (!curl)
|
||||
return;
|
||||
|
||||
snprintf (path, 32, "%d.dat", index++);
|
||||
fp = fopen (path, "w");
|
||||
if (!fp)
|
||||
return;
|
||||
|
||||
curl_easy_setopt (curl, CURLOPT_URL, url);
|
||||
curl_easy_setopt (curl, CURLOPT_ACCEPT_ENCODING, "");
|
||||
curl_easy_setopt (curl, CURLOPT_WRITEDATA, fp);
|
||||
curl_easy_perform (curl);
|
||||
|
||||
fclose (fp);
|
||||
curl_easy_cleanup (curl);
|
||||
|
||||
printf ("%s DONE\n", url);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
|
||||
posix_poll = dlsym (RTLD_NEXT, "poll");
|
||||
if (!posix_poll || posix_poll == poll)
|
||||
return -1;
|
||||
|
||||
hev_task_system_init ();
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
HevTask *task;
|
||||
|
||||
task = hev_task_new (-1);
|
||||
hev_task_run (task, task_socket_entry, argv[i]);
|
||||
}
|
||||
|
||||
hev_task_system_run ();
|
||||
|
||||
hev_task_system_fini ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
============================================================================
|
||||
Name : echo-server.c
|
||||
Author : Heiher <r@hev.cc>
|
||||
Copyright : Copyright (c) 2017 - 2018 everyone.
|
||||
Description :
|
||||
============================================================================
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <hev-task.h>
|
||||
#include <hev-task-system.h>
|
||||
#include <hev-task-io.h>
|
||||
#include <hev-task-io-socket.h>
|
||||
|
||||
static void
|
||||
task_client_entry (void *data)
|
||||
{
|
||||
int fd = (intptr_t)data;
|
||||
char buf[2048];
|
||||
ssize_t size;
|
||||
|
||||
size = hev_task_io_socket_recv (fd, buf, 2048, 0, NULL, NULL);
|
||||
if (size == -1) {
|
||||
printf ("Receive failed!\n");
|
||||
goto quit;
|
||||
}
|
||||
|
||||
size = hev_task_io_socket_send (fd, buf, size, MSG_WAITALL, NULL, NULL);
|
||||
if (size == -1) {
|
||||
printf ("Send failed!\n");
|
||||
goto quit;
|
||||
}
|
||||
|
||||
quit:
|
||||
close (fd);
|
||||
}
|
||||
|
||||
static void
|
||||
task_listener_entry (void *data)
|
||||
{
|
||||
HevTask *task = hev_task_self ();
|
||||
int fd, ret, reuseaddr = 1;
|
||||
struct sockaddr_in addr;
|
||||
|
||||
fd = hev_task_io_socket_socket (AF_INET, SOCK_STREAM, 0);
|
||||
if (fd == -1) {
|
||||
fprintf (stderr, "Create socket failed!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &reuseaddr,
|
||||
sizeof (reuseaddr));
|
||||
if (ret == -1) {
|
||||
fprintf (stderr, "Set reuse address failed!\n");
|
||||
close (fd);
|
||||
return;
|
||||
}
|
||||
|
||||
memset (&addr, 0, sizeof (addr));
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_addr.s_addr = INADDR_ANY;
|
||||
addr.sin_port = htons (8000);
|
||||
ret = bind (fd, (struct sockaddr *)&addr, (socklen_t)sizeof (addr));
|
||||
if (ret == -1) {
|
||||
fprintf (stderr, "Bind address failed!\n");
|
||||
close (fd);
|
||||
return;
|
||||
}
|
||||
ret = listen (fd, 100);
|
||||
if (ret == -1) {
|
||||
fprintf (stderr, "Listen failed!\n");
|
||||
close (fd);
|
||||
return;
|
||||
}
|
||||
|
||||
hev_task_add_fd (task, fd, POLLIN);
|
||||
|
||||
while (1) {
|
||||
int client_fd;
|
||||
struct sockaddr *in_addr = (struct sockaddr *)&addr;
|
||||
socklen_t addr_len = sizeof (addr);
|
||||
|
||||
for (;;) {
|
||||
client_fd =
|
||||
hev_task_io_socket_accept (fd, in_addr, &addr_len, NULL, NULL);
|
||||
if (-1 != client_fd)
|
||||
break;
|
||||
printf ("Accept failed!\n");
|
||||
}
|
||||
|
||||
printf ("New client %d enter from %s:%u\n", client_fd,
|
||||
inet_ntoa (addr.sin_addr), ntohs (addr.sin_port));
|
||||
|
||||
task = hev_task_new (-1);
|
||||
hev_task_set_priority (task, 1);
|
||||
hev_task_add_fd (task, client_fd, POLLIN | POLLOUT);
|
||||
hev_task_run (task, task_client_entry, (void *)(intptr_t)client_fd);
|
||||
}
|
||||
|
||||
close (fd);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
HevTask *task;
|
||||
|
||||
hev_task_system_init ();
|
||||
|
||||
task = hev_task_new (-1);
|
||||
hev_task_run (task, task_listener_entry, NULL);
|
||||
|
||||
hev_task_system_run ();
|
||||
|
||||
hev_task_system_fini ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
============================================================================
|
||||
Name : gtk.c
|
||||
Author : Heiher <r@hev.cc>
|
||||
Copyright : Copyright (c) 2017 everyone.
|
||||
Description :
|
||||
============================================================================
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <hev-task.h>
|
||||
#include <hev-task-system.h>
|
||||
#include <hev-task-io-poll.h>
|
||||
|
||||
#include <glib.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
static gboolean
|
||||
window_delete_event_handler (GtkWidget *widget, GdkEvent *event,
|
||||
gpointer user_data)
|
||||
{
|
||||
gtk_main_quit ();
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
task_entry1 (void *data)
|
||||
{
|
||||
GtkWidget *window;
|
||||
|
||||
gtk_init (NULL, NULL);
|
||||
|
||||
/* Use hev_task_poll to poll fds in GLib event loop */
|
||||
g_main_context_set_poll_func (g_main_context_default (),
|
||||
(GPollFunc)hev_task_io_poll);
|
||||
|
||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
g_signal_connect (window, "delete-event",
|
||||
G_CALLBACK (window_delete_event_handler), NULL);
|
||||
gtk_widget_show (window);
|
||||
|
||||
gtk_main ();
|
||||
}
|
||||
|
||||
static void
|
||||
task_entry2 (void *data)
|
||||
{
|
||||
HevTask *task1 = data;
|
||||
|
||||
for (; hev_task_get_state (task1) != HEV_TASK_STOPPED;) {
|
||||
printf ("hello 1\n");
|
||||
hev_task_sleep (1000);
|
||||
}
|
||||
|
||||
hev_task_unref (task1);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
HevTask *task1, *task2;
|
||||
|
||||
hev_task_system_init ();
|
||||
|
||||
task1 = hev_task_new (1024 * 1024);
|
||||
hev_task_set_priority (task1, 2);
|
||||
hev_task_run (task1, task_entry1, NULL);
|
||||
|
||||
task2 = hev_task_new (-1);
|
||||
hev_task_set_priority (task2, 1);
|
||||
hev_task_run (task2, task_entry2, hev_task_ref (task1));
|
||||
|
||||
hev_task_system_run ();
|
||||
|
||||
hev_task_system_fini ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
============================================================================
|
||||
Name : simple.c
|
||||
Author : Heiher <r@hev.cc>
|
||||
Copyright : Copyright (c) 2017 everyone.
|
||||
Description :
|
||||
============================================================================
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <hev-task.h>
|
||||
#include <hev-task-system.h>
|
||||
|
||||
static void
|
||||
task_entry1 (void *data)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
printf ("hello 1\n");
|
||||
hev_task_yield (HEV_TASK_YIELD);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
task_entry2 (void *data)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
printf ("hello 2\n");
|
||||
hev_task_yield (HEV_TASK_YIELD);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
HevTask *task;
|
||||
|
||||
hev_task_system_init ();
|
||||
|
||||
task = hev_task_new (-1);
|
||||
hev_task_set_priority (task, 2);
|
||||
hev_task_run (task, task_entry1, NULL);
|
||||
|
||||
task = hev_task_new (-1);
|
||||
hev_task_set_priority (task, 1);
|
||||
hev_task_run (task, task_entry2, NULL);
|
||||
|
||||
hev_task_system_run ();
|
||||
|
||||
hev_task_system_fini ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
============================================================================
|
||||
Name : timeout.c
|
||||
Author : Heiher <r@hev.cc>
|
||||
Copyright : Copyright (c) 2017 everyone.
|
||||
Description :
|
||||
============================================================================
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <hev-task.h>
|
||||
#include <hev-task-system.h>
|
||||
|
||||
static void
|
||||
task_entry (void *data)
|
||||
{
|
||||
const unsigned int interval = 1000;
|
||||
|
||||
printf ("waiting for timeout %ums ...\n", interval);
|
||||
hev_task_sleep (interval);
|
||||
printf ("timeout\n");
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
HevTask *task;
|
||||
|
||||
hev_task_system_init ();
|
||||
|
||||
task = hev_task_new (-1);
|
||||
hev_task_run (task, task_entry, NULL);
|
||||
|
||||
hev_task_system_run ();
|
||||
|
||||
hev_task_system_fini ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
============================================================================
|
||||
Name : wakeup.c
|
||||
Author : Heiher <r@hev.cc>
|
||||
Copyright : Copyright (c) 2017 everyone.
|
||||
Description :
|
||||
============================================================================
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <hev-task.h>
|
||||
#include <hev-task-system.h>
|
||||
|
||||
static void
|
||||
task_entry1 (void *data)
|
||||
{
|
||||
const unsigned int interval = 5000;
|
||||
unsigned int left_ms;
|
||||
|
||||
printf ("task1: waiting for timeout %ums ...\n", interval);
|
||||
left_ms = hev_task_sleep (interval);
|
||||
if (left_ms == 0)
|
||||
printf ("task1: timeout\n");
|
||||
else
|
||||
printf ("task1: awake now, left: %ums\n", left_ms);
|
||||
}
|
||||
|
||||
static void
|
||||
task_entry2 (void *data)
|
||||
{
|
||||
HevTask *task1 = data;
|
||||
const unsigned int interval = 1000;
|
||||
|
||||
printf ("task2: wakeup task1 after %dms...\n", interval);
|
||||
hev_task_sleep (interval);
|
||||
printf ("task2: wakeup task1 ...\n");
|
||||
hev_task_wakeup (task1);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
HevTask *task1, *task2;
|
||||
|
||||
hev_task_system_init ();
|
||||
|
||||
task1 = hev_task_new (-1);
|
||||
hev_task_run (task1, task_entry1, NULL);
|
||||
|
||||
task2 = hev_task_new (-1);
|
||||
hev_task_set_priority (task2, 1);
|
||||
hev_task_run (task2, task_entry2, task1);
|
||||
|
||||
hev_task_system_run ();
|
||||
|
||||
hev_task_system_fini ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user