1. 同步与异步的区别?
阻塞非阻塞
2. 如何设计?
思想: 客户端发送n多请求给服务器,然后客户端自己起一个线程,去轮询服务器发送回来的应答,好像这个客户端的线程起了一个服务一样,等待服务器的应答消息,客户端使用了epoll来管理这些IO。
3.部分代码 -- 使用epoll来管理IO
struct async_context *http_async_client_init(void) {
int epfd = epoll_create(1); //
if (epfd < 0) return NULL;
struct async_context *ctx = calloc(1, sizeof(struct async_context));
if (ctx == NULL) {
close(epfd);
return NULL;
}
ctx->epfd = epfd;
int ret = pthread_create(&