pro: Add a little userland utility for testing ProtocolServer

This commit is contained in:
Andreas Kling 2019-11-23 21:48:39 +01:00
parent fd4349a9f2
commit 88c5126fa7
2 changed files with 30 additions and 1 deletions

View file

@ -19,7 +19,7 @@ clean:
$(APPS) : % : %.o $(OBJS)
@echo "LD $@"
@$(LD) -o $@ $(LDFLAGS) $< -lc -lhtml -lgui -ldraw -laudio -lipc -lthread -lcore -lpcidb -lmarkdown -lpthread
@$(LD) -o $@ $(LDFLAGS) $< -lc -lhtml -lgui -ldraw -laudio -lipc -lthread -lcore -lpcidb -lmarkdown -lpthread -lprotocol -lipc
%.o: %.cpp
@echo "CXX $<"

29
Userland/pro.cpp Normal file
View file

@ -0,0 +1,29 @@
#include <LibCore/CEventLoop.h>
#include <LibProtocol/Client.h>
#include <stdio.h>
int main(int argc, char** argv)
{
(void)argc;
(void)argv;
CEventLoop loop;
auto protocol_client = LibProtocol::Client::construct();
protocol_client->handshake();
printf("supports HTTP? %u\n", protocol_client->is_supported_protocol("http"));
printf(" supports FTP? %u\n", protocol_client->is_supported_protocol("ftp"));
protocol_client->on_download_finish = [&](i32 download_id, bool success) {
printf("download %d finished, success=%u\n", download_id, success);
loop.quit(0);
};
protocol_client->on_download_progress = [&](i32 download_id, u32 total_size, u32 downloaded_size) {
printf("download %d progress: %u / %u\n", download_id, downloaded_size, total_size);
};
i32 download_id = protocol_client->start_download("http://192.168.1.21/");
printf("started download with id %d\n", download_id);
return loop.exec();
}