| 809 | } |
| 810 | |
| 811 | void* Writer(void* void_arg) { |
| 812 | WriterArg* arg = static_cast<WriterArg*>(void_arg); |
| 813 | brpc::SocketUniquePtr sock; |
| 814 | if (brpc::Socket::Address(arg->socket_id, &sock) < 0) { |
| 815 | printf("Fail to address SocketId=%" PRIu64 "\n", arg->socket_id); |
| 816 | return NULL; |
| 817 | } |
| 818 | char buf[32]; |
| 819 | for (size_t i = 0; i < arg->times; ++i) { |
| 820 | snprintf(buf, sizeof(buf), "%0" BAIDU_SYMBOLSTR(NUMBER_WIDTH) "lu", |
| 821 | i + arg->offset); |
| 822 | butil::IOBuf src; |
| 823 | src.append(buf); |
| 824 | if (sock->Write(&src) != 0) { |
| 825 | if (errno == brpc::EOVERCROWDED) { |
| 826 | // The buf is full, sleep a while and retry. |
| 827 | bthread_usleep(1000); |
| 828 | --i; |
| 829 | continue; |
| 830 | } |
| 831 | printf("Fail to write into SocketId=%" PRIu64 ", %s\n", |
| 832 | arg->socket_id, berror()); |
| 833 | break; |
| 834 | } |
| 835 | } |
| 836 | return NULL; |
| 837 | } |
| 838 | |
| 839 | TEST_F(SocketTest, multi_threaded_write) { |
| 840 | const size_t REP = 20000; |
nothing calls this directly
no test coverage detected