Files
qemu/net/stream_data.h
Laurent Vivier adf684ce69 net: Refactor stream logic for reuse in '-net passt'
To prepare for the implementation of '-net passt', this patch moves
the generic stream handling functions from net/stream.c into new
net/stream_data.c and net/stream_data.h files.

This refactoring introduces a NetStreamData struct that encapsulates
the generic fields and logic previously in NetStreamState. The
NetStreamState now embeds NetStreamData and delegates the core
stream operations to the new generic functions.

To maintain flexibility for different users of this generic code,
callbacks for send and listen operations are now passed via
function pointers within the NetStreamData struct. This allows
callers to provide their own specific implementations while reusing
the common connection and data transfer logic.

Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2025-07-14 13:27:09 +08:00

32 lines
995 B
C

/*
* net stream generic functions
*
* Copyright Red Hat
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
typedef struct NetStreamData {
NetClientState nc;
QIOChannel *ioc;
guint ioc_read_tag;
guint ioc_write_tag;
SocketReadState rs;
unsigned int send_index; /* number of bytes sent*/
QIOChannelFunc send;
/* server data */
QIOChannel *listen_ioc;
QIONetListener *listener;
QIONetListenerClientFunc listen;
} NetStreamData;
ssize_t net_stream_data_receive(NetStreamData *d, const uint8_t *buf,
size_t size);
void net_stream_data_rs_finalize(SocketReadState *rs);
gboolean net_stream_data_send(QIOChannel *ioc, GIOCondition condition,
NetStreamData *d);
int net_stream_data_client_connected(QIOTask *task, NetStreamData *d);
void net_stream_data_listen(QIONetListener *listener,
QIOChannelSocket *cioc,
NetStreamData *d);