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

Function main

lib_acl_cpp/samples/aio/aio_echo/main.cpp:122–184  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

120}
121
122int main(int argc, char* argv[])
123{
124 bool use_kernel = false;
125 acl::string addr("127.0.0.1:9001");
126 int ch;
127
128 while ((ch = getopt(argc, argv, "hks:")) > 0) {
129 switch (ch) {
130 case 'h':
131 usage(argv[0]);
132 return 0;
133 case 's':
134 addr = optarg;
135 break;
136 case 'k':
137 use_kernel = true;
138 break;
139 default:
140 break;
141 }
142 }
143
144 // ��ʼ��ACL��(��������WIN32��һ��Ҫ���ô˺�������UNIXƽ̨�¿ɲ�����)
145 acl::acl_cpp_init();
146
147 // �����첽���������
148 acl::aio_handle handle(use_kernel ? acl::ENGINE_KERNEL : acl::ENGINE_SELECT);
149
150 // ���������첽��
151 acl::aio_listen_stream* sstream = new acl::aio_listen_stream(&handle);
152
153 // ����ָ���ĵ�ַ
154 if (!sstream->open(addr)) {
155 std::cout << "open " << addr.c_str() << " error!" << std::endl;
156 sstream->close();
157 // XXX: Ϊ�˱�֤�ܹرռ�������Ӧ�ڴ˴��� check һ��
158 handle.check();
159
160 getchar();
161 return 1;
162 }
163
164 // �����ص�����󣬵��������ӵ���ʱ�Զ����ô������Ļص�����
165 io_accept_callback callback;
166 sstream->add_accept_callback(&callback);
167 std::cout << "Listen: " << addr.c_str() << " ok!" << std::endl;
168
169 while (true) {
170 // ������� false ���ʾ���ټ�������Ҫ�˳�
171 if (!handle.check()) {
172 std::cout << "aio_server stop now ..." << std::endl;
173 break;
174 }
175 }
176
177 // �رռ��������ͷ�������
178 sstream->close();
179

Callers

nothing calls this directly

Calls 8

acl_cpp_initFunction · 0.85
add_accept_callbackMethod · 0.80
usageFunction · 0.70
getoptFunction · 0.50
openMethod · 0.45
c_strMethod · 0.45
closeMethod · 0.45
checkMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…