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

Method Create

src/brpc/stream.cpp:78–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76}
77
78int Stream::Create(const StreamOptions &options,
79 const StreamSettings *remote_settings,
80 StreamId *id, bool parse_rpc_response) {
81 Stream* s = new Stream();
82 s->_host_socket = NULL;
83 s->_fake_socket_weak_ref = NULL;
84 s->_connected = false;
85 s->_options = options;
86 s->_closed = false;
87 s->_error_code = 0;
88 s->_cur_buf_size = options.max_buf_size > 0 ? options.max_buf_size : 0;
89 if (options.max_buf_size > 0 && options.min_buf_size > options.max_buf_size) {
90 // set 0 if min_buf_size is invalid.
91 s->_options.min_buf_size = 0;
92 LOG(WARNING) << "options.min_buf_size is larger than options.max_buf_size, it will be set to 0.";
93 }
94 if (FLAGS_socket_max_streams_unconsumed_bytes > 0 && s->_options.min_buf_size > 0) {
95 s->_cur_buf_size = s->_options.min_buf_size;
96 }
97
98 if (remote_settings != NULL) {
99 s->_remote_settings.MergeFrom(*remote_settings);
100 }
101 s->_parse_rpc_response = parse_rpc_response;
102 if (bthread_id_list_init(&s->_writable_wait_list, 8, 8/*FIXME*/)) {
103 delete s;
104 return -1;
105 }
106 bthread::ExecutionQueueOptions q_opt;
107 q_opt.bthread_attr
108 = FLAGS_usercode_in_pthread ? BTHREAD_ATTR_PTHREAD : BTHREAD_ATTR_NORMAL;
109 if (bthread::execution_queue_start(&s->_consumer_queue, &q_opt, Consume, s) != 0) {
110 LOG(FATAL) << "Fail to create ExecutionQueue";
111 delete s;
112 return -1;
113 }
114 SocketOptions sock_opt;
115 sock_opt.conn = s;
116 SocketId fake_sock_id;
117 if (Socket::Create(sock_opt, &fake_sock_id) != 0) {
118 s->BeforeRecycle(NULL);
119 return -1;
120 }
121 SocketUniquePtr ptr;
122 CHECK_EQ(0, Socket::Address(fake_sock_id, &ptr));
123 s->_fake_socket_weak_ref = ptr.get();
124 s->_id = fake_sock_id;
125 *id = s->id();
126 return 0;
127}
128
129void Stream::BeforeRecycle(Socket *) {
130 // No one holds reference now, so we don't need lock here

Callers

nothing calls this directly

Calls 6

bthread_id_list_initFunction · 0.85
execution_queue_startFunction · 0.85
MergeFromMethod · 0.45
BeforeRecycleMethod · 0.45
getMethod · 0.45
idMethod · 0.45

Tested by

no test coverage detected