mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-27 12:23:53 -06:00
socket shutdown
Add QEMUFile interface to allow a socket to be 'shut down' - i.e. any reads/writes will fail (and any blocking read/write will be woken). Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Amit Shah <amit.shah@redhat.com> Signed-off-by: Amit Shah <amit.shah@redhat.com>
This commit is contained in:
parent
8580b06498
commit
e1a8c9b67f
4 changed files with 48 additions and 4 deletions
|
@ -26,6 +26,7 @@
|
|||
#include "qemu/sockets.h"
|
||||
#include "block/coroutine.h"
|
||||
#include "migration/qemu-file.h"
|
||||
#include "migration/qemu-file-internal.h"
|
||||
|
||||
typedef struct QEMUFileSocket {
|
||||
int fd;
|
||||
|
@ -84,6 +85,17 @@ static int socket_close(void *opaque)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int socket_shutdown(void *opaque, bool rd, bool wr)
|
||||
{
|
||||
QEMUFileSocket *s = opaque;
|
||||
|
||||
if (shutdown(s->fd, rd ? (wr ? SHUT_RDWR : SHUT_RD) : SHUT_WR)) {
|
||||
return -errno;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static ssize_t unix_writev_buffer(void *opaque, struct iovec *iov, int iovcnt,
|
||||
int64_t pos)
|
||||
{
|
||||
|
@ -192,15 +204,18 @@ QEMUFile *qemu_fdopen(int fd, const char *mode)
|
|||
}
|
||||
|
||||
static const QEMUFileOps socket_read_ops = {
|
||||
.get_fd = socket_get_fd,
|
||||
.get_fd = socket_get_fd,
|
||||
.get_buffer = socket_get_buffer,
|
||||
.close = socket_close
|
||||
.close = socket_close,
|
||||
.shut_down = socket_shutdown
|
||||
|
||||
};
|
||||
|
||||
static const QEMUFileOps socket_write_ops = {
|
||||
.get_fd = socket_get_fd,
|
||||
.get_fd = socket_get_fd,
|
||||
.writev_buffer = socket_writev_buffer,
|
||||
.close = socket_close
|
||||
.close = socket_close,
|
||||
.shut_down = socket_shutdown
|
||||
};
|
||||
|
||||
QEMUFile *qemu_fopen_socket(int fd, const char *mode)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue