| 152 | } |
| 153 | |
| 154 | int main(int argc, char* argv[]) |
| 155 | { |
| 156 | int ch; |
| 157 | bool use_thread = false; |
| 158 | |
| 159 | while ((ch = getopt(argc, argv, "ht")) > 0) { |
| 160 | switch (ch) { |
| 161 | case 'h': |
| 162 | usage(argv[0]); |
| 163 | return (0); |
| 164 | case 't': |
| 165 | use_thread = true; |
| 166 | break; |
| 167 | default: |
| 168 | break; |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | acl::acl_cpp_init(); |
| 173 | |
| 174 | acl::aio_handle handle; |
| 175 | |
| 176 | acl::ipc_server* server = new test_server(); |
| 177 | |
| 178 | // ʹ��Ϣ���������� 127.0.0.1 �ĵ�ַ |
| 179 | if (!server->open(&handle, "127.0.0.1:0")) { |
| 180 | delete server; |
| 181 | std::cout << "open server error!" << std::endl; |
| 182 | getchar(); |
| 183 | return 1; |
| 184 | } |
| 185 | |
| 186 | char addr[256]; |
| 187 | #ifdef WIN32 |
| 188 | _snprintf(addr, sizeof(addr), "%s", server->get_addr()); |
| 189 | #else |
| 190 | snprintf(addr, sizeof(addr), "%s", server->get_addr()); |
| 191 | #endif |
| 192 | |
| 193 | if (use_thread) { |
| 194 | acl_pthread_t tid; |
| 195 | acl_pthread_create(&tid, NULL, thread_callback, addr); |
| 196 | } else { |
| 197 | client_main(&handle, addr); |
| 198 | } |
| 199 | |
| 200 | while (true) { |
| 201 | if (!handle.check()) { |
| 202 | std::cout << "stop now!" << std::endl; |
| 203 | break; |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | delete server; |
| 208 | handle.check(); |
| 209 | |
| 210 | std::cout << "server stopped, enter any key to exit ..." << std::endl; |
| 211 | getchar(); |
nothing calls this directly
no test coverage detected
searching dependent graphs…