-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update toml files under apps/ and how to use them
- Loading branch information
Showing
30 changed files
with
1,388 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
/target | ||
/Nomu_Engine | ||
*.hash | ||
compile_commands.json | ||
compile_commands.json | ||
ruxos_bld | ||
sqlite-amalgamation-3410100 | ||
file.sqlite | ||
dump.rdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[build] | ||
compiler = "gcc" | ||
|
||
[os] | ||
name = "ruxos" | ||
services = ["alloc","paging","fs","blkfs"] | ||
ulib = "ruxlibc" | ||
|
||
[os.platform] | ||
name = "x86_64-qemu-q35" | ||
smp = "4" | ||
mode = "release" | ||
log = "warn" | ||
|
||
[os.platform.qemu] | ||
graphic = "n" | ||
blk = "y" | ||
|
||
[[targets]] | ||
name = "filetest" | ||
src = "./" | ||
include_dir = "./" | ||
type = "exe" | ||
cflags = "" | ||
linker = "rust-lld -flavor gnu" | ||
ldflags = "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[build] | ||
compiler = "gcc" | ||
|
||
[[targets]] | ||
name = "helloworld" | ||
src = "./" | ||
include_dir = "./" | ||
type = "exe" | ||
cflags = "" | ||
ldflags = "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* Copyright (c) [2023] [Syswonder Community] | ||
* [Ruxos] is licensed under Mulan PSL v2. | ||
* You can use this software according to the terms and conditions of the Mulan PSL v2. | ||
* You may obtain a copy of Mulan PSL v2 at: | ||
* http://license.coscl.org.cn/MulanPSL2 | ||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. | ||
* See the Mulan PSL v2 for more details. | ||
*/ | ||
|
||
#include <stdio.h> | ||
|
||
int main() | ||
{ | ||
printf("Hello, %c app!\n", 'C'); | ||
return 0; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[build] | ||
compiler = "gcc" | ||
|
||
[[targets]] | ||
name = "httpclient" | ||
src = "./" | ||
include_dir = "./" | ||
type = "exe" | ||
cflags = "" | ||
ldflags = "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* Copyright (c) [2023] [Syswonder Community] | ||
* [Ruxos] is licensed under Mulan PSL v2. | ||
* You can use this software according to the terms and conditions of the Mulan PSL v2. | ||
* You may obtain a copy of Mulan PSL v2 at: | ||
* http://license.coscl.org.cn/MulanPSL2 | ||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. | ||
* See the Mulan PSL v2 for more details. | ||
*/ | ||
|
||
#include <arpa/inet.h> | ||
#include <netdb.h> | ||
#include <netinet/in.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <sys/socket.h> | ||
#include <sys/uio.h> | ||
|
||
const char request[] = "\ | ||
GET / HTTP/1.1\r\n\ | ||
Host: ident.me\r\n\ | ||
Accept: */*\r\n\ | ||
\r\n"; | ||
|
||
char request1[] = "\ | ||
GET / HTTP/1.1\r\n"; | ||
|
||
char request2[] = "Host: ident.me\r\n\ | ||
Accept: */*\r\n\ | ||
\r\n"; | ||
|
||
int main() | ||
{ | ||
puts("Hello, Ruxos C HTTP client!"); | ||
int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); | ||
if (sock == -1) { | ||
perror("socket() error"); | ||
return -1; | ||
} | ||
struct addrinfo *res; | ||
|
||
if (getaddrinfo("ident.me", NULL, NULL, &res) != 0) { | ||
perror("getaddrinfo() error"); | ||
return -1; | ||
} | ||
char str[INET_ADDRSTRLEN]; | ||
if (inet_ntop(AF_INET, &(((struct sockaddr_in *)(res->ai_addr))->sin_addr), str, | ||
INET_ADDRSTRLEN) == NULL) { | ||
perror("inet_ntop() error"); | ||
return -1; | ||
} | ||
printf("IP: %s\n", str); | ||
((struct sockaddr_in *)(res->ai_addr))->sin_port = htons(80); | ||
if (connect(sock, res->ai_addr, sizeof(*(res->ai_addr))) != 0) { | ||
perror("connect() error"); | ||
return -1; | ||
} | ||
char rebuf[2000] = {}; | ||
if (send(sock, request, strlen(request), 0) == -1) { | ||
perror("send() error"); | ||
return -1; | ||
} | ||
ssize_t l = recv(sock, rebuf, 2000, 0); | ||
if (l == -1) { | ||
perror("recv() error"); | ||
return -1; | ||
} | ||
rebuf[l] = '\0'; | ||
printf("%s\n", rebuf); | ||
// test sendmsg | ||
struct iovec iovs[2] = { | ||
{ .iov_base = request1, .iov_len = strlen(request1)}, | ||
{ .iov_base = request2, .iov_len = strlen(request2)} | ||
}; | ||
struct msghdr mg = { | ||
.msg_iov = iovs, | ||
.msg_iovlen = 2 | ||
}; | ||
int num = sendmsg(sock, &mg, 0); | ||
if (num == -1) { | ||
perror("sendmsg() error"); | ||
return -1; | ||
} | ||
freeaddrinfo(res); | ||
|
||
return 0; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[build] | ||
compiler = "gcc" | ||
|
||
[[targets]] | ||
name = "httpserver" | ||
src = "./" | ||
include_dir = "./" | ||
type = "exe" | ||
cflags = "-Wno-format" | ||
ldflags = "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* Copyright (c) [2023] [Syswonder Community] | ||
* [Ruxos] is licensed under Mulan PSL v2. | ||
* You can use this software according to the terms and conditions of the Mulan PSL v2. | ||
* You may obtain a copy of Mulan PSL v2 at: | ||
* http://license.coscl.org.cn/MulanPSL2 | ||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. | ||
* See the Mulan PSL v2 for more details. | ||
*/ | ||
|
||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
#include <arpa/inet.h> | ||
#include <netinet/in.h> | ||
#include <sys/socket.h> | ||
|
||
const char header[] = "\ | ||
HTTP/1.1 200 OK\r\n\ | ||
Content-Type: text/html\r\n\ | ||
Content-Length: %u\r\n\ | ||
Connection: close\r\n\ | ||
\r\n\ | ||
"; | ||
|
||
const char content[] = "<html>\n\ | ||
<head>\n\ | ||
<title>Hello, Ruxos</title>\n\ | ||
</head>\n\ | ||
<body>\n\ | ||
<center>\n\ | ||
<h1>Hello, <a href=\"https://github.com/syswonder/ruxos\">Ruxos</a></h1>\n\ | ||
</center>\n\ | ||
<hr>\n\ | ||
<center>\n\ | ||
<i>Powered by <a href=\"https://github.com/syswonder/ruxos/tree/main/apps/net/httpserver\">Ruxos example HTTP server</a> v0.1.0</i>\n\ | ||
</center>\n\ | ||
</body>\n\ | ||
</html>\n\ | ||
"; | ||
|
||
int main() | ||
{ | ||
puts("Hello, Ruxos C HTTP server!"); | ||
struct sockaddr_in local, remote; | ||
int addr_len = sizeof(remote); | ||
local.sin_family = AF_INET; | ||
if (inet_pton(AF_INET, "0.0.0.0", &(local.sin_addr)) != 1) { | ||
perror("inet_pton() error"); | ||
return -1; | ||
} | ||
local.sin_port = htons(5555); | ||
int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); | ||
if (sock == -1) { | ||
perror("socket() error"); | ||
return -1; | ||
} | ||
if (bind(sock, (struct sockaddr *)&local, sizeof(local)) != 0) { | ||
perror("bind() error"); | ||
return -1; | ||
} | ||
if (listen(sock, 0) != 0) { | ||
perror("listen() error"); | ||
return -1; | ||
} | ||
puts("listen on: http://0.0.0.0:5555/"); | ||
char buf[1024] = {}; | ||
int client; | ||
char response[1024] = {}; | ||
snprintf(response, 1024, header, strlen(content)); | ||
strcat(response, content); | ||
for (;;) { | ||
client = accept(sock, (struct sockaddr *)&remote, (socklen_t *)&addr_len); | ||
if (client == -1) { | ||
perror("accept() error"); | ||
return -1; | ||
} | ||
printf("new client %d\n", client); | ||
if (recv(client, buf, 1024, 0) == -1) { | ||
perror("recv() error"); | ||
return -1; | ||
} | ||
ssize_t l = send(client, response, strlen(response), 0); | ||
if (l == -1) { | ||
perror("send() error"); | ||
return -1; | ||
} | ||
if (close(client) == -1) { | ||
perror("close() error"); | ||
return -1; | ||
} | ||
printf("client %d close: %ld bytes sent\n", client, l); | ||
} | ||
if (close(sock) == -1) { | ||
perror("close() error"); | ||
return -1; | ||
} | ||
return 0; | ||
} |
File renamed without changes.
Oops, something went wrong.