mirror of
https://github.com/scylladb/scylladb.git
synced 2026-04-22 09:30:45 +00:00
tests: add tcp test
Simple echo server on the now famous port 10000.
This commit is contained in:
3
build.mk
3
build.mk
@@ -21,6 +21,7 @@ CXXFLAGS += -I $(src)
|
||||
CXXFLAGS += -Wl,--no-as-needed
|
||||
|
||||
tests = tests/test-reactor tests/fileiotest tests/virtiotest tests/l3_test tests/ip_test tests/timertest
|
||||
tests += tests/tcp_test
|
||||
|
||||
link = mkdir -p $(@D) && $(CXX) $(CXXFLAGS) -o $@ $^
|
||||
compile = mkdir -p $(@D) && $(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||
@@ -51,6 +52,8 @@ tests/l3_test: tests/l3_test.o net/virtio.o core/reactor.o net/net.o net/ip.o ne
|
||||
|
||||
tests/ip_test: tests/ip_test.o net/virtio.o core/reactor.o net/net.o net/ip.o net/arp.o net/ethernet.o
|
||||
|
||||
tests/tcp_test: tests/tcp_test.o net/virtio.o core/reactor.o net/net.o net/ip.o net/arp.o net/ethernet.o
|
||||
|
||||
tests/timertest: tests/timertest.o core/reactor.o
|
||||
|
||||
-include $(shell find -name '*.d')
|
||||
|
||||
43
tests/tcp_test.cc
Normal file
43
tests/tcp_test.cc
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Cloudius Systems, Ltd.
|
||||
*/
|
||||
|
||||
#include "net/ip.hh"
|
||||
#include "net/virtio.hh"
|
||||
|
||||
using namespace net;
|
||||
|
||||
struct tcp_test {
|
||||
ipv4& inet;
|
||||
using tcp = net::tcp<ipv4_traits>;
|
||||
struct connection {
|
||||
tcp::connection tcp_conn;
|
||||
explicit connection(tcp::connection tc) : tcp_conn(std::move(tc)) {}
|
||||
void run() {
|
||||
tcp_conn.receive().then([this] (packet p) {
|
||||
tcp_conn.send(std::move(p));
|
||||
run();
|
||||
});
|
||||
}
|
||||
};
|
||||
tcp_test(ipv4& inet) : inet(inet) {}
|
||||
void run() {
|
||||
inet.get_tcp().listen(10000).then([this] (tcp::connection conn) {
|
||||
(new connection(std::move(conn)))->run();
|
||||
run();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
int main(int ac, char** av) {
|
||||
auto vnet = create_virtio_net_device("tap0");
|
||||
interface netif(std::move(vnet));
|
||||
netif.run();
|
||||
ipv4 inet(&netif);
|
||||
inet.set_host_address(ipv4_address(0xc0a87a02));
|
||||
tcp_test tt(inet);
|
||||
the_reactor.start().then([&tt] { tt.run(); });
|
||||
the_reactor.run();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user