| 48 | } |
| 49 | |
| 50 | int main(int argc, char* argv[]) |
| 51 | { |
| 52 | int ch, cocurrent = 4, count = 1000, len = 10; |
| 53 | acl::string addr("127.0.0.1:8887"); |
| 54 | |
| 55 | while ((ch = getopt(argc, argv, "hs:c:n:l:")) > 0) { |
| 56 | switch (ch) { |
| 57 | case 'h': |
| 58 | usage(argv[0]); |
| 59 | return 0; |
| 60 | case 's': |
| 61 | addr = optarg; |
| 62 | break; |
| 63 | case 'c': |
| 64 | cocurrent = atoi(optarg); |
| 65 | break; |
| 66 | case 'n': |
| 67 | count = atoi(optarg); |
| 68 | break; |
| 69 | case 'l': |
| 70 | len = atoi(optarg); |
| 71 | break; |
| 72 | default: |
| 73 | usage(argv[0]); |
| 74 | return 0; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | acl::tcp_pool pool(addr, count); |
| 79 | |
| 80 | std::vector<acl::thread*> threads; |
| 81 | for (int i = 0; i < cocurrent; i++) { |
| 82 | acl::thread* thread = new client_thread(pool, count, len); |
| 83 | thread->set_detachable(false); |
| 84 | threads.push_back(thread); |
| 85 | thread->start(); |
| 86 | } |
| 87 | |
| 88 | for (std::vector<acl::thread*>::iterator it = threads.begin(); |
| 89 | it != threads.end(); ++it) { |
| 90 | |
| 91 | (*it)->wait(); |
| 92 | delete *it; |
| 93 | } |
| 94 | |
| 95 | return 0; |
| 96 | } |