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

Method DoWrite

src/brpc/socket.cpp:1868–1930  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1866}
1867
1868ssize_t Socket::DoWrite(WriteRequest* req) {
1869 // Group butil::IOBuf in the list into a batch array.
1870 butil::IOBuf* data_list[DATA_LIST_MAX];
1871 size_t ndata = 0;
1872 for (WriteRequest* p = req; p != NULL && ndata < DATA_LIST_MAX;
1873 p = p->next) {
1874 data_list[ndata++] = &p->data;
1875 if (p->need_shutdown_write()) {
1876 // Write WriteRequest until shutdown write.
1877 _is_write_shutdown = true;
1878 break;
1879 }
1880 }
1881
1882 if (ssl_state() == SSL_OFF) {
1883 // Write IOBuf in the batch array into the fd.
1884 if (_conn) {
1885 return _conn->CutMessageIntoFileDescriptor(fd(), data_list, ndata);
1886 } else {
1887 return _transport->CutFromIOBufList(data_list, ndata);
1888 }
1889 }
1890
1891 CHECK_EQ(SSL_CONNECTED, ssl_state());
1892 if (_conn) {
1893 // TODO: Separate SSL stuff from SocketConnection
1894 BAIDU_SCOPED_LOCK(_ssl_session_mutex);
1895 return _conn->CutMessageIntoSSLChannel(_ssl_session, data_list, ndata);
1896 }
1897 int ssl_error = 0;
1898 ssize_t nw = 0;
1899 {
1900 BAIDU_SCOPED_LOCK(_ssl_session_mutex);
1901 nw = butil::IOBuf::cut_multiple_into_SSL_channel(_ssl_session, data_list, ndata, &ssl_error);
1902 }
1903 switch (ssl_error) {
1904 case SSL_ERROR_NONE:
1905 break;
1906
1907 case SSL_ERROR_WANT_READ:
1908 // Disable renegotiation
1909 errno = EPROTO;
1910 return -1;
1911
1912 case SSL_ERROR_WANT_WRITE:
1913 errno = EAGAIN;
1914 break;
1915
1916 default: {
1917 const unsigned long e = ERR_get_error();
1918 if (e != 0) {
1919 LOG(WARNING) << "Fail to write into ssl_fd=" << fd() << ": "
1920 << SSLError(e);
1921 errno = ESSL;
1922 } else {
1923 // System error with corresponding errno set
1924 PLOG(WARNING) << "Fail to write into ssl_fd=" << fd();
1925 }

Callers 1

KeepWriteMethod · 0.80

Calls 6

ssl_stateFunction · 0.85
fdFunction · 0.85
SSLErrorClass · 0.85
CutFromIOBufListMethod · 0.45

Tested by

no test coverage detected