[Spice-commits] 3 commits - server/char-device.cpp server/char-device.h server/reds.cpp server/red-stream-device.cpp server/red-stream-device.h server/smartcard.cpp server/smartcard.h server/spicevmc.cpp
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue Jun 23 11:51:37 UTC 2020
server/char-device.cpp | 13 ++++++
server/char-device.h | 7 +++
server/red-stream-device.cpp | 81 ++++++++++++++++++-------------------------
server/red-stream-device.h | 18 ++++-----
server/reds.cpp | 15 ++-----
server/smartcard.cpp | 5 +-
server/smartcard.h | 2 -
server/spicevmc.cpp | 10 +----
8 files changed, 71 insertions(+), 80 deletions(-)
New commits:
commit a10e496c469cee7aa3bc9887209a5f558f534326
Author: Frediano Ziglio <freddy77 at gmail.com>
Date: Thu May 7 12:43:14 2020 +0100
char-device: Remove "sin" parameter from read_one_msg_from_device
Not much used, can be retrieved from the class if needed.
There are some apparent test removal on reds.cpp.
The test "if (!reds->vdagent)" apparently disappeared but it's included in
the while.
reds->agent_dev cannot be NULL as SPICE server allows only one agent and we
are into a member of an object so it must be reds->agent_dev.get() == this.
As there's only an agent and as the interface (sin) is extracted from that
agent it must be reds->agent_dev.get() == sin->st and either reds->vdagent
== sin or reds->vdagent == NULL.
Signed-off-by: Frediano Ziglio <freddy77 at gmail.com>
Acked-by: Julien Ropé <jrope at gmail.com>
diff --git a/server/char-device.cpp b/server/char-device.cpp
index cf527001..762a4939 100644
--- a/server/char-device.cpp
+++ b/server/char-device.cpp
@@ -255,7 +255,7 @@ static bool red_char_device_read_from_device(RedCharDevice *dev)
while ((max_send_tokens || (dev->priv->clients == NULL)) && dev->priv->running) {
RedPipeItem *msg;
- msg = dev->read_one_msg_from_device(dev->priv->sin);
+ msg = dev->read_one_msg_from_device();
if (!msg) {
if (dev->priv->during_read_from_device > 1) {
dev->priv->during_read_from_device = 1;
diff --git a/server/char-device.h b/server/char-device.h
index 5c453b78..54963e55 100644
--- a/server/char-device.h
+++ b/server/char-device.h
@@ -190,7 +190,7 @@ public:
/* reads from the device till reaching a msg that should be sent to the client,
* or till the reading fails */
- virtual RedPipeItem* read_one_msg_from_device(SpiceCharDeviceInstance *sin) = 0;
+ virtual RedPipeItem* read_one_msg_from_device() = 0;
/* After this call, the message is unreferenced.
* Can be NULL. */
virtual void send_msg_to_client(RedPipeItem *msg, RedCharDeviceClientOpaque *client) {};
diff --git a/server/red-stream-device.cpp b/server/red-stream-device.cpp
index e57e554a..c62ceceb 100644
--- a/server/red-stream-device.cpp
+++ b/server/red-stream-device.cpp
@@ -158,7 +158,7 @@ StreamDevice::partial_read()
return false;
}
-RedPipeItem* StreamDevice::read_one_msg_from_device(SpiceCharDeviceInstance *)
+RedPipeItem* StreamDevice::read_one_msg_from_device()
{
while (partial_read()) {
continue;
diff --git a/server/red-stream-device.h b/server/red-stream-device.h
index b1f0f055..c10e4beb 100644
--- a/server/red-stream-device.h
+++ b/server/red-stream-device.h
@@ -90,7 +90,7 @@ private:
StreamDeviceDisplayInfo device_display_info;
private:
- virtual RedPipeItem* read_one_msg_from_device(SpiceCharDeviceInstance *sin) override;
+ virtual RedPipeItem* read_one_msg_from_device() override;
virtual void remove_client(RedCharDeviceClientOpaque *client) override;
virtual void port_event(uint8_t event) override;
diff --git a/server/reds.cpp b/server/reds.cpp
index 945c1400..c3e94cb1 100644
--- a/server/reds.cpp
+++ b/server/reds.cpp
@@ -220,7 +220,7 @@ struct RedCharDeviceVDIPort: public RedCharDevice
RedCharDeviceVDIPort();
~RedCharDeviceVDIPort();
- virtual RedPipeItem* read_one_msg_from_device(SpiceCharDeviceInstance *sin) override;
+ virtual RedPipeItem* read_one_msg_from_device() override;
virtual void send_msg_to_client(RedPipeItem *msg, RedCharDeviceClientOpaque *opaque) override;
virtual void send_tokens_to_client(RedCharDeviceClientOpaque *opaque, uint32_t tokens) override;
virtual void remove_client(RedCharDeviceClientOpaque *opaque);
@@ -760,18 +760,13 @@ static void reds_adjust_agent_capabilities(RedsState *reds, VDAgentMessage *mess
/* reads from the device till completes reading a message that is addressed to the client,
* or otherwise, when reading from the device fails */
RedPipeItem *
-RedCharDeviceVDIPort::read_one_msg_from_device(SpiceCharDeviceInstance *sin)
+RedCharDeviceVDIPort::read_one_msg_from_device()
{
RedsState *reds;
RedVDIReadBuf *dispatch_buf;
int n;
reds = get_server();
- g_assert(reds->agent_dev.get() == sin->st);
- if (!reds->vdagent) {
- return NULL;
- }
- spice_assert(reds->vdagent == sin);
while (reds->vdagent) {
switch (priv->read_state) {
case VDI_PORT_READ_STATE_READ_HEADER:
diff --git a/server/smartcard.cpp b/server/smartcard.cpp
index d6f2695b..d17c318b 100644
--- a/server/smartcard.cpp
+++ b/server/smartcard.cpp
@@ -98,7 +98,7 @@ static void smartcard_read_buf_prepare(RedCharDeviceSmartcard *dev, VSCMsgHeader
}
RedPipeItem*
-RedCharDeviceSmartcard::read_one_msg_from_device(SpiceCharDeviceInstance *)
+RedCharDeviceSmartcard::read_one_msg_from_device()
{
RedCharDeviceSmartcard *dev = this;
VSCMsgHeader *vheader = (VSCMsgHeader*)dev->priv->buf;
diff --git a/server/smartcard.h b/server/smartcard.h
index c1bf1d29..19ad349c 100644
--- a/server/smartcard.h
+++ b/server/smartcard.h
@@ -34,7 +34,7 @@ public:
protected:
~RedCharDeviceSmartcard();
private:
- RedPipeItem* read_one_msg_from_device(SpiceCharDeviceInstance *sin) override;
+ RedPipeItem* read_one_msg_from_device() override;
void send_msg_to_client(RedPipeItem *msg, RedCharDeviceClientOpaque *client) override;
void remove_client(RedCharDeviceClientOpaque *client) override;
public: // XXX make private
diff --git a/server/spicevmc.cpp b/server/spicevmc.cpp
index ad314cd0..0c187c3f 100644
--- a/server/spicevmc.cpp
+++ b/server/spicevmc.cpp
@@ -59,7 +59,7 @@ struct RedCharDeviceSpiceVmc: public RedCharDevice
RedCharDeviceSpiceVmc(SpiceCharDeviceInstance *sin, RedsState *reds, RedVmcChannel *channel);
~RedCharDeviceSpiceVmc();
- virtual RedPipeItem* read_one_msg_from_device(SpiceCharDeviceInstance *sin) override;
+ virtual RedPipeItem* read_one_msg_from_device() override;
virtual void remove_client(RedCharDeviceClientOpaque *opaque) override;
virtual void on_free_self_token() override;
virtual void port_event(uint8_t event) override;
@@ -247,7 +247,7 @@ static RedVmcPipeItem* try_compress_lz4(RedVmcChannel *channel, int n, RedVmcPip
}
#endif
-RedPipeItem* RedCharDeviceSpiceVmc::read_one_msg_from_device(SpiceCharDeviceInstance *)
+RedPipeItem* RedCharDeviceSpiceVmc::read_one_msg_from_device()
{
RedVmcPipeItem *msg_item;
int n;
commit 479a1a74a28feed520e55f1e879cdc1fad2cc21f
Author: Frediano Ziglio <freddy77 at gmail.com>
Date: Thu May 7 12:37:21 2020 +0100
Reuse RedCharDevice::read
Signed-off-by: Frediano Ziglio <freddy77 at gmail.com>
Acked-by: Julien Ropé <jrope at gmail.com>
diff --git a/server/red-stream-device.cpp b/server/red-stream-device.cpp
index 73dd6527..e57e554a 100644
--- a/server/red-stream-device.cpp
+++ b/server/red-stream-device.cpp
@@ -47,20 +47,17 @@ fill_dev_hdr(StreamDevHeader *hdr, StreamMsgType msg_type, uint32_t msg_size)
}
bool
-StreamDevice::partial_read(SpiceCharDeviceInstance *sin)
+StreamDevice::partial_read()
{
- SpiceCharDeviceInterface *sif;
int n;
bool handled = false;
- sif = spice_char_device_get_interface(sin);
-
// in order to get in sync every time we open the device we need to discard data here.
// Qemu keeps a buffer of data which is used only during spice_server_char_device_wakeup
// from Qemu
if (G_UNLIKELY(has_error)) {
uint8_t buf[16 * 1024];
- while (sif->read(sin, buf, sizeof(buf)) > 0) {
+ while (read(buf, sizeof(buf)) > 0) {
continue;
}
@@ -83,7 +80,7 @@ StreamDevice::partial_read(SpiceCharDeviceInstance *sin)
/* read header */
while (hdr_pos < sizeof(hdr)) {
- n = sif->read(sin, (uint8_t *) &hdr + hdr_pos, sizeof(hdr) - hdr_pos);
+ n = read((uint8_t *) &hdr + hdr_pos, sizeof(hdr) - hdr_pos);
if (n <= 0) {
return false;
}
@@ -98,40 +95,40 @@ StreamDevice::partial_read(SpiceCharDeviceInstance *sin)
switch ((StreamMsgType) hdr.type) {
case STREAM_TYPE_FORMAT:
if (hdr.size != sizeof(StreamMsgFormat)) {
- handled = handle_msg_invalid(sin, "Wrong size for StreamMsgFormat");
+ handled = handle_msg_invalid("Wrong size for StreamMsgFormat");
} else {
- handled = handle_msg_format(sin);
+ handled = handle_msg_format();
}
break;
case STREAM_TYPE_DEVICE_DISPLAY_INFO:
if (hdr.size > sizeof(StreamMsgDeviceDisplayInfo) + MAX_DEVICE_ADDRESS_LEN) {
- handled = handle_msg_invalid(sin, "StreamMsgDeviceDisplayInfo too large");
+ handled = handle_msg_invalid("StreamMsgDeviceDisplayInfo too large");
} else {
- handled = handle_msg_device_display_info(sin);
+ handled = handle_msg_device_display_info();
}
break;
case STREAM_TYPE_DATA:
if (hdr.size > 32*1024*1024) {
- handled = handle_msg_invalid(sin, "STREAM_DATA too large");
+ handled = handle_msg_invalid("STREAM_DATA too large");
} else {
- handled = handle_msg_data(sin);
+ handled = handle_msg_data();
}
break;
case STREAM_TYPE_CURSOR_SET:
- handled = handle_msg_cursor_set(sin);
+ handled = handle_msg_cursor_set();
break;
case STREAM_TYPE_CURSOR_MOVE:
if (hdr.size != sizeof(StreamMsgCursorMove)) {
- handled = handle_msg_invalid(sin, "Wrong size for StreamMsgCursorMove");
+ handled = handle_msg_invalid("Wrong size for StreamMsgCursorMove");
} else {
- handled = handle_msg_cursor_move(sin);
+ handled = handle_msg_cursor_move();
}
break;
case STREAM_TYPE_CAPABILITIES:
- handled = handle_msg_capabilities(sin);
+ handled = handle_msg_capabilities();
break;
default:
- handled = handle_msg_invalid(sin, "Invalid message type");
+ handled = handle_msg_invalid("Invalid message type");
break;
}
@@ -161,16 +158,16 @@ StreamDevice::partial_read(SpiceCharDeviceInstance *sin)
return false;
}
-RedPipeItem* StreamDevice::read_one_msg_from_device(SpiceCharDeviceInstance *sin)
+RedPipeItem* StreamDevice::read_one_msg_from_device(SpiceCharDeviceInstance *)
{
- while (partial_read(sin)) {
+ while (partial_read()) {
continue;
}
return NULL;
}
bool
-StreamDevice::handle_msg_invalid(SpiceCharDeviceInstance *sin, const char *error_msg)
+StreamDevice::handle_msg_invalid(const char *error_msg)
{
static const char default_error_msg[] = "Protocol error";
@@ -203,16 +200,14 @@ StreamDevice::handle_msg_invalid(SpiceCharDeviceInstance *sin, const char *error
}
bool
-StreamDevice::handle_msg_format(SpiceCharDeviceInstance *sin)
+StreamDevice::handle_msg_format()
{
- SpiceCharDeviceInterface *sif = spice_char_device_get_interface(sin);
-
spice_extra_assert(hdr_pos >= sizeof(StreamDevHeader));
spice_extra_assert(hdr.type == STREAM_TYPE_FORMAT);
- int n = sif->read(sin, msg->buf + msg_pos, sizeof(StreamMsgFormat) - msg_pos);
+ int n = read(msg->buf + msg_pos, sizeof(StreamMsgFormat) - msg_pos);
if (n < 0) {
- return handle_msg_invalid(sin, NULL);
+ return handle_msg_invalid(NULL);
}
msg_pos += n;
@@ -228,10 +223,8 @@ StreamDevice::handle_msg_format(SpiceCharDeviceInstance *sin)
}
bool
-StreamDevice::handle_msg_device_display_info(SpiceCharDeviceInstance *sin)
+StreamDevice::handle_msg_device_display_info()
{
- SpiceCharDeviceInterface *sif = spice_char_device_get_interface(sin);
-
spice_extra_assert(hdr_pos >= sizeof(StreamDevHeader));
spice_extra_assert(hdr.type == STREAM_TYPE_DEVICE_DISPLAY_INFO);
@@ -241,7 +234,7 @@ StreamDevice::handle_msg_device_display_info(SpiceCharDeviceInstance *sin)
}
/* read from device */
- ssize_t n = sif->read(sin, msg->buf + msg_pos, hdr.size - msg_pos);
+ ssize_t n = read(msg->buf + msg_pos, hdr.size - msg_pos);
if (n <= 0) {
return msg_pos == hdr.size;
}
@@ -293,20 +286,18 @@ StreamDevice::handle_msg_device_display_info(SpiceCharDeviceInstance *sin)
}
bool
-StreamDevice::handle_msg_capabilities(SpiceCharDeviceInstance *sin)
+StreamDevice::handle_msg_capabilities()
{
- SpiceCharDeviceInterface *sif = spice_char_device_get_interface(sin);
-
spice_extra_assert(hdr_pos >= sizeof(StreamDevHeader));
spice_extra_assert(hdr.type == STREAM_TYPE_CAPABILITIES);
if (hdr.size > STREAM_MSG_CAPABILITIES_MAX_BYTES) {
- return handle_msg_invalid(sin, "Wrong size for StreamMsgCapabilities");
+ return handle_msg_invalid("Wrong size for StreamMsgCapabilities");
}
- int n = sif->read(sin, msg->buf + msg_pos, hdr.size - msg_pos);
+ int n = read(msg->buf + msg_pos, hdr.size - msg_pos);
if (n < 0) {
- return handle_msg_invalid(sin, NULL);
+ return handle_msg_invalid(NULL);
}
msg_pos += n;
@@ -324,9 +315,8 @@ StreamDevice::handle_msg_capabilities(SpiceCharDeviceInstance *sin)
}
bool
-StreamDevice::handle_msg_data(SpiceCharDeviceInstance *sin)
+StreamDevice::handle_msg_data()
{
- SpiceCharDeviceInterface *sif = spice_char_device_get_interface(sin);
int n;
spice_extra_assert(hdr_pos >= sizeof(StreamDevHeader));
@@ -351,7 +341,7 @@ StreamDevice::handle_msg_data(SpiceCharDeviceInstance *sin)
}
/* read from device */
- n = sif->read(sin, msg->buf + msg_pos, hdr.size - msg_pos);
+ n = read(msg->buf + msg_pos, hdr.size - msg_pos);
if (n <= 0) {
return msg_pos == hdr.size;
}
@@ -435,7 +425,7 @@ stream_msg_cursor_set_to_cursor_cmd(const StreamMsgCursorSet *msg, size_t msg_si
}
bool
-StreamDevice::handle_msg_cursor_set(SpiceCharDeviceInstance *sin)
+StreamDevice::handle_msg_cursor_set()
{
// Calculate the maximum size required to send the pixel data for a cursor that is the
// maximum size using the format that requires the largest number of bits per pixel
@@ -445,12 +435,10 @@ StreamDevice::handle_msg_cursor_set(SpiceCharDeviceInstance *sin)
(STREAM_MSG_CURSOR_SET_MAX_WIDTH * 4 + (STREAM_MSG_CURSOR_SET_MAX_WIDTH + 7)/8)
* STREAM_MSG_CURSOR_SET_MAX_HEIGHT;
- SpiceCharDeviceInterface *sif = spice_char_device_get_interface(sin);
-
if (hdr.size < sizeof(StreamMsgCursorSet) || hdr.size > max_cursor_set_size) {
// we could skip the message but on the other hand the guest
// is buggy in any case
- return handle_msg_invalid(sin, "Cursor size is invalid");
+ return handle_msg_invalid("Cursor size is invalid");
}
// read part of the message till we get all
@@ -458,7 +446,7 @@ StreamDevice::handle_msg_cursor_set(SpiceCharDeviceInstance *sin)
msg = (StreamDevice::AllMessages*) g_realloc(msg, hdr.size);
msg_len = hdr.size;
}
- int n = sif->read(sin, msg->buf + msg_pos, hdr.size - msg_pos);
+ int n = read(msg->buf + msg_pos, hdr.size - msg_pos);
if (n <= 0) {
return false;
}
@@ -470,7 +458,7 @@ StreamDevice::handle_msg_cursor_set(SpiceCharDeviceInstance *sin)
// transform the message to a cursor command and process it
RedCursorCmd *cmd = stream_msg_cursor_set_to_cursor_cmd(&msg->cursor_set, msg_pos);
if (!cmd) {
- return handle_msg_invalid(sin, NULL);
+ return handle_msg_invalid(NULL);
}
cursor_channel->process_cmd(cmd);
@@ -478,10 +466,9 @@ StreamDevice::handle_msg_cursor_set(SpiceCharDeviceInstance *sin)
}
bool
-StreamDevice::handle_msg_cursor_move(SpiceCharDeviceInstance *sin)
+StreamDevice::handle_msg_cursor_move()
{
- SpiceCharDeviceInterface *sif = spice_char_device_get_interface(sin);
- int n = sif->read(sin, msg->buf + msg_pos, hdr.size - msg_pos);
+ int n = read(msg->buf + msg_pos, hdr.size - msg_pos);
if (n <= 0) {
return false;
}
diff --git a/server/red-stream-device.h b/server/red-stream-device.h
index 0e4e35fa..b1f0f055 100644
--- a/server/red-stream-device.h
+++ b/server/red-stream-device.h
@@ -94,14 +94,14 @@ private:
virtual void remove_client(RedCharDeviceClientOpaque *client) override;
virtual void port_event(uint8_t event) override;
- bool partial_read(SpiceCharDeviceInstance *sin);
- bool handle_msg_invalid(SpiceCharDeviceInstance *sin, const char *error_msg) SPICE_GNUC_WARN_UNUSED_RESULT;
- bool handle_msg_capabilities(SpiceCharDeviceInstance *sin) SPICE_GNUC_WARN_UNUSED_RESULT;
- bool handle_msg_format(SpiceCharDeviceInstance *sin) SPICE_GNUC_WARN_UNUSED_RESULT;
- bool handle_msg_cursor_move(SpiceCharDeviceInstance *sin) SPICE_GNUC_WARN_UNUSED_RESULT;
- bool handle_msg_cursor_set(SpiceCharDeviceInstance *sin) SPICE_GNUC_WARN_UNUSED_RESULT;
- bool handle_msg_data(SpiceCharDeviceInstance *sin) SPICE_GNUC_WARN_UNUSED_RESULT;
- bool handle_msg_device_display_info(SpiceCharDeviceInstance *sin) SPICE_GNUC_WARN_UNUSED_RESULT;
+ bool partial_read();
+ bool handle_msg_invalid(const char *error_msg) SPICE_GNUC_WARN_UNUSED_RESULT;
+ bool handle_msg_capabilities() SPICE_GNUC_WARN_UNUSED_RESULT;
+ bool handle_msg_format() SPICE_GNUC_WARN_UNUSED_RESULT;
+ bool handle_msg_cursor_move() SPICE_GNUC_WARN_UNUSED_RESULT;
+ bool handle_msg_cursor_set() SPICE_GNUC_WARN_UNUSED_RESULT;
+ bool handle_msg_data() SPICE_GNUC_WARN_UNUSED_RESULT;
+ bool handle_msg_device_display_info() SPICE_GNUC_WARN_UNUSED_RESULT;
void reset_channels();
static void close_timer_func(StreamDevice *dev);
static void stream_start(void *opaque, StreamMsgStartStop *start,
diff --git a/server/reds.cpp b/server/reds.cpp
index 1abb9fe9..945c1400 100644
--- a/server/reds.cpp
+++ b/server/reds.cpp
@@ -763,7 +763,6 @@ RedPipeItem *
RedCharDeviceVDIPort::read_one_msg_from_device(SpiceCharDeviceInstance *sin)
{
RedsState *reds;
- SpiceCharDeviceInterface *sif;
RedVDIReadBuf *dispatch_buf;
int n;
@@ -773,11 +772,10 @@ RedCharDeviceVDIPort::read_one_msg_from_device(SpiceCharDeviceInstance *sin)
return NULL;
}
spice_assert(reds->vdagent == sin);
- sif = spice_char_device_get_interface(reds->vdagent);
while (reds->vdagent) {
switch (priv->read_state) {
case VDI_PORT_READ_STATE_READ_HEADER:
- n = sif->read(reds->vdagent, priv->receive_pos, priv->receive_len);
+ n = read(priv->receive_pos, priv->receive_len);
if (!n) {
return NULL;
}
@@ -801,7 +799,7 @@ RedCharDeviceVDIPort::read_one_msg_from_device(SpiceCharDeviceInstance *sin)
}
/* fall through */
case VDI_PORT_READ_STATE_READ_DATA: {
- n = sif->read(reds->vdagent, priv->receive_pos, priv->receive_len);
+ n = read(priv->receive_pos, priv->receive_len);
if (!n) {
return NULL;
}
diff --git a/server/smartcard.cpp b/server/smartcard.cpp
index 5820b8da..d6f2695b 100644
--- a/server/smartcard.cpp
+++ b/server/smartcard.cpp
@@ -98,10 +98,9 @@ static void smartcard_read_buf_prepare(RedCharDeviceSmartcard *dev, VSCMsgHeader
}
RedPipeItem*
-RedCharDeviceSmartcard::read_one_msg_from_device(SpiceCharDeviceInstance *sin)
+RedCharDeviceSmartcard::read_one_msg_from_device(SpiceCharDeviceInstance *)
{
RedCharDeviceSmartcard *dev = this;
- SpiceCharDeviceInterface *sif = spice_char_device_get_interface(sin);
VSCMsgHeader *vheader = (VSCMsgHeader*)dev->priv->buf;
int remaining;
int actual_length;
@@ -113,7 +112,7 @@ RedCharDeviceSmartcard::read_one_msg_from_device(SpiceCharDeviceInstance *sin)
// read. In this case we don't need to read any byte
if (dev->priv->buf_used < sizeof(VSCMsgHeader) ||
dev->priv->buf_used - sizeof(VSCMsgHeader) < ntohl(vheader->length)) {
- int n = sif->read(sin, dev->priv->buf_pos, dev->priv->buf_size - dev->priv->buf_used);
+ int n = read(dev->priv->buf_pos, dev->priv->buf_size - dev->priv->buf_used);
if (n <= 0) {
break;
}
diff --git a/server/spicevmc.cpp b/server/spicevmc.cpp
index 265f6049..ad314cd0 100644
--- a/server/spicevmc.cpp
+++ b/server/spicevmc.cpp
@@ -247,14 +247,11 @@ static RedVmcPipeItem* try_compress_lz4(RedVmcChannel *channel, int n, RedVmcPip
}
#endif
-RedPipeItem* RedCharDeviceSpiceVmc::read_one_msg_from_device(SpiceCharDeviceInstance *sin)
+RedPipeItem* RedCharDeviceSpiceVmc::read_one_msg_from_device(SpiceCharDeviceInstance *)
{
- SpiceCharDeviceInterface *sif;
RedVmcPipeItem *msg_item;
int n;
- sif = spice_char_device_get_interface(sin);
-
if (!channel->rcc || channel->queued_data >= QUEUED_DATA_LIMIT) {
return NULL;
}
@@ -269,8 +266,7 @@ RedPipeItem* RedCharDeviceSpiceVmc::read_one_msg_from_device(SpiceCharDeviceInst
channel->pipe_item = NULL;
}
- n = sif->read(sin, msg_item->buf,
- sizeof(msg_item->buf));
+ n = read(msg_item->buf, sizeof(msg_item->buf));
if (n > 0) {
spice_debug("read from dev %d", n);
#ifdef USE_LZ4
commit 66dacecda942be9ab125698eda4023be57de6e51
Author: Frediano Ziglio <freddy77 at gmail.com>
Date: Thu May 7 12:36:44 2020 +0100
char-device: Add a read method to simplify reading data
Avoid to pass throught SpiceCharDeviceInterface.
When data is read from device the device get marked as active.
This is coherent with what is done in red_char_device_read_from_device.
Signed-off-by: Frediano Ziglio <freddy77 at gmail.com>
Acked-by: Julien Ropé <jrope at gmail.com>
diff --git a/server/char-device.cpp b/server/char-device.cpp
index e28a1919..cf527001 100644
--- a/server/char-device.cpp
+++ b/server/char-device.cpp
@@ -947,3 +947,14 @@ RedCharDevice::RedCharDevice(RedsState *reds, SpiceCharDeviceInstance *sin,
g_queue_init(&priv->write_queue);
}
+
+int RedCharDevice::read(uint8_t *buf, int len)
+{
+ auto sif = spice_char_device_get_interface(priv->sin);
+
+ int ret = sif->read(priv->sin, buf, len);
+ if (ret > 0) {
+ priv->active = true;
+ }
+ return ret;
+}
diff --git a/server/char-device.h b/server/char-device.h
index 0f910bc0..5c453b78 100644
--- a/server/char-device.h
+++ b/server/char-device.h
@@ -174,6 +174,11 @@ public:
SpiceCharDeviceInstance *get_device_instance();
+ /**
+ * Read data from device
+ */
+ int read(uint8_t *buf, int len);
+
red::unique_link<RedCharDevicePrivate> priv;
//protected:
More information about the Spice-commits
mailing list