MCPcopy Create free account
hub / github.com/acl-dev/acl / on_connect

Function on_connect

lib_protocol/samples/http_aio2/http_aio.cpp:76–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74}
75
76static int on_connect(const ACL_ASTREAM_CTX *context)
77{
78 ACL_ASTREAM *stream = acl_astream_get_conn(context);
79// const ACL_SOCKADDR *addr = acl_astream_get_serv_addr(context);
80
81 if (stream == NULL) {
82// int err = acl_last_error();
83// printf("connect %s failed, errno=%d, %s\r\n", addr, err,
84// err < 0 ? acl_dns_serror(err) : acl_last_serror());
85 __stop = true;
86 return -1;
87 }
88
89// printf(">>>> connect %s ok!\r\n", addr);
90
91 CTX *ctx = (CTX*) acl_mycalloc(1, sizeof(CTX));
92 ctx->stream = stream;
93
94 // ���� HTTP ����ͷ
95 ctx->hdr_req = http_hdr_req_create("/", "GET", "HTTP/1.1");
96 // ���ö�����ģʽ
97 http_hdr_entry_replace(&ctx->hdr_req->hdr, "Connection", "Close", 1);
98 // ������������
99 http_hdr_put_str(&ctx->hdr_req->hdr, "Content-Type", "text/plain");
100 // ���������ֶ�
101 http_hdr_put_str(&ctx->hdr_req->hdr, "Host", __server_addr);
102
103 // ���ö���ʱ�ص�����
104 acl_aio_add_timeo_hook(stream, on_timeout, ctx);
105 // ���ùرջص�����
106 acl_aio_add_close_hook(stream, on_close, ctx);
107
108 // ������̬�ڴ沢�� HTTP ����ͷ����������
109 ACL_VSTRING *buf = acl_vstring_alloc(1024);
110 http_hdr_build_request(ctx->hdr_req, buf);
111
112 // ���� HTTP ����
113 acl_aio_writen(stream, acl_vstring_str(buf), ACL_VSTRING_LEN(buf));
114
115 // �ͷŶ�̬�ڴ�
116 acl_vstring_free(buf);
117
118 // ���� HTTP ��Ӧ����
119 ctx->hdr_res = http_hdr_res_new();
120
121 // �첽��ȡ�������Ӧ�� HTTP ͷ
122 http_hdr_res_get_async(ctx->hdr_res, stream, on_http_hdr, ctx, 0);
123
124 return 0;
125}
126
127static void usage(const char *procname)
128{

Callers

nothing calls this directly

Calls 12

acl_astream_get_connFunction · 0.85
http_hdr_req_createFunction · 0.85
http_hdr_entry_replaceFunction · 0.85
http_hdr_put_strFunction · 0.85
acl_aio_add_timeo_hookFunction · 0.85
acl_aio_add_close_hookFunction · 0.85
acl_vstring_allocFunction · 0.85
http_hdr_build_requestFunction · 0.85
acl_aio_writenFunction · 0.85
acl_vstring_freeFunction · 0.85
http_hdr_res_newFunction · 0.85
http_hdr_res_get_asyncFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…