wind+libos+libui: Handle interrupted reads properly
This commit is contained in:
parent
b95d495815
commit
1b683ffd08
@ -102,7 +102,7 @@ namespace os
|
|||||||
{
|
{
|
||||||
u8 response_id;
|
u8 response_id;
|
||||||
auto rc = client.recv_typed(response_id);
|
auto rc = client.recv_typed(response_id);
|
||||||
if (rc.has_error() && rc.error() == EAGAIN) continue;
|
if (rc.has_error() && (rc.error() == EAGAIN || rc.error() == EINTR)) continue;
|
||||||
|
|
||||||
if (response_id == 0) // Error result
|
if (response_id == 0) // Error result
|
||||||
{
|
{
|
||||||
@ -110,7 +110,7 @@ namespace os
|
|||||||
{
|
{
|
||||||
int code;
|
int code;
|
||||||
rc = client.recv_typed(code);
|
rc = client.recv_typed(code);
|
||||||
if (rc.has_error() && rc.error() == EAGAIN) continue;
|
if (rc.has_error() && (rc.error() == EAGAIN || rc.error() == EINTR)) continue;
|
||||||
return err(code);
|
return err(code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -126,7 +126,7 @@ namespace os
|
|||||||
{
|
{
|
||||||
ResponseType response;
|
ResponseType response;
|
||||||
rc = client.recv_typed(response);
|
rc = client.recv_typed(response);
|
||||||
if (rc.has_error() && rc.error() == EAGAIN) continue;
|
if (rc.has_error() && (rc.error() == EAGAIN || rc.error() == EINTR)) continue;
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,8 @@ namespace os::IPC
|
|||||||
if (rc.has_error())
|
if (rc.has_error())
|
||||||
{
|
{
|
||||||
if (rc.error() == EAGAIN) return {}; // No messages, and the caller does not want us to block.
|
if (rc.error() == EAGAIN) return {}; // No messages, and the caller does not want us to block.
|
||||||
|
if (rc.error() == EINTR)
|
||||||
|
return {}; // Let the caller check for anything having happened because a signal handler ran.
|
||||||
return rc.release_error();
|
return rc.release_error();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,6 +33,8 @@ namespace os::IPC
|
|||||||
if (rc.has_error())
|
if (rc.has_error())
|
||||||
{
|
{
|
||||||
if (rc.error() == EAGAIN) return {}; // No messages, and the caller does not want us to block.
|
if (rc.error() == EAGAIN) return {}; // No messages, and the caller does not want us to block.
|
||||||
|
if (rc.error() == EINTR)
|
||||||
|
return {}; // Let the caller check for anything having happened because a signal handler ran.
|
||||||
return rc.release_error();
|
return rc.release_error();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,13 +88,26 @@ namespace ui
|
|||||||
return window->ptr();
|
return window->ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define READ_MESSAGE(request) \
|
||||||
|
do { \
|
||||||
|
auto rc = m_client->recv_typed(request); \
|
||||||
|
if (rc.has_error()) \
|
||||||
|
{ \
|
||||||
|
if (rc.error() == EAGAIN) { continue; } \
|
||||||
|
if (rc.error() == EINTR) { continue; } \
|
||||||
|
else \
|
||||||
|
return rc.release_error(); \
|
||||||
|
} \
|
||||||
|
break; \
|
||||||
|
} while (true)
|
||||||
|
|
||||||
Result<void> App::handle_ipc_event(u8 id)
|
Result<void> App::handle_ipc_event(u8 id)
|
||||||
{
|
{
|
||||||
switch (id)
|
switch (id)
|
||||||
{
|
{
|
||||||
case WINDOW_CLOSE_REQUEST_ID: {
|
case WINDOW_CLOSE_REQUEST_ID: {
|
||||||
WindowCloseRequest request;
|
WindowCloseRequest request;
|
||||||
TRY(m_client->recv_typed(request));
|
READ_MESSAGE(request);
|
||||||
os::eprintln("ui: Window close request from server! Shall comply.");
|
os::eprintln("ui: Window close request from server! Shall comply.");
|
||||||
auto* window = find_window(request.window);
|
auto* window = find_window(request.window);
|
||||||
window->close();
|
window->close();
|
||||||
@ -102,7 +115,7 @@ namespace ui
|
|||||||
}
|
}
|
||||||
case MOUSE_EVENT_REQUEST_ID: {
|
case MOUSE_EVENT_REQUEST_ID: {
|
||||||
MouseEventRequest request;
|
MouseEventRequest request;
|
||||||
TRY(m_client->recv_typed(request));
|
READ_MESSAGE(request);
|
||||||
auto* window = find_window(request.window);
|
auto* window = find_window(request.window);
|
||||||
window->handle_mouse_move(request.position);
|
window->handle_mouse_move(request.position);
|
||||||
window->handle_mouse_buttons(request.position, request.buttons);
|
window->handle_mouse_buttons(request.position, request.buttons);
|
||||||
|
@ -68,6 +68,12 @@ static Result<u32*> create_shm_region(const char* path, int* outfd, ui::Rect rec
|
|||||||
client.rpc_id = decltype(request)::ID; \
|
client.rpc_id = decltype(request)::ID; \
|
||||||
return {}; \
|
return {}; \
|
||||||
} \
|
} \
|
||||||
|
if (rc.error() == EINTR) \
|
||||||
|
{ \
|
||||||
|
client.rpc_in_progress = true; \
|
||||||
|
client.rpc_id = decltype(request)::ID; \
|
||||||
|
return {}; \
|
||||||
|
} \
|
||||||
else \
|
else \
|
||||||
return rc.release_error(); \
|
return rc.release_error(); \
|
||||||
} \
|
} \
|
||||||
@ -202,6 +208,7 @@ namespace wind
|
|||||||
if (rc.has_error())
|
if (rc.has_error())
|
||||||
{
|
{
|
||||||
if (rc.error() == EAGAIN) { return {}; }
|
if (rc.error() == EAGAIN) { return {}; }
|
||||||
|
if (rc.error() == EINTR) { return {}; }
|
||||||
else
|
else
|
||||||
return rc.release_error();
|
return rc.release_error();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user