~mir-team/mir/liberate-historical-pointer-coordinates

« back to all changes in this revision

Viewing changes to src/server/frontend/socket_messenger.cpp

server: Work around unresponsive clients causing the server to hang (LP: #1350207). Fixes: https://bugs.launchpad.net/bugs/1350207.

Approved by Daniel van Vugt, Alberto Aguirre, Kevin DuBois, Chris Halse Rogers, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
mfd::SocketMessenger::SocketMessenger(std::shared_ptr<ba::local::stream_protocol::socket> const& socket)
37
37
    : socket(socket)
38
38
{
 
39
    // Make the socket non-blocking to avoid hanging the server when a client
 
40
    // is unresponsive. Also increase the send buffer size to 64KiB to allow
 
41
    // more leeway for transient client freezes.
 
42
    // See https://bugs.launchpad.net/mir/+bug/1350207
 
43
    // TODO: Rework the messenger to support asynchronous sends
 
44
    socket->non_blocking(true);
 
45
    boost::asio::socket_base::send_buffer_size option(64*1024);
 
46
    socket->set_option(option);
39
47
}
40
48
 
41
49
mf::SessionCredentials mfd::SocketMessenger::creator_creds() const
143
151
    ba::mutable_buffers_1 const& buffer)
144
152
{
145
153
    bs::error_code e;
146
 
    boost::asio::read(
147
 
         *socket,
148
 
         buffer,
149
 
         boost::asio::transfer_exactly(ba::buffer_size(buffer)),
150
 
         e);
 
154
    size_t nread = 0;
 
155
 
 
156
    while (nread < ba::buffer_size(buffer))
 
157
    {
 
158
        nread += boost::asio::read(
 
159
             *socket,
 
160
             ba::mutable_buffers_1{buffer + nread},
 
161
             e);
 
162
 
 
163
        if (e && e != ba::error::would_block)
 
164
            break;
 
165
    }
 
166
 
151
167
    return e;
152
168
}
153
169