本文整理汇总了C++中qemu_set_fd_handler2函数的典型用法代码示例。如果您正苦于以下问题:C++ qemu_set_fd_handler2函数的具体用法?C++ qemu_set_fd_handler2怎么用?C++ qemu_set_fd_handler2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了qemu_set_fd_handler2函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: nbd_co_send_reply
static ssize_t nbd_co_send_reply(NBDRequest *req, struct nbd_reply *reply,
int len)
{
NBDClient *client = req->client;
int csock = client->sock;
ssize_t rc, ret;
qemu_co_mutex_lock(&client->send_lock);
qemu_set_fd_handler2(csock, nbd_can_read, nbd_read,
nbd_restart_write, client);
client->send_coroutine = qemu_coroutine_self();
if (!len) {
rc = nbd_send_reply(csock, reply);
} else {
socket_set_cork(csock, 1);
rc = nbd_send_reply(csock, reply);
if (rc >= 0) {
ret = qemu_co_send(csock, req->data, len);
if (ret != len) {
rc = -EIO;
}
}
socket_set_cork(csock, 0);
}
client->send_coroutine = NULL;
qemu_set_fd_handler2(csock, nbd_can_read, nbd_read, NULL, client);
qemu_co_mutex_unlock(&client->send_lock);
return rc;
}
示例2: vncws_handshake_read
void vncws_handshake_read(void *opaque)
{
VncState *vs = opaque;
uint8_t *handshake_end;
long ret;
/* Typical HTTP headers from novnc are 512 bytes, so limiting
* total header size to 4096 is easily enough. */
size_t want = 4096 - vs->ws_input.offset;
buffer_reserve(&vs->ws_input, want);
ret = vnc_client_read_buf(vs, buffer_end(&vs->ws_input), want);
if (!ret) {
if (vs->csock == -1) {
vnc_disconnect_finish(vs);
}
return;
}
vs->ws_input.offset += ret;
handshake_end = (uint8_t *)g_strstr_len((char *)vs->ws_input.buffer,
vs->ws_input.offset, WS_HANDSHAKE_END);
if (handshake_end) {
qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, vs);
vncws_process_handshake(vs, vs->ws_input.buffer, vs->ws_input.offset);
buffer_advance(&vs->ws_input, handshake_end - vs->ws_input.buffer +
strlen(WS_HANDSHAKE_END));
} else if (vs->ws_input.offset >= 4096) {
VNC_DEBUG("End of headers not found in first 4096 bytes\n");
vnc_client_error(vs);
}
}
示例3: unmap_disk
static void unmap_disk(struct td_state *s)
{
tapdev_info_t *info = s->ring_info;
fd_list_entry_t *entry;
bdrv_close(s->bs);
if (info != NULL && info->mem > 0)
munmap(info->mem, getpagesize() * BLKTAP_MMAP_REGION_SIZE);
entry = s->fd_entry;
*entry->pprev = entry->next;
if (entry->next)
entry->next->pprev = entry->pprev;
qemu_set_fd_handler2(info->fd, NULL, NULL, NULL, NULL);
close(info->fd);
free(s->fd_entry);
free(s->blkif);
free(s->ring_info);
free(s);
return;
}
示例4: vncws_handshake_read
void vncws_handshake_read(void *opaque)
{
VncState *vs = opaque;
uint8_t *handshake_end;
long ret;
buffer_reserve(&vs->ws_input, 4096);
ret = vnc_client_read_buf(vs, buffer_end(&vs->ws_input), 4096);
if (!ret) {
if (vs->csock == -1) {
vnc_disconnect_finish(vs);
}
return;
}
vs->ws_input.offset += ret;
handshake_end = (uint8_t *)g_strstr_len((char *)vs->ws_input.buffer,
vs->ws_input.offset, WS_HANDSHAKE_END);
if (handshake_end) {
qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, vs);
vncws_process_handshake(vs, vs->ws_input.buffer, vs->ws_input.offset);
buffer_advance(&vs->ws_input, handshake_end - vs->ws_input.buffer +
strlen(WS_HANDSHAKE_END));
}
}
示例5: vnc_start_vencrypt_handshake
static int vnc_start_vencrypt_handshake(struct VncState *vs) {
int ret;
if ((ret = gnutls_handshake(vs->tls.session)) < 0) {
if (!gnutls_error_is_fatal(ret)) {
VNC_DEBUG("Handshake interrupted (blocking)\n");
if (!gnutls_record_get_direction(vs->tls.session))
qemu_set_fd_handler(vs->csock, vnc_tls_handshake_io, NULL, vs);
else
qemu_set_fd_handler(vs->csock, NULL, vnc_tls_handshake_io, vs);
return 0;
}
VNC_DEBUG("Handshake failed %s\n", gnutls_strerror(ret));
vnc_client_error(vs);
return -1;
}
if (vs->vd->tls.x509verify) {
if (vnc_tls_validate_certificate(vs) < 0) {
VNC_DEBUG("Client verification failed\n");
vnc_client_error(vs);
return -1;
} else {
VNC_DEBUG("Client verification passed\n");
}
}
VNC_DEBUG("Handshake done, switching to TLS data mode\n");
vs->tls.wiremode = VNC_WIREMODE_TLS;
qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, vnc_client_write, vs);
start_auth_vencrypt_subauth(vs);
return 0;
}
示例6: tcp_start_incoming_migration
int tcp_start_incoming_migration(const char *host_port)
{
SockAddress addr;
int s;
if (parse_host_port(&addr, host_port) < 0) {
fprintf(stderr, "invalid host/port combination: %s\n", host_port);
return -EINVAL;
}
s = socket_create_inet(SOCKET_STREAM);
if (s == -1)
return -socket_error();
socket_set_xreuseaddr(s);
if (socket_bind(s, &addr) == -1)
goto err;
if (socket_listen(s, 1) == -1)
goto err;
qemu_set_fd_handler2(s, NULL, tcp_accept_incoming_migration, NULL,
(void *)(unsigned long)s);
return 0;
err:
socket_close(s);
return -socket_error();
}
示例7: tcp_accept_incoming_migration
static void tcp_accept_incoming_migration(void *opaque)
{
struct sockaddr_in addr;
socklen_t addrlen = sizeof(addr);
int s = (unsigned long)opaque;
QEMUFile *f;
int c;
do {
c = qemu_accept(s, (struct sockaddr *)&addr, &addrlen);
} while (c == -1 && socket_error() == EINTR);
DPRINTF("accepted migration\n");
if (c == -1) {
fprintf(stderr, "could not accept migration connection\n");
return;
}
f = qemu_fopen_socket(c);
if (f == NULL) {
fprintf(stderr, "could not qemu_fopen socket\n");
goto out;
}
process_incoming_migration(f);
qemu_fclose(f);
out:
qemu_set_fd_handler2(s, NULL, NULL, NULL, NULL);
close(s);
close(c);
}
示例8: migrate_fd_cleanup
int migrate_fd_cleanup(FdMigrationState *s)
{
int ret = 0;
qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL);
if (s->file) {
DPRINTF("closing file\n");
if (qemu_fclose(s->file) != 0) {
ret = -1;
}
s->file = NULL;
} else {
if (s->mon) {
monitor_resume(s->mon);
}
}
if (s->fd != -1) {
close(s->fd);
s->fd = -1;
}
return ret;
}
示例9: tcp_start_incoming_migration
int tcp_start_incoming_migration(const char *host_port)
{
struct sockaddr_in addr;
int val;
int s;
if (parse_host_port(&addr, host_port) < 0) {
fprintf(stderr, "invalid host/port combination: %s\n", host_port);
return -EINVAL;
}
s = socket(PF_INET, SOCK_STREAM, 0);
if (s == -1)
return -socket_error();
val = 1;
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (const char *)&val, sizeof(val));
if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) == -1)
goto err;
if (listen(s, 1) == -1)
goto err;
qemu_set_fd_handler2(s, NULL, tcp_accept_incoming_migration, NULL,
(void *)(unsigned long)s);
return 0;
err:
close(s);
return -socket_error();
}
示例10: tcp_wait_for_connect
static void tcp_wait_for_connect(void *opaque)
{
FdMigrationState *s = opaque;
int val, ret;
socklen_t valsize = sizeof(val);
dprintf("connect completed\n");
do {
ret = getsockopt(s->fd, SOL_SOCKET, SO_ERROR, (char *)&val, &valsize);
} while (ret == -1 && (s->get_error(s)) == EINTR);
if (ret < 0) {
migrate_fd_error(s);
return;
}
qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL);
if (val == 0)
migrate_fd_connect(s);
else {
dprintf("error connecting %d\n", val);
migrate_fd_error(s);
}
}
示例11: qemu_event_init
static int qemu_event_init(void)
{
int err;
int fds[2];
err = pipe(fds);
if (err == -1)
return -errno;
err = fcntl_setfl(fds[0], O_NONBLOCK);
if (err < 0)
goto fail;
err = fcntl_setfl(fds[1], O_NONBLOCK);
if (err < 0)
goto fail;
qemu_set_fd_handler2(fds[0], NULL, qemu_event_read, NULL,
(void *)(unsigned long)fds[0]);
io_thread_fd = fds[1];
return 0;
fail:
close(fds[0]);
close(fds[1]);
return err;
}
示例12: qemu_event_init
static int qemu_event_init(void)
{
int err;
int fds[2];
err = qemu_eventfd(fds);
if (err == -1) {
return -errno;
}
err = fcntl_setfl(fds[0], O_NONBLOCK);
if (err < 0) {
goto fail;
}
err = fcntl_setfl(fds[1], O_NONBLOCK);
if (err < 0) {
goto fail;
}
qemu_set_fd_handler2(fds[0], NULL, qemu_event_read, NULL,
(void *)(intptr_t)fds[0]);
io_thread_fd = fds[1];
return 0;
fail:
close(fds[0]);
close(fds[1]);
return err;
}
示例13: vncws_start_tls_handshake
static int vncws_start_tls_handshake(struct VncState *vs)
{
int ret = gnutls_handshake(vs->ws_tls.session);
if (ret < 0) {
if (!gnutls_error_is_fatal(ret)) {
VNC_DEBUG("Handshake interrupted (blocking)\n");
if (!gnutls_record_get_direction(vs->ws_tls.session)) {
qemu_set_fd_handler(vs->csock, vncws_tls_handshake_io,
NULL, vs);
} else {
qemu_set_fd_handler(vs->csock, NULL, vncws_tls_handshake_io,
vs);
}
return 0;
}
VNC_DEBUG("Handshake failed %s\n", gnutls_strerror(ret));
vnc_client_error(vs);
return -1;
}
VNC_DEBUG("Handshake done, switching to TLS data mode\n");
vs->ws_tls.wiremode = VNC_WIREMODE_TLS;
qemu_set_fd_handler2(vs->csock, NULL, vncws_handshake_read, NULL, vs);
return 0;
}
示例14: migrate_fd_close
int migrate_fd_close(void *opaque)
{
FdMigrationState *s = opaque;
qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL);
return s->close(s);
}
示例15: migrate_fd_cleanup
int migrate_fd_cleanup(FdMigrationState *s)
{
int ret = 0;
qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL);
if (s->file) {
DPRINTF("closing file\n");
if (qemu_fclose(s->file) != 0) {
ret = -1;
}
s->file = NULL;
}
if (s->fd != -1)
close(s->fd);
/* Don't resume monitor until we've flushed all of the buffers */
if (s->mon) {
monitor_resume(s->mon);
}
s->fd = -1;
return ret;
}