mirror of
https://github.com/mmueller41/genode.git
synced 2026-01-21 12:32:56 +01:00
Mutlithreaded netty server.
This commit is contained in:
@@ -6,6 +6,7 @@ import_from_depot [depot_user]/src/[base_src] \
|
||||
[depot_user]/src/dynamic_rom \
|
||||
[depot_user]/src/init \
|
||||
[depot_user]/src/libc \
|
||||
[depot_user]/src/stdcxx \
|
||||
[depot_user]/src/nic_router \
|
||||
[depot_user]/src/vfs_audit \
|
||||
[depot_user]/src/vfs_lxip \
|
||||
@@ -50,12 +51,12 @@ append config {
|
||||
<service name="Nic"/>
|
||||
<service name="Uplink"/>
|
||||
</provides>
|
||||
<config verbose_domain_state="yes">
|
||||
<config verbose_domain_state="no">
|
||||
|
||||
<policy label_prefix="socket_fs" domain="downlink"/>
|
||||
<policy label_prefix="drivers" domain="uplink"/>
|
||||
|
||||
<domain name="uplink" interface="10.0.2.55/24" gateway="10.0.2.1" verbose_packets="true">
|
||||
<domain name="uplink" interface="10.0.2.55/24" gateway="10.0.2.1" verbose_packets="no">
|
||||
|
||||
<nat domain="downlink"
|
||||
tcp-ports="16384"
|
||||
@@ -70,7 +71,7 @@ append config {
|
||||
|
||||
</domain>
|
||||
|
||||
<domain name="downlink" interface="10.0.3.1/24" verbose_packets="true">
|
||||
<domain name="downlink" interface="10.0.3.1/24" verbose_packets="no">
|
||||
|
||||
<dhcp-server ip_first="10.0.3.55" ip_last="10.0.3.55">
|
||||
<dns-server ip="8.8.8.8"/>
|
||||
@@ -96,7 +97,7 @@ append_if [use_dynamic_rom] config {
|
||||
<config ld_verbose="yes">
|
||||
<vfs>
|
||||
<dir name="socket">
|
||||
<lxip ip_addr="10.0.2.55" netmask="255.255.255.0" gateway="10.0.2.1" nameserver="8.8.8.8"/>
|
||||
<lxip ip_addr="192.168.0.2" netmask="255.255.255.0" gateway="192.168.0.1" nameserver="8.8.8.8"/>
|
||||
</dir>
|
||||
</vfs>
|
||||
<default-policy root="/socket" writeable="yes" />
|
||||
@@ -156,4 +157,4 @@ append qemu_args " -nographic "
|
||||
append_qemu_nic_args "host=10.0.2.1,dhcpstart=10.0.2.55,hostfwd=tcp::10080-:80,hostfwd=tcp::18080-:8080,hostfwd=udp::10007-:7,hostfwd=udp::17070-:7070"
|
||||
|
||||
|
||||
# vi: set ft=tcl :
|
||||
# vi: set ft=tcl
|
||||
|
||||
@@ -3,9 +3,9 @@ import_from_depot [depot_user]/src/[base_src] \
|
||||
[depot_user]/pkg/[drivers_nic_pkg] \
|
||||
[depot_user]/src/init \
|
||||
[depot_user]/src/libc \
|
||||
[depot_user]/src/stdcxx \
|
||||
[depot_user]/src/nic_router \
|
||||
[depot_user]/src/vfs_audit \
|
||||
[depot_user]/src/vfs_lwip \
|
||||
[depot_user]/src/vfs
|
||||
|
||||
append config {
|
||||
@@ -27,10 +27,11 @@ append config {
|
||||
<any-service> <parent/> <any-child/> </any-service>
|
||||
</default-route>
|
||||
|
||||
<default caps="100"/>
|
||||
<affinity-space width="64" height="1"/>
|
||||
<default caps="8192"/>
|
||||
|
||||
<start name="timer">
|
||||
<resource name="RAM" quantum="1M"/>
|
||||
<resource name="RAM" quantum="16M"/>
|
||||
<provides> <service name="Timer"/> </provides>
|
||||
</start>
|
||||
|
||||
@@ -51,12 +52,12 @@ append config {
|
||||
<service name="Nic"/>
|
||||
<service name="Uplink"/>
|
||||
</provides>
|
||||
<config verbose_domain_state="yes">
|
||||
<config verbose_domain_state="false">
|
||||
|
||||
<policy label_prefix="socket_fs" domain="downlink"/>
|
||||
<policy label_prefix="drivers" domain="uplink"/>
|
||||
|
||||
<domain name="uplink" interface="10.0.2.55/24" gateway="10.0.2.1">
|
||||
<domain name="uplink" interface="192.168.0.2/24" gateway="192.168.0.2">
|
||||
|
||||
<nat domain="downlink"
|
||||
tcp-ports="16384"
|
||||
@@ -98,13 +99,10 @@ append config {
|
||||
</route>
|
||||
<config ld_verbose="yes">
|
||||
<vfs>
|
||||
<dir name="lwip">
|
||||
<dir name="socket">
|
||||
<lwip ip_addr="10.0.3.55" netmask="255.255.255.0" gateway="10.0.3.1" nameserver="8.8.8.8"/>
|
||||
<!-- <lwip dhcp="yes"/> -->
|
||||
</dir>
|
||||
<dir name="socket">
|
||||
<audit path="/lwip"/>
|
||||
</dir>
|
||||
</vfs>
|
||||
<default-policy root="/socket" writeable="yes" />
|
||||
</config>
|
||||
@@ -112,6 +110,6 @@ append config {
|
||||
}
|
||||
|
||||
append qemu_args " -nographic "
|
||||
append_qemu_nic_args
|
||||
append_qemu_nic_args "host=10.0.2.1,dhcpstart=10.0.2.55,hostfwd=tcp::10080-:80,hostfwd=tcp::18080-:8080,hostfwd=udp::10007-:7,hostfwd=udp::17070-:7070"
|
||||
|
||||
# vi: set ft=tcl :
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
source ${genode_dir}/repos/libports/run/netty_lwip.inc
|
||||
|
||||
build { test/netty/tcp }
|
||||
build { lib/vfs_lwip test/netty/tcp }
|
||||
|
||||
append config {
|
||||
<!---
|
||||
<start name="netty-server-80">
|
||||
<binary name="test-netty_tcp"/>
|
||||
<resource name="RAM" quantum="16M"/>
|
||||
@@ -15,10 +16,12 @@ append config {
|
||||
<libc stdout="/dev/log" stderr="/dev/log" socket="/socket"/>
|
||||
</config>
|
||||
</start>
|
||||
-->
|
||||
<start name="netty-server-8080">
|
||||
<binary name="test-netty_tcp"/>
|
||||
<resource name="RAM" quantum="16M"/>
|
||||
<config ld_verbose="yes" mode="server" port="8080" nonblock="false">
|
||||
<resource name="RAM" quantum="32G"/>
|
||||
<affinity xpos="1" ypos="0" width="63" height="1"/>
|
||||
<config ld_verbose="yes" mode="server" port="8080" read_write="yes" nonblock="false">
|
||||
<vfs>
|
||||
<dir name="dev"> <log/> </dir>
|
||||
<dir name="socket"> <fs/> </dir>
|
||||
@@ -58,7 +61,7 @@ append config {
|
||||
}
|
||||
|
||||
install_config $config
|
||||
build_boot_image { test-netty_tcp }
|
||||
build_boot_image { vfs_lwip.lib.so test-netty_tcp }
|
||||
run_genode_until forever
|
||||
|
||||
# vi: set ft=tcl :
|
||||
|
||||
@@ -3,6 +3,7 @@ source ${genode_dir}/repos/libports/run/netty.inc
|
||||
build { test/netty/tcp }
|
||||
|
||||
append config {
|
||||
<!--
|
||||
<start name="netty-server-80">
|
||||
<binary name="test-netty_tcp"/>
|
||||
<resource name="RAM" quantum="8M"/>
|
||||
@@ -15,10 +16,11 @@ append config {
|
||||
<libc stdout="/dev/log" stderr="/dev/log" socket="/socket"/>
|
||||
</config>
|
||||
</start>
|
||||
-->
|
||||
<start name="netty-server-8080">
|
||||
<binary name="test-netty_tcp"/>
|
||||
<resource name="RAM" quantum="8M"/>
|
||||
<config ld_verbose="yes" mode="server" port="8080" nonblock="false">
|
||||
<resource name="RAM" quantum="512M"/>
|
||||
<config ld_verbose="yes" mode="server" port="8080" nonblock="no" read_write="yes">
|
||||
<vfs>
|
||||
<dir name="dev"> <log/> </dir>
|
||||
<dir name="socket"> <fs/> </dir>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
/* Local includes */
|
||||
#include <netty.h>
|
||||
|
||||
#include <thread>
|
||||
|
||||
namespace Netty { struct Tcp; }
|
||||
|
||||
@@ -59,56 +59,69 @@ void Netty::Tcp::server(int const sd, bool const nonblock, bool const read_write
|
||||
Genode::log("okay, accept will not block");
|
||||
}
|
||||
|
||||
Genode::log("test in ", nonblock ? "non-blocking" : "blocking", " mode");
|
||||
//Genode::log("test in ", nonblock ? "non-blocking" : "blocking", " mode");
|
||||
|
||||
int const cd = accept(sd, pcaddr, &scaddr);
|
||||
Genode::log("cd=", cd);
|
||||
//Genode::log("cd=", cd);
|
||||
if (cd == -1) DIE("accept");
|
||||
|
||||
getnames(cd);
|
||||
//getnames(cd);
|
||||
|
||||
size_t count = 0;
|
||||
static char data[64*1024];
|
||||
|
||||
if (nonblock) nonblocking(cd);
|
||||
|
||||
while (true) {
|
||||
int ret = read_write
|
||||
? read(cd, data, sizeof(data))
|
||||
: recv(cd, data, sizeof(data), 0);
|
||||
auto con_handler = std::thread{[cd, read_write, nonblock]()
|
||||
{
|
||||
size_t count = 0;
|
||||
static char data[64*1024];
|
||||
while (true)
|
||||
{
|
||||
//GENODE_LOG_TSC_NAMED(10, "netty_read");
|
||||
int ret = read_write
|
||||
? read(cd, data, sizeof(data))
|
||||
: recv(cd, data, sizeof(data), 0);
|
||||
|
||||
if (ret == 0) {
|
||||
Genode::log("experienced EOF");
|
||||
break;
|
||||
}
|
||||
if (ret == 0)
|
||||
{
|
||||
// Genode::log("experienced EOF");
|
||||
break;
|
||||
}
|
||||
|
||||
if (ret > 0) {
|
||||
/* echo received data */
|
||||
ret = read_write
|
||||
? write(cd, data, ret)
|
||||
: send(cd, data, ret, 0);
|
||||
if (ret == -1) DIE(read_write ? "write" : "send");
|
||||
if (ret > 0)
|
||||
{
|
||||
//GENODE_LOG_TSC_NAMED(10, "netty_write");
|
||||
/* echo received data */
|
||||
ret = read_write
|
||||
? write(cd, data, ret)
|
||||
: send(cd, data, ret, 0);
|
||||
if (ret == -1)
|
||||
DIE(read_write ? "write" : "send");
|
||||
|
||||
count += ret;
|
||||
continue;
|
||||
}
|
||||
count += ret;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!nonblock || errno != EAGAIN)
|
||||
DIE(read_write ? "read" : "recv");
|
||||
if (!nonblock || errno != EAGAIN)
|
||||
DIE(read_write ? "read" : "recv");
|
||||
|
||||
Genode::log("block in select because of EAGAIN");
|
||||
fd_set read_fds; FD_ZERO(&read_fds); FD_SET(cd, &read_fds);
|
||||
ret = select(cd + 1, &read_fds, nullptr, nullptr, nullptr);
|
||||
if (ret == -1) DIE("select");
|
||||
}
|
||||
Genode::log("block in select because of EAGAIN");
|
||||
fd_set read_fds;
|
||||
FD_ZERO(&read_fds);
|
||||
FD_SET(cd, &read_fds);
|
||||
ret = select(cd + 1, &read_fds, nullptr, nullptr, nullptr);
|
||||
if (ret == -1)
|
||||
DIE("select");
|
||||
|
||||
Genode::log("echoed ", count, " bytes");
|
||||
ret = shutdown(cd, SHUT_RDWR);
|
||||
if (ret == -1) DIE("shutdown");
|
||||
|
||||
ret = shutdown(cd, SHUT_RDWR);
|
||||
if (ret == -1) DIE("shutdown");
|
||||
ret = close(cd);
|
||||
if (ret == -1) DIE("close");
|
||||
}
|
||||
}};
|
||||
con_handler.detach();
|
||||
|
||||
ret = close(cd);
|
||||
if (ret == -1) DIE("close");
|
||||
//Genode::log("echoed ", count, " bytes");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
TARGET = test-netty_tcp
|
||||
SRC_CC = main.cc netty.cc
|
||||
LIBS = base libc
|
||||
LIBS = base libc stdcxx
|
||||
|
||||
INC_DIR += $(PRG_DIR)/..
|
||||
|
||||
|
||||
Reference in New Issue
Block a user