Commit 9977c8943a56b06908555ea6d1706142a3c9da4d
Committed by
Anthony Liguori
1 parent
f707726e
Make tcp_chr_read() use recvmsg()
Split out tcp_chr_recv() out of tcp_chr_read() and implement it on non-win32 using recvmsg(). This is needed for a subsequent patch which implements SCM_RIGHTS support. Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Showing
1 changed file
with
24 additions
and
1 deletions
qemu-char.c
| ... | ... | @@ -1907,6 +1907,29 @@ static void tcp_chr_process_IAC_bytes(CharDriverState *chr, |
| 1907 | 1907 | *size = j; |
| 1908 | 1908 | } |
| 1909 | 1909 | |
| 1910 | +#ifndef WIN32 | |
| 1911 | +static ssize_t tcp_chr_recv(CharDriverState *chr, char *buf, size_t len) | |
| 1912 | +{ | |
| 1913 | + TCPCharDriver *s = chr->opaque; | |
| 1914 | + struct msghdr msg = { 0, }; | |
| 1915 | + struct iovec iov[1]; | |
| 1916 | + | |
| 1917 | + iov[0].iov_base = buf; | |
| 1918 | + iov[0].iov_len = len; | |
| 1919 | + | |
| 1920 | + msg.msg_iov = iov; | |
| 1921 | + msg.msg_iovlen = 1; | |
| 1922 | + | |
| 1923 | + return recvmsg(s->fd, &msg, 0); | |
| 1924 | +} | |
| 1925 | +#else | |
| 1926 | +static ssize_t tcp_chr_recv(CharDriverState *chr, char *buf, size_t len) | |
| 1927 | +{ | |
| 1928 | + TCPCharDriver *s = chr->opaque; | |
| 1929 | + return recv(s->fd, buf, len, 0); | |
| 1930 | +} | |
| 1931 | +#endif | |
| 1932 | + | |
| 1910 | 1933 | static void tcp_chr_read(void *opaque) |
| 1911 | 1934 | { |
| 1912 | 1935 | CharDriverState *chr = opaque; |
| ... | ... | @@ -1919,7 +1942,7 @@ static void tcp_chr_read(void *opaque) |
| 1919 | 1942 | len = sizeof(buf); |
| 1920 | 1943 | if (len > s->max_size) |
| 1921 | 1944 | len = s->max_size; |
| 1922 | - size = recv(s->fd, (void *)buf, len, 0); | |
| 1945 | + size = tcp_chr_recv(chr, (void *)buf, len); | |
| 1923 | 1946 | if (size == 0) { |
| 1924 | 1947 | /* connection closed */ |
| 1925 | 1948 | s->connected = 0; | ... | ... |