libcamera: ipc: unix: Make socket operation asynchronous

Blocking socket operation when receiving messages may lead to long
delays, and possibly a complete deadlock, if the remote side delays
sending of the payload after the header, or doesn't send the payload at
all. To avoid this, make the socket non-blocking and implement a simple
state machine to receive the header synchronously with the socket read
notification. The payload read is still synchronous with the receive()
method to avoid data copies.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
This commit is contained in:
Laurent Pinchart
2019-07-02 00:58:53 +03:00
parent a00fdabacd
commit f137451817
2 changed files with 63 additions and 27 deletions
+2
View File
@@ -49,6 +49,8 @@ private:
void dataNotifier(EventNotifier *notifier);
int fd_;
bool headerReceived_;
struct Header header_;
EventNotifier *notifier_;
};