-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathstep19.cpp
40 lines (35 loc) · 1.06 KB
/
step19.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "co_async/debug.hpp"
#include "co_async/task.hpp"
#include "co_async/generator.hpp"
#include "co_async/timer_loop.hpp"
#include "co_async/epoll_loop.hpp"
#include "co_async/async_loop.hpp"
#include "co_async/when_any.hpp"
#include "co_async/when_all.hpp"
#include "co_async/limit_timeout.hpp"
#include "co_async/and_then.hpp"
#include "co_async/socket.hpp"
#include <cstring>
#include <termios.h>
[[gnu::constructor]] static void disable_canon() {
struct termios tc;
tcgetattr(STDIN_FILENO, &tc);
tc.c_lflag &= ~ICANON;
tc.c_lflag &= ~ECHO;
tcsetattr(STDIN_FILENO, TCSANOW, &tc);
}
using namespace std::literals;
co_async::AsyncLoop loop;
co_async::Task<> amain() {
auto sock = co_await create_tcp_client(loop, co_async::socket_address(co_async::ip_address("142857.red"), 80));
co_await write_file(loop, sock, "GET / HTTP/1.1\r\n\r\n"sv);
char buf[4096];
auto len = co_await read_file(loop, sock, buf);
std::string_view res(buf, len);
std::cout << res;
co_return;
}
int main() {
run_task(loop, amain());
return 0;
}