MCPcopy Create free account
hub / github.com/apache/brpc / Writer

Function Writer

test/brpc_socket_unittest.cpp:811–837  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

809}
810
811void* 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
839TEST_F(SocketTest, multi_threaded_write) {
840 const size_t REP = 20000;

Callers

nothing calls this directly

Calls 5

snprintfFunction · 0.85
bthread_usleepFunction · 0.85
berrorFunction · 0.85
appendMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected