| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #include <config.h> |
| |
| #include <fcntl.h> |
| |
| #include "common-graphics-channel.h" |
| #include "dcc.h" |
| #include "red-client.h" |
| |
| #define CHANNEL_RECEIVE_BUF_SIZE 1024 |
| |
| struct CommonGraphicsChannelPrivate |
| { |
| int during_target_migrate; |
| |
| |
| |
| |
| }; |
| |
| G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(CommonGraphicsChannel, common_graphics_channel, |
| RED_TYPE_CHANNEL) |
| |
| struct CommonGraphicsChannelClientPrivate { |
| uint8_t recv_buf[CHANNEL_RECEIVE_BUF_SIZE]; |
| }; |
| |
| G_DEFINE_TYPE_WITH_PRIVATE(CommonGraphicsChannelClient, common_graphics_channel_client, |
| RED_TYPE_CHANNEL_CLIENT) |
| |
| static uint8_t *common_alloc_recv_buf(RedChannelClient *rcc, uint16_t type, uint32_t size) |
| { |
| CommonGraphicsChannelClient *common = COMMON_GRAPHICS_CHANNEL_CLIENT(rcc); |
| |
| |
| if (type == SPICE_MSGC_MIGRATE_DATA) { |
| return g_malloc(size); |
| } |
| |
| if (size > CHANNEL_RECEIVE_BUF_SIZE) { |
| spice_warning("unexpected message size %u (max is %d)", size, CHANNEL_RECEIVE_BUF_SIZE); |
| return NULL; |
| } |
| return common->priv->recv_buf; |
| } |
| |
| static void common_release_recv_buf(RedChannelClient *rcc, uint16_t type, uint32_t size, |
| uint8_t* msg) |
| { |
| if (type == SPICE_MSGC_MIGRATE_DATA) { |
| g_free(msg); |
| } |
| } |
| |
| bool common_channel_client_config_socket(RedChannelClient *rcc) |
| { |
| RedClient *client = red_channel_client_get_client(rcc); |
| MainChannelClient *mcc = red_client_get_main(client); |
| RedStream *stream = red_channel_client_get_stream(rcc); |
| gboolean is_low_bandwidth; |
| |
| |
| is_low_bandwidth = main_channel_client_is_low_bandwidth(mcc); |
| if (!red_stream_set_auto_flush(stream, false)) { |
| |
| |
| |
| |
| |
| |
| red_stream_set_no_delay(stream, !is_low_bandwidth); |
| } |
| |
| red_channel_client_ack_set_client_window(rcc, |
| is_low_bandwidth ? |
| WIDE_CLIENT_ACK_WINDOW : NARROW_CLIENT_ACK_WINDOW); |
| return TRUE; |
| } |
| |
| |
| static void |
| common_graphics_channel_class_init(CommonGraphicsChannelClass *klass) |
| { |
| } |
| |
| static void |
| common_graphics_channel_init(CommonGraphicsChannel *self) |
| { |
| self->priv = common_graphics_channel_get_instance_private(self); |
| } |
| |
| void common_graphics_channel_set_during_target_migrate(CommonGraphicsChannel *self, gboolean value) |
| { |
| self->priv->during_target_migrate = value; |
| } |
| |
| gboolean common_graphics_channel_get_during_target_migrate(CommonGraphicsChannel *self) |
| { |
| return self->priv->during_target_migrate; |
| } |
| |
| static void |
| common_graphics_channel_client_init(CommonGraphicsChannelClient *self) |
| { |
| self->priv = common_graphics_channel_client_get_instance_private(self); |
| } |
| |
| static void |
| common_graphics_channel_client_class_init(CommonGraphicsChannelClientClass *klass) |
| { |
| RedChannelClientClass *client_class = RED_CHANNEL_CLIENT_CLASS(klass); |
| |
| client_class->config_socket = common_channel_client_config_socket; |
| client_class->alloc_recv_buf = common_alloc_recv_buf; |
| client_class->release_recv_buf = common_release_recv_buf; |
| } |