diff options
author | Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | 2016-05-13 15:35:19 +0800 |
---|---|---|
committer | Jason Wang <jasowang@redhat.com> | 2016-06-01 09:25:29 +0800 |
commit | 16a3df403b10c4ac347159e39005fd520b2648bb (patch) | |
tree | 50ade2b78e5758951e34c077ae207393fe95813f /include | |
parent | d30300f771bffc3964e86472e0c21607521a2e24 (diff) |
net/net: Add SocketReadState for reuse codes
This function is from net/socket.c, move it to net.c and net.h.
Add SocketReadState to make others reuse net_fill_rstate().
suggestion from jason.
v4:
- move 'rs->finalize = finalize' to rs_init()
v3:
- remove SocketReadState init callback
- put finalize callback to net_fill_rstate()
v2:
- rename ReadState to SocketReadState
- add SocketReadState init and finalize callback
v1:
- init patch
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/net/net.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/include/net/net.h b/include/net/net.h index 059a464212..50b10504c5 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -57,6 +57,8 @@ typedef void (SetOffload)(NetClientState *, int, int, int, int, int); typedef void (SetVnetHdrLen)(NetClientState *, int); typedef int (SetVnetLE)(NetClientState *, bool); typedef int (SetVnetBE)(NetClientState *, bool); +typedef struct SocketReadState SocketReadState; +typedef void (SocketReadStateFinalize)(SocketReadState *rs); typedef struct NetClientInfo { NetClientOptionsKind type; @@ -102,6 +104,15 @@ typedef struct NICState { bool peer_deleted; } NICState; +struct SocketReadState { + int state; /* 0 = getting length, 1 = getting data */ + uint32_t index; + uint32_t packet_len; + uint8_t buf[NET_BUFSIZE]; + SocketReadStateFinalize *finalize; +}; + +int net_fill_rstate(SocketReadState *rs, const uint8_t *buf, int size); char *qemu_mac_strdup_printf(const uint8_t *macaddr); NetClientState *qemu_find_netdev(const char *id); int qemu_find_net_clients_except(const char *id, NetClientState **ncs, @@ -160,6 +171,8 @@ ssize_t qemu_deliver_packet_iov(NetClientState *sender, void print_net_client(Monitor *mon, NetClientState *nc); void hmp_info_network(Monitor *mon, const QDict *qdict); +void net_socket_rs_init(SocketReadState *rs, + SocketReadStateFinalize *finalize); /* NIC info */ |