mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-30 09:53:10 +00:00
Add virSetBlocking() to allow O_NONBLOCK to be toggle on or off
The virSetNonBlock() API only allows enabling non-blocking operations. It doesn't allow turning blocking back on. Add a new API to allow arbitrary toggling. * src/libvirt_private.syms, src/util/util.h src/util/util.c: Add virSetBlocking
This commit is contained in:
parent
30a50fc3b0
commit
2737b6c20b
@ -910,6 +910,7 @@ virRandom;
|
|||||||
virRandomInitialize;
|
virRandomInitialize;
|
||||||
virRun;
|
virRun;
|
||||||
virRunWithHook;
|
virRunWithHook;
|
||||||
|
virSetBlocking;
|
||||||
virSetCloseExec;
|
virSetCloseExec;
|
||||||
virSetNonBlock;
|
virSetNonBlock;
|
||||||
virSetUIDGID;
|
virSetUIDGID;
|
||||||
|
@ -244,16 +244,19 @@ virArgvToString(const char *const *argv)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int virSetNonBlock(int fd) {
|
int virSetBlocking(int fd, bool blocking) {
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
int flags;
|
int flags;
|
||||||
if ((flags = fcntl(fd, F_GETFL)) < 0)
|
if ((flags = fcntl(fd, F_GETFL)) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
flags |= O_NONBLOCK;
|
if (blocking)
|
||||||
|
flags &= ~O_NONBLOCK;
|
||||||
|
else
|
||||||
|
flags |= O_NONBLOCK;
|
||||||
if ((fcntl(fd, F_SETFL, flags)) < 0)
|
if ((fcntl(fd, F_SETFL, flags)) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
#else
|
#else
|
||||||
unsigned long flag = 1;
|
unsigned long flag = blocking ? 0 : 1;
|
||||||
|
|
||||||
/* This is actually Gnulib's replacement rpl_ioctl function.
|
/* This is actually Gnulib's replacement rpl_ioctl function.
|
||||||
* We can't call ioctlsocket directly in any case.
|
* We can't call ioctlsocket directly in any case.
|
||||||
@ -264,6 +267,10 @@ int virSetNonBlock(int fd) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int virSetNonBlock(int fd) {
|
||||||
|
return virSetBlocking(fd, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
|
|
||||||
|
@ -49,6 +49,7 @@ enum {
|
|||||||
VIR_EXEC_CLEAR_CAPS = (1 << 2),
|
VIR_EXEC_CLEAR_CAPS = (1 << 2),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int virSetBlocking(int fd, bool blocking) ATTRIBUTE_RETURN_CHECK;
|
||||||
int virSetNonBlock(int fd) ATTRIBUTE_RETURN_CHECK;
|
int virSetNonBlock(int fd) ATTRIBUTE_RETURN_CHECK;
|
||||||
int virSetCloseExec(int fd) ATTRIBUTE_RETURN_CHECK;
|
int virSetCloseExec(int fd) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user