| 930 | } |
| 931 | |
| 932 | void* FastWriter(void* void_arg) { |
| 933 | WriterArg* arg = static_cast<WriterArg*>(void_arg); |
| 934 | brpc::SocketUniquePtr sock; |
| 935 | if (brpc::Socket::Address(arg->socket_id, &sock) < 0) { |
| 936 | printf("Fail to address SocketId=%" PRIu64 "\n", arg->socket_id); |
| 937 | return NULL; |
| 938 | } |
| 939 | char buf[] = "hello reader side!"; |
| 940 | int64_t begin_ts = butil::cpuwide_time_us(); |
| 941 | int64_t nretry = 0; |
| 942 | size_t c = 0; |
| 943 | for (; c < arg->times; ++c) { |
| 944 | butil::IOBuf src; |
| 945 | src.append(buf, 16); |
| 946 | if (sock->Write(&src) != 0) { |
| 947 | if (errno == brpc::EOVERCROWDED) { |
| 948 | // The buf is full, sleep a while and retry. |
| 949 | bthread_usleep(1000); |
| 950 | --c; |
| 951 | ++nretry; |
| 952 | continue; |
| 953 | } |
| 954 | printf("Fail to write into SocketId=%" PRIu64 ", %s\n", |
| 955 | arg->socket_id, berror()); |
| 956 | break; |
| 957 | } |
| 958 | } |
| 959 | int64_t end_ts = butil::cpuwide_time_us(); |
| 960 | int64_t total_time = end_ts - begin_ts; |
| 961 | printf("total=%ld count=%ld nretry=%ld\n", |
| 962 | (long)total_time * 1000/ c, (long)c, (long)nretry); |
| 963 | return NULL; |
| 964 | } |
| 965 | |
| 966 | struct ReaderArg { |
| 967 | int fd; |
nothing calls this directly
no test coverage detected