annotate gara/main.c @ 48:46daba6e3cf4

Few python scrtips to show how to use asychio.
author MrJuneJune <me@mrjunejune.com>
date Sat, 13 Dec 2025 14:23:02 -0800
parents ac8626c7859c
children a0f0ad5e42eb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
45
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
1 #include "seobeo/seobeo.h"
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
2 #include "stdio.h"
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
3
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
4 void HandleClientRequest(Seobeo_PHandle p_cli_handle) {
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
5 char *hello = "Hello good sir";
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
6 Seobeo_Handle_Queue(p_cli_handle, (uint8_t*)hello, 14);
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
7 Seobeo_Handle_Flush(p_cli_handle);
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
8
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
9 while (1)
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
10 {
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
11 int n = Seobeo_Handle_Read(p_cli_handle);
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
12 if (n > 0)
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
13 {
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
14 printf(p_cli_handle->read_buffer);
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
15 Seobeo_Handle_Consume(p_cli_handle, n);
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
16 }
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
17 }
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
18 }
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
19
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
20 int main()
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
21 {
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
22
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
23 printf("Server initializing\n");
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
24 const char *PORT = "3322";
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
25 Seobeo_PHandle server = Seobeo_Stream_Handle_Server_Create(NULL, PORT);
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
26
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
27 printf("Server running\n");
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
28 while (1)
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
29 {
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
30 Seobeo_PHandle p_cli_handle =
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
31 Seobeo_Stream_Handle_Server_Accept(server);
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
32 if (!p_cli_handle) continue;
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
33
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
34 if (fork() == 0)
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
35 {
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
36 HandleClientRequest(p_cli_handle);
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
37 _exit(0);
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
38 }
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
39 }
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
40
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
41 return 0;
ac8626c7859c [Gara] Re-writing basic logic in C and hoping that I can import that into Java.
MrJuneJune <me@mrjunejune.com>
parents:
diff changeset
42 }