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

Function on_connect

test/libhttp/http.cpp:82–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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…