server/red_channel (+): remove red_channel_add_buf

This commit is contained in:
Alon Levy 2010-11-10 09:52:28 +02:00
parent 16bff20f91
commit 8cd5568c92
5 changed files with 55 additions and 60 deletions

View File

@ -461,7 +461,6 @@ static void inputs_shutdown(Channel *channel)
if (inputs_channel) {
red_channel_shutdown(&inputs_channel->base);
inputs_channel->base.incoming.shut = TRUE;
channel->data = NULL;
g_inputs_channel = NULL;
}

View File

@ -455,6 +455,7 @@ void red_channel_shutdown(RedChannel *channel)
red_channel_pipe_clear(channel);
shutdown(channel->stream->socket, SHUT_RDWR);
channel->stream->shutdown = TRUE;
channel->incoming.shut = TRUE;
}
}
@ -531,12 +532,6 @@ static void red_channel_event(int fd, int event, void *data)
}
}
void red_channel_add_buf(RedChannel *channel, void *data, uint32_t size)
{
spice_marshaller_add_ref(channel->send_data.marshaller, data, size);
channel->send_data.header->size += size;
}
void red_channel_init_send_data(RedChannel *channel, uint16_t msg_type, PipeItem *item)
{
ASSERT(channel->send_data.item == NULL);

View File

@ -148,10 +148,6 @@ struct RedChannel {
struct {
SpiceMarshaller *marshaller;
SpiceDataHeader *header;
union {
SpiceMsgSetAck ack;
SpiceMsgMigrate migrate;
} u;
uint32_t size;
PipeItem *item;
int blocked;
@ -218,7 +214,6 @@ int red_channel_is_connected(RedChannel *channel);
void red_channel_destroy(RedChannel *channel);
void red_channel_shutdown(RedChannel *channel);
/* should be called when a new channel is ready to send messages */
void red_channel_init_outgoing_messages_window(RedChannel *channel);
@ -229,10 +224,8 @@ int red_channel_handle_message(RedChannel *channel, uint32_t size,
/* default error handler that disconnects channel */
void red_channel_default_peer_on_error(RedChannel *channel);
/* when preparing send_data: should call init and then add_buf per buffer that is
being sent */
/* when preparing send_data: should call init and then use marshaller */
void red_channel_init_send_data(RedChannel *channel, uint16_t msg_type, PipeItem *item);
void red_channel_add_buf(RedChannel *channel, void *data, uint32_t size);
uint64_t red_channel_get_message_serial(RedChannel *channel);
void red_channel_set_message_serial(RedChannel *channel, uint64_t);
@ -254,6 +247,8 @@ void red_channel_ack_zero_messages_window(RedChannel *channel);
void red_channel_ack_set_client_window(RedChannel *channel, int client_window);
void red_channel_push_set_ack(RedChannel *channel);
void red_channel_shutdown(RedChannel *channel);
// TODO: unstaticed for display/cursor channels. they do some specific pushes not through
// adding elements or on events. but not sure if this is actually required (only result
// should be that they ""try"" a little harder, but if the event system is correct it

View File

@ -491,6 +491,7 @@ struct TunnelChannel {
int tunnel_error;
/* TODO: this needs to be RCC specific (or bad things will happen) */
struct {
union {
SpiceMsgTunnelInit init;
@ -502,6 +503,7 @@ struct TunnelChannel {
SpiceMsgTunnelSocketData socket_data;
SpiceMsgTunnelSocketTokens socket_token;
TunnelMigrateData migrate_data;
SpiceMsgMigrate migrate;
} u;
} send_data;
@ -2341,14 +2343,16 @@ static int tunnel_channel_handle_message(RedChannel *channel, SpiceDataHeader *h
/* outgoing msgs
********************************/
static void tunnel_channel_marshall_migrate(TunnelChannel *channel, SpiceMarshaller *m, PipeItem *item)
static void tunnel_channel_marshall_migrate(TunnelChannel *tunnel_channel, SpiceMarshaller *m, PipeItem *item)
{
ASSERT(channel);
channel->base.send_data.u.migrate.flags = SPICE_MIGRATE_NEED_FLUSH |
SPICE_MIGRATE_NEED_DATA_TRANSFER;
channel->expect_migrate_mark = TRUE;
red_channel_init_send_data(&channel->base, SPICE_MSG_MIGRATE, item);
red_channel_add_buf(&channel->base, &channel->base.send_data.u.migrate, sizeof(SpiceMsgMigrate));
ASSERT(tunnel_channel);
tunnel_channel->send_data.u.migrate.flags =
SPICE_MIGRATE_NEED_FLUSH | SPICE_MIGRATE_NEED_DATA_TRANSFER;
tunnel_channel->expect_migrate_mark = TRUE;
red_channel_init_send_data(&tunnel_channel->base, SPICE_MSG_MIGRATE, item);
spice_marshaller_add_ref(m,
(uint8_t*)&tunnel_channel->send_data.u.migrate,
sizeof(SpiceMsgMigrate));
}
static int __tunnel_channel_marshall_process_bufs_migrate_data(TunnelChannel *channel,
@ -2359,7 +2363,7 @@ static int __tunnel_channel_marshall_process_bufs_migrate_data(TunnelChannel *ch
int size = 0;
while (buf) {
red_channel_add_buf(&channel->base, buf->data + buf_offset, buf->size - buf_offset);
spice_marshaller_add_ref(m, (uint8_t*)buf->data + buf_offset, buf->size - buf_offset);
size += buf->size - buf_offset;
buf_offset = 0;
buf = buf->next;
@ -2376,7 +2380,7 @@ static int __tunnel_channel_marshall_ready_bufs_migrate_data(TunnelChannel *chan
int size = 0;
while (chunk) {
red_channel_add_buf(&channel->base, chunk->data + offset, chunk->size - offset);
spice_marshaller_add_ref(m, (uint8_t*)chunk->data + offset, chunk->size - offset);
size += chunk->size - offset;
offset = 0;
chunk = chunk->next;
@ -2396,12 +2400,12 @@ static int __tunnel_channel_marshall_service_migrate_data(TunnelChannel *channel
if (service->type == SPICE_TUNNEL_SERVICE_TYPE_GENERIC) {
generic_data = &item->u.generic_service;
red_channel_add_buf(&channel->base, &item->u.generic_service,
spice_marshaller_add_ref(m, (uint8_t*)&item->u.generic_service,
sizeof(item->u.generic_service));
cur_offset += sizeof(item->u.generic_service);
} else if (service->type == SPICE_TUNNEL_SERVICE_TYPE_IPP) {
generic_data = &item->u.print_service.base;
red_channel_add_buf(&channel->base, &item->u.print_service,
spice_marshaller_add_ref(m, (uint8_t*)&item->u.print_service,
sizeof(item->u.print_service));
cur_offset += sizeof(item->u.print_service);
} else {
@ -2409,11 +2413,11 @@ static int __tunnel_channel_marshall_service_migrate_data(TunnelChannel *channel
}
generic_data->name = cur_offset;
red_channel_add_buf(&channel->base, service->name, strlen(service->name) + 1);
spice_marshaller_add_ref(m, (uint8_t*)service->name, strlen(service->name) + 1);
cur_offset += strlen(service->name) + 1;
generic_data->description = cur_offset;
red_channel_add_buf(&channel->base, service->description, strlen(service->description) + 1);
spice_marshaller_add_ref(m, (uint8_t*)service->description, strlen(service->description) + 1);
cur_offset += strlen(service->description) + 1;
return (cur_offset - offset);
@ -2426,7 +2430,7 @@ static int __tunnel_channel_marshall_socket_migrate_data(TunnelChannel *channel,
RedSocket *sckt = item->socket;
TunnelMigrateSocket *mig_sckt = &item->mig_socket;
int cur_offset = offset;
red_channel_add_buf(&channel->base, mig_sckt, sizeof(*mig_sckt));
spice_marshaller_add_ref(m, (uint8_t*)mig_sckt, sizeof(*mig_sckt));
cur_offset += sizeof(*mig_sckt);
if ((sckt->client_status != CLIENT_SCKT_STATUS_CLOSED) &&
@ -2439,7 +2443,7 @@ static int __tunnel_channel_marshall_socket_migrate_data(TunnelChannel *channel,
cur_offset += mig_sckt->out_data.process_buf_size;
if (mig_sckt->out_data.process_queue_size) {
mig_sckt->out_data.process_queue = cur_offset;
red_channel_add_buf(&channel->base, item->out_process_queue,
spice_marshaller_add_ref(m, (uint8_t*)item->out_process_queue,
mig_sckt->out_data.process_queue_size);
cur_offset += mig_sckt->out_data.process_queue_size;
}
@ -2463,7 +2467,7 @@ static int __tunnel_channel_marshall_socket_migrate_data(TunnelChannel *channel,
cur_offset += mig_sckt->in_data.process_buf_size;
if (mig_sckt->in_data.process_queue_size) {
mig_sckt->in_data.process_queue = cur_offset;
red_channel_add_buf(&channel->base, item->in_process_queue,
spice_marshaller_add_ref(m, (uint8_t*)item->in_process_queue,
mig_sckt->in_data.process_queue_size);
cur_offset += mig_sckt->in_data.process_queue_size;
}
@ -2478,7 +2482,7 @@ static int __tunnel_channel_marshall_socket_migrate_data(TunnelChannel *channel,
}
if (item->slirp_socket_size) { // zero if socket is closed
red_channel_add_buf(&channel->base, item->slirp_socket, item->slirp_socket_size);
spice_marshaller_add_ref(m, (uint8_t*)item->slirp_socket, item->slirp_socket_size);
mig_sckt->slirp_sckt = cur_offset;
cur_offset += item->slirp_socket_size;
}
@ -2499,14 +2503,14 @@ static void tunnel_channel_marshall_migrate_data(TunnelChannel *channel,
migrate_data->version = TUNNEL_MIGRATE_DATA_VERSION;
migrate_data->message_serial = red_channel_get_message_serial(&channel->base);
red_channel_init_send_data(&channel->base, SPICE_MSG_MIGRATE_DATA, item);
red_channel_add_buf(&channel->base, migrate_data, sizeof(*migrate_data));
spice_marshaller_add_ref(m, (uint8_t*)migrate_data, sizeof(*migrate_data));
migrate_data->slirp_state = data_buf_offset;
red_channel_add_buf(&channel->base, migrate_item->slirp_state, migrate_item->slirp_state_size);
spice_marshaller_add_ref(m, (uint8_t*)migrate_item->slirp_state, migrate_item->slirp_state_size);
data_buf_offset += migrate_item->slirp_state_size;
migrate_data->services_list = data_buf_offset;
red_channel_add_buf(&channel->base, migrate_item->services_list,
spice_marshaller_add_ref(m, (uint8_t*)migrate_item->services_list,
migrate_item->services_list_size);
data_buf_offset += migrate_item->services_list_size;
@ -2519,7 +2523,7 @@ static void tunnel_channel_marshall_migrate_data(TunnelChannel *channel,
migrate_data->sockets_list = data_buf_offset;
red_channel_add_buf(&channel->base, migrate_item->sockets_list,
spice_marshaller_add_ref(m, (uint8_t*)migrate_item->sockets_list,
migrate_item->sockets_list_size);
data_buf_offset += migrate_item->sockets_list_size;
@ -2539,7 +2543,7 @@ static void tunnel_channel_marshall_init(TunnelChannel *channel, SpiceMarshaller
channel->send_data.u.init.max_num_of_sockets = MAX_SOCKETS_NUM;
red_channel_init_send_data(&channel->base, SPICE_MSG_TUNNEL_INIT, item);
red_channel_add_buf(&channel->base, &channel->send_data.u.init, sizeof(SpiceMsgTunnelInit));
spice_marshaller_add_ref(m, (uint8_t*)&channel->send_data.u.init, sizeof(SpiceMsgTunnelInit));
}
static void tunnel_channel_marshall_service_ip_map(TunnelChannel *channel, SpiceMarshaller *m, PipeItem *item)
@ -2550,9 +2554,9 @@ static void tunnel_channel_marshall_service_ip_map(TunnelChannel *channel, Spice
channel->send_data.u.service_ip.virtual_ip.type = SPICE_TUNNEL_IP_TYPE_IPv4;
red_channel_init_send_data(&channel->base, SPICE_MSG_TUNNEL_SERVICE_IP_MAP, item);
red_channel_add_buf(&channel->base, &channel->send_data.u.service_ip,
spice_marshaller_add_ref(m, (uint8_t*)&channel->send_data.u.service_ip,
sizeof(SpiceMsgTunnelServiceIpMap));
red_channel_add_buf(&channel->base, &service->virt_ip.s_addr, sizeof(SpiceTunnelIPv4));
spice_marshaller_add_ref(m, (uint8_t*)&service->virt_ip.s_addr, sizeof(SpiceTunnelIPv4));
}
static void tunnel_channel_marshall_socket_open(TunnelChannel *channel, SpiceMarshaller *m, PipeItem *item)
@ -2567,7 +2571,7 @@ static void tunnel_channel_marshall_socket_open(TunnelChannel *channel, SpiceMar
sckt->in_data.client_total_num_tokens = SOCKET_WINDOW_SIZE;
sckt->in_data.num_tokens = 0;
red_channel_init_send_data(&channel->base, SPICE_MSG_TUNNEL_SOCKET_OPEN, item);
red_channel_add_buf(&channel->base, &channel->send_data.u.socket_open,
spice_marshaller_add_ref(m, (uint8_t*)&channel->send_data.u.socket_open,
sizeof(channel->send_data.u.socket_open));
#ifdef DEBUG_NETWORK
PRINT_SCKT(sckt);
@ -2590,7 +2594,7 @@ static void tunnel_channel_marshall_socket_fin(TunnelChannel *channel, SpiceMars
channel->send_data.u.socket_fin.connection_id = sckt->connection_id;
red_channel_init_send_data(&channel->base, SPICE_MSG_TUNNEL_SOCKET_FIN, item);
red_channel_add_buf(&channel->base, &channel->send_data.u.socket_fin,
spice_marshaller_add_ref(m, (uint8_t*)&channel->send_data.u.socket_fin,
sizeof(channel->send_data.u.socket_fin));
#ifdef DEBUG_NETWORK
PRINT_SCKT(sckt);
@ -2619,7 +2623,7 @@ static void tunnel_channel_marshall_socket_close(TunnelChannel *channel, SpiceMa
channel->send_data.u.socket_close.connection_id = sckt->connection_id;
red_channel_init_send_data(&channel->base, SPICE_MSG_TUNNEL_SOCKET_CLOSE, item);
red_channel_add_buf(&channel->base, &channel->send_data.u.socket_close,
spice_marshaller_add_ref(m, (uint8_t*)&channel->send_data.u.socket_close,
sizeof(channel->send_data.u.socket_close));
#ifdef DEBUG_NETWORK
PRINT_SCKT(sckt);
@ -2635,7 +2639,7 @@ static void tunnel_channel_marshall_socket_closed_ack(TunnelChannel *channel, Sp
// pipe item is null because we free the sckt.
red_channel_init_send_data(&channel->base, SPICE_MSG_TUNNEL_SOCKET_CLOSED_ACK, NULL);
red_channel_add_buf(&channel->base, &channel->send_data.u.socket_close_ack,
spice_marshaller_add_ref(m, (uint8_t*)&channel->send_data.u.socket_close_ack,
sizeof(channel->send_data.u.socket_close_ack));
#ifdef DEBUG_NETWORK
PRINT_SCKT(sckt);
@ -2669,7 +2673,7 @@ static void tunnel_channel_marshall_socket_token(TunnelChannel *channel, SpiceMa
ASSERT(sckt->in_data.client_total_num_tokens <= SOCKET_WINDOW_SIZE);
red_channel_init_send_data(&channel->base, SPICE_MSG_TUNNEL_SOCKET_TOKEN, item);
red_channel_add_buf(&channel->base, &channel->send_data.u.socket_token,
spice_marshaller_add_ref(m, (uint8_t*)&channel->send_data.u.socket_token,
sizeof(channel->send_data.u.socket_token));
}
@ -2697,14 +2701,14 @@ static void tunnel_channel_marshall_socket_out_data(TunnelChannel *channel, Spic
channel->send_data.u.socket_data.connection_id = sckt->connection_id;
red_channel_init_send_data(&channel->base, SPICE_MSG_TUNNEL_SOCKET_DATA, item);
red_channel_add_buf(&channel->base, &channel->send_data.u.socket_data,
spice_marshaller_add_ref(m, (uint8_t*)&channel->send_data.u.socket_data,
sizeof(channel->send_data.u.socket_data));
pushed_bufs_num++;
// the first chunk is in a valid size
chunk = sckt->out_data.ready_chunks_queue.head;
total_push_size = chunk->size - sckt->out_data.ready_chunks_queue.offset;
red_channel_add_buf(&channel->base, chunk->data + sckt->out_data.ready_chunks_queue.offset,
spice_marshaller_add_ref(m, (uint8_t*)chunk->data + sckt->out_data.ready_chunks_queue.offset,
total_push_size);
pushed_bufs_num++;
sckt->out_data.push_tail = chunk;
@ -2714,7 +2718,7 @@ static void tunnel_channel_marshall_socket_out_data(TunnelChannel *channel, Spic
while (chunk && (total_push_size < MAX_SOCKET_DATA_SIZE) && (pushed_bufs_num < MAX_SEND_BUFS)) {
uint32_t cur_push_size = MIN(chunk->size, MAX_SOCKET_DATA_SIZE - total_push_size);
red_channel_add_buf(&channel->base, chunk->data, cur_push_size);
spice_marshaller_add_ref(m, (uint8_t*)chunk->data, cur_push_size);
pushed_bufs_num++;
sckt->out_data.push_tail = chunk;

View File

@ -257,20 +257,21 @@ static void smartcard_channel_release_msg_rcv_buf(RedChannel *channel, SpiceData
free(msg);
}
static void smartcard_channel_send_data(RedChannel *channel, PipeItem *item, VSCMsgHeader *vheader)
static void smartcard_channel_send_data(RedChannel *channel, SpiceMarshaller *m,
PipeItem *item, VSCMsgHeader *vheader)
{
ASSERT(channel);
ASSERT(vheader);
red_channel_init_send_data(channel, SPICE_MSG_SMARTCARD_DATA, item);
red_channel_add_buf(channel, vheader, sizeof(VSCMsgHeader));
spice_marshaller_add_ref(m, (uint8_t*)vheader, sizeof(VSCMsgHeader));
if (vheader->length > 0) {
red_channel_add_buf(channel, (uint8_t*)(vheader+1), vheader->length);
spice_marshaller_add_ref(m, (uint8_t*)(vheader+1), vheader->length);
}
red_channel_begin_send_message(channel);
}
static void smartcard_channel_send_message(RedChannel *channel, PipeItem *item,
uint32_t reader_id, VSCMsgType type, uint8_t* data, uint32_t len)
static void smartcard_channel_send_message(RedChannel *channel, SpiceMarshaller *m,
PipeItem *item, uint32_t reader_id, VSCMsgType type, uint8_t* data, uint32_t len)
{
VSCMsgHeader mhHeader;
//SpiceMarshaller* m = msg->marshaller();
@ -283,38 +284,39 @@ static void smartcard_channel_send_message(RedChannel *channel, PipeItem *item,
//spice_marshaller_add(m, data, len);
//marshaller_outgoing_write(msg);
smartcard_channel_send_data(channel, item, &mhHeader);
smartcard_channel_send_data(channel, m, item, &mhHeader);
}
static void smartcard_channel_send_error(
SmartCardChannel *smartcard_channel, PipeItem *item)
SmartCardChannel *smartcard_channel, SpiceMarshaller *m, PipeItem *item)
{
ErrorItem* error_item = (ErrorItem*)item;
VSCMsgError error;
error.code = error_item->error;
smartcard_channel_send_message(&smartcard_channel->base, item, error_item->reader_id,
VSC_Error, (uint8_t*)&error, sizeof(error));
smartcard_channel_send_message(&smartcard_channel->base, m, item,
error_item->reader_id, VSC_Error, (uint8_t*)&error, sizeof(error));
}
static void smartcard_channel_send_msg(
SmartCardChannel *smartcard_channel, PipeItem *item)
SmartCardChannel *smartcard_channel, SpiceMarshaller *m, PipeItem *item)
{
MsgItem* msg_item = (MsgItem*)item;
smartcard_channel_send_data(&smartcard_channel->base, item, msg_item->vheader);
smartcard_channel_send_data(&smartcard_channel->base, m, item, msg_item->vheader);
}
static void smartcard_channel_send_item(RedChannel *channel, PipeItem *item)
{
SmartCardChannel *smartcard_channel = (SmartCardChannel *)channel;
SpiceMarshaller *m = red_channel_get_marshaller(channel);
switch (item->type) {
case PIPE_ITEM_TYPE_ERROR:
smartcard_channel_send_error(smartcard_channel, item);
smartcard_channel_send_error(smartcard_channel, m, item);
break;
case PIPE_ITEM_TYPE_MSG:
smartcard_channel_send_msg(smartcard_channel, item);
smartcard_channel_send_msg(smartcard_channel, m, item);
}
}