Mir

Merge lp:~afrantzis/mir/fix-lp-1163368 into lp:~mir-team/mir/trunk

Proposed by Alexandros Frantzis
Status: Merged
Approved by: Alan Griffiths
Approved revision: no longer in the source branch.
Merged at revision: 552
Proposed branch: lp:~afrantzis/mir/fix-lp-1163368
Merge into: lp:~mir-team/mir/trunk
Diff against target: 27 lines (+14/-3)
1 file modified
src/server/signal_dispatcher.cpp (+14/-3)
To merge this branch: bzr merge lp:~afrantzis/mir/fix-lp-1163368
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Alan Griffiths Approve
Review via email: mp+156625@code.launchpad.net

Commit message

server: Properly handle EOF when reading from SignalDispatcher socket

Description of the change

server: Properly handle EOF when reading from SignalDispatcher socket

The handling is not ideal (e.g. we use an exception for a non-exceptional situation (EOF)) but certainly an improvement... and it doesn't crash :)

To post a comment you must log in.
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

good

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/server/signal_dispatcher.cpp'
2--- src/server/signal_dispatcher.cpp 2013-03-28 12:13:18 +0000
3+++ src/server/signal_dispatcher.cpp 2013-04-02 16:11:38 +0000
4@@ -60,9 +60,20 @@
5
6 int read_signal_from(SocketIdentifier id)
7 {
8- int signal;
9- if (::read(sockets[id], &signal, sizeof(signal)) < 0)
10- throw std::runtime_error("Problem reading_from socket");
11+ int signal{0};
12+ ssize_t nread{0};
13+
14+ while (nread <= 0)
15+ {
16+ nread = ::read(sockets[id], &signal, sizeof(signal));
17+
18+ if (nread == 0)
19+ throw std::runtime_error("Write end of socket has been closed");
20+ else if (nread > 0 && nread < static_cast<ssize_t>(sizeof(signal)))
21+ throw std::runtime_error("Incomplete message retrieved");
22+ else if (nread < 0 && errno != EINTR)
23+ throw std::runtime_error("Problem reading from socket");
24+ }
25
26 return signal;
27 }

Subscribers

People subscribed via source and target branches