1 /* 2 * QEMU I/O channels sockets driver 3 * 4 * Copyright (c) 2015 Red Hat, Inc. 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, see <http://www.gnu.org/licenses/>. 18 * 19 */ 20 21 #include "qemu/osdep.h" 22 #include "qapi/error.h" 23 #include "qapi/qapi-visit-sockets.h" 24 #include "io/channel-socket.h" 25 #include "io/channel-watch.h" 26 #include "trace.h" 27 #include "qapi/clone-visitor.h" 28 29 #define SOCKET_MAX_FDS 16 30 31 SocketAddress * 32 qio_channel_socket_get_local_address(QIOChannelSocket *ioc, 33 Error **errp) 34 { 35 return socket_sockaddr_to_address(&ioc->localAddr, 36 ioc->localAddrLen, 37 errp); 38 } 39 40 SocketAddress * 41 qio_channel_socket_get_remote_address(QIOChannelSocket *ioc, 42 Error **errp) 43 { 44 return socket_sockaddr_to_address(&ioc->remoteAddr, 45 ioc->remoteAddrLen, 46 errp); 47 } 48 49 QIOChannelSocket * 50 qio_channel_socket_new(void) 51 { 52 QIOChannelSocket *sioc; 53 QIOChannel *ioc; 54 55 sioc = QIO_CHANNEL_SOCKET(object_new(TYPE_QIO_CHANNEL_SOCKET)); 56 sioc->fd = -1; 57 58 ioc = QIO_CHANNEL(sioc); 59 qio_channel_set_feature(ioc, QIO_CHANNEL_FEATURE_SHUTDOWN); 60 61 #ifdef WIN32 62 ioc->event = CreateEvent(NULL, FALSE, FALSE, NULL); 63 #endif 64 65 trace_qio_channel_socket_new(sioc); 66 67 return sioc; 68 } 69 70 71 static int 72 qio_channel_socket_set_fd(QIOChannelSocket *sioc, 73 int fd, 74 Error **errp) 75 { 76 if (sioc->fd != -1) { 77 error_setg(errp, "Socket is already open"); 78 return -1; 79 } 80 81 sioc->fd = fd; 82 sioc->remoteAddrLen = sizeof(sioc->remoteAddr); 83 sioc->localAddrLen = sizeof(sioc->localAddr); 84 85 86 if (getpeername(fd, (struct sockaddr *)&sioc->remoteAddr, 87 &sioc->remoteAddrLen) < 0) { 88 if (errno == ENOTCONN) { 89 memset(&sioc->remoteAddr, 0, sizeof(sioc->remoteAddr)); 90 sioc->remoteAddrLen = sizeof(sioc->remoteAddr); 91 } else { 92 error_setg_errno(errp, errno, 93 "Unable to query remote socket address"); 94 goto error; 95 } 96 } 97 98 if (getsockname(fd, (struct sockaddr *)&sioc->localAddr, 99 &sioc->localAddrLen) < 0) { 100 error_setg_errno(errp, errno, 101 "Unable to query local socket address"); 102 goto error; 103 } 104 105 #ifndef WIN32 106 if (sioc->localAddr.ss_family == AF_UNIX) { 107 QIOChannel *ioc = QIO_CHANNEL(sioc); 108 qio_channel_set_feature(ioc, QIO_CHANNEL_FEATURE_FD_PASS); 109 } 110 #endif /* WIN32 */ 111 112 return 0; 113 114 error: 115 sioc->fd = -1; /* Let the caller close FD on failure */ 116 return -1; 117 } 118 119 QIOChannelSocket * 120 qio_channel_socket_new_fd(int fd, 121 Error **errp) 122 { 123 QIOChannelSocket *ioc; 124 125 ioc = qio_channel_socket_new(); 126 if (qio_channel_socket_set_fd(ioc, fd, errp) < 0) { 127 object_unref(OBJECT(ioc)); 128 return NULL; 129 } 130 131 trace_qio_channel_socket_new_fd(ioc, fd); 132 133 return ioc; 134 } 135 136 137 int qio_channel_socket_connect_sync(QIOChannelSocket *ioc, 138 SocketAddress *addr, 139 Error **errp) 140 { 141 int fd; 142 143 trace_qio_channel_socket_connect_sync(ioc, addr); 144 fd = socket_connect(addr, errp); 145 if (fd < 0) { 146 trace_qio_channel_socket_connect_fail(ioc); 147 return -1; 148 } 149 150 trace_qio_channel_socket_connect_complete(ioc, fd); 151 if (qio_channel_socket_set_fd(ioc, fd, errp) < 0) { 152 close(fd); 153 return -1; 154 } 155 156 return 0; 157 } 158 159 160 static void qio_channel_socket_connect_worker(QIOTask *task, 161 gpointer opaque) 162 { 163 QIOChannelSocket *ioc = QIO_CHANNEL_SOCKET(qio_task_get_source(task)); 164 SocketAddress *addr = opaque; 165 Error *err = NULL; 166 167 qio_channel_socket_connect_sync(ioc, addr, &err); 168 169 qio_task_set_error(task, err); 170 } 171 172 173 void qio_channel_socket_connect_async(QIOChannelSocket *ioc, 174 SocketAddress *addr, 175 QIOTaskFunc callback, 176 gpointer opaque, 177 GDestroyNotify destroy) 178 { 179 QIOTask *task = qio_task_new( 180 OBJECT(ioc), callback, opaque, destroy); 181 SocketAddress *addrCopy; 182 183 addrCopy = QAPI_CLONE(SocketAddress, addr); 184 185 /* socket_connect() does a non-blocking connect(), but it 186 * still blocks in DNS lookups, so we must use a thread */ 187 trace_qio_channel_socket_connect_async(ioc, addr); 188 qio_task_run_in_thread(task, 189 qio_channel_socket_connect_worker, 190 addrCopy, 191 (GDestroyNotify)qapi_free_SocketAddress); 192 } 193 194 195 int qio_channel_socket_listen_sync(QIOChannelSocket *ioc, 196 SocketAddress *addr, 197 Error **errp) 198 { 199 int fd; 200 201 trace_qio_channel_socket_listen_sync(ioc, addr); 202 fd = socket_listen(addr, errp); 203 if (fd < 0) { 204 trace_qio_channel_socket_listen_fail(ioc); 205 return -1; 206 } 207 208 trace_qio_channel_socket_listen_complete(ioc, fd); 209 if (qio_channel_socket_set_fd(ioc, fd, errp) < 0) { 210 close(fd); 211 return -1; 212 } 213 qio_channel_set_feature(QIO_CHANNEL(ioc), QIO_CHANNEL_FEATURE_LISTEN); 214 215 return 0; 216 } 217 218 219 static void qio_channel_socket_listen_worker(QIOTask *task, 220 gpointer opaque) 221 { 222 QIOChannelSocket *ioc = QIO_CHANNEL_SOCKET(qio_task_get_source(task)); 223 SocketAddress *addr = opaque; 224 Error *err = NULL; 225 226 qio_channel_socket_listen_sync(ioc, addr, &err); 227 228 qio_task_set_error(task, err); 229 } 230 231 232 void qio_channel_socket_listen_async(QIOChannelSocket *ioc, 233 SocketAddress *addr, 234 QIOTaskFunc callback, 235 gpointer opaque, 236 GDestroyNotify destroy) 237 { 238 QIOTask *task = qio_task_new( 239 OBJECT(ioc), callback, opaque, destroy); 240 SocketAddress *addrCopy; 241 242 addrCopy = QAPI_CLONE(SocketAddress, addr); 243 244 /* socket_listen() blocks in DNS lookups, so we must use a thread */ 245 trace_qio_channel_socket_listen_async(ioc, addr); 246 qio_task_run_in_thread(task, 247 qio_channel_socket_listen_worker, 248 addrCopy, 249 (GDestroyNotify)qapi_free_SocketAddress); 250 } 251 252 253 int qio_channel_socket_dgram_sync(QIOChannelSocket *ioc, 254 SocketAddress *localAddr, 255 SocketAddress *remoteAddr, 256 Error **errp) 257 { 258 int fd; 259 260 trace_qio_channel_socket_dgram_sync(ioc, localAddr, remoteAddr); 261 fd = socket_dgram(remoteAddr, localAddr, errp); 262 if (fd < 0) { 263 trace_qio_channel_socket_dgram_fail(ioc); 264 return -1; 265 } 266 267 trace_qio_channel_socket_dgram_complete(ioc, fd); 268 if (qio_channel_socket_set_fd(ioc, fd, errp) < 0) { 269 close(fd); 270 return -1; 271 } 272 273 return 0; 274 } 275 276 277 struct QIOChannelSocketDGramWorkerData { 278 SocketAddress *localAddr; 279 SocketAddress *remoteAddr; 280 }; 281 282 283 static void qio_channel_socket_dgram_worker_free(gpointer opaque) 284 { 285 struct QIOChannelSocketDGramWorkerData *data = opaque; 286 qapi_free_SocketAddress(data->localAddr); 287 qapi_free_SocketAddress(data->remoteAddr); 288 g_free(data); 289 } 290 291 static void qio_channel_socket_dgram_worker(QIOTask *task, 292 gpointer opaque) 293 { 294 QIOChannelSocket *ioc = QIO_CHANNEL_SOCKET(qio_task_get_source(task)); 295 struct QIOChannelSocketDGramWorkerData *data = opaque; 296 Error *err = NULL; 297 298 /* socket_dgram() blocks in DNS lookups, so we must use a thread */ 299 qio_channel_socket_dgram_sync(ioc, data->localAddr, 300 data->remoteAddr, &err); 301 302 qio_task_set_error(task, err); 303 } 304 305 306 void qio_channel_socket_dgram_async(QIOChannelSocket *ioc, 307 SocketAddress *localAddr, 308 SocketAddress *remoteAddr, 309 QIOTaskFunc callback, 310 gpointer opaque, 311 GDestroyNotify destroy) 312 { 313 QIOTask *task = qio_task_new( 314 OBJECT(ioc), callback, opaque, destroy); 315 struct QIOChannelSocketDGramWorkerData *data = g_new0( 316 struct QIOChannelSocketDGramWorkerData, 1); 317 318 data->localAddr = QAPI_CLONE(SocketAddress, localAddr); 319 data->remoteAddr = QAPI_CLONE(SocketAddress, remoteAddr); 320 321 trace_qio_channel_socket_dgram_async(ioc, localAddr, remoteAddr); 322 qio_task_run_in_thread(task, 323 qio_channel_socket_dgram_worker, 324 data, 325 qio_channel_socket_dgram_worker_free); 326 } 327 328 329 QIOChannelSocket * 330 qio_channel_socket_accept(QIOChannelSocket *ioc, 331 Error **errp) 332 { 333 QIOChannelSocket *cioc; 334 335 cioc = qio_channel_socket_new(); 336 cioc->remoteAddrLen = sizeof(ioc->remoteAddr); 337 cioc->localAddrLen = sizeof(ioc->localAddr); 338 339 retry: 340 trace_qio_channel_socket_accept(ioc); 341 cioc->fd = qemu_accept(ioc->fd, (struct sockaddr *)&cioc->remoteAddr, 342 &cioc->remoteAddrLen); 343 if (cioc->fd < 0) { 344 if (errno == EINTR) { 345 goto retry; 346 } 347 error_setg_errno(errp, errno, "Unable to accept connection"); 348 trace_qio_channel_socket_accept_fail(ioc); 349 goto error; 350 } 351 352 if (getsockname(cioc->fd, (struct sockaddr *)&cioc->localAddr, 353 &cioc->localAddrLen) < 0) { 354 error_setg_errno(errp, errno, 355 "Unable to query local socket address"); 356 goto error; 357 } 358 359 #ifndef WIN32 360 if (cioc->localAddr.ss_family == AF_UNIX) { 361 QIOChannel *ioc_local = QIO_CHANNEL(cioc); 362 qio_channel_set_feature(ioc_local, QIO_CHANNEL_FEATURE_FD_PASS); 363 } 364 #endif /* WIN32 */ 365 366 trace_qio_channel_socket_accept_complete(ioc, cioc, cioc->fd); 367 return cioc; 368 369 error: 370 object_unref(OBJECT(cioc)); 371 return NULL; 372 } 373 374 static void qio_channel_socket_init(Object *obj) 375 { 376 QIOChannelSocket *ioc = QIO_CHANNEL_SOCKET(obj); 377 ioc->fd = -1; 378 } 379 380 static void qio_channel_socket_finalize(Object *obj) 381 { 382 QIOChannelSocket *ioc = QIO_CHANNEL_SOCKET(obj); 383 384 if (ioc->fd != -1) { 385 QIOChannel *ioc_local = QIO_CHANNEL(ioc); 386 if (qio_channel_has_feature(ioc_local, QIO_CHANNEL_FEATURE_LISTEN)) { 387 Error *err = NULL; 388 389 socket_listen_cleanup(ioc->fd, &err); 390 if (err) { 391 error_report_err(err); 392 err = NULL; 393 } 394 } 395 #ifdef WIN32 396 WSAEventSelect(ioc->fd, NULL, 0); 397 #endif 398 closesocket(ioc->fd); 399 ioc->fd = -1; 400 } 401 } 402 403 404 #ifndef WIN32 405 static void qio_channel_socket_copy_fds(struct msghdr *msg, 406 int **fds, size_t *nfds) 407 { 408 struct cmsghdr *cmsg; 409 410 *nfds = 0; 411 *fds = NULL; 412 413 for (cmsg = CMSG_FIRSTHDR(msg); cmsg; cmsg = CMSG_NXTHDR(msg, cmsg)) { 414 int fd_size, i; 415 int gotfds; 416 417 if (cmsg->cmsg_len < CMSG_LEN(sizeof(int)) || 418 cmsg->cmsg_level != SOL_SOCKET || 419 cmsg->cmsg_type != SCM_RIGHTS) { 420 continue; 421 } 422 423 fd_size = cmsg->cmsg_len - CMSG_LEN(0); 424 425 if (!fd_size) { 426 continue; 427 } 428 429 gotfds = fd_size / sizeof(int); 430 *fds = g_renew(int, *fds, *nfds + gotfds); 431 memcpy(*fds + *nfds, CMSG_DATA(cmsg), fd_size); 432 433 for (i = 0; i < gotfds; i++) { 434 int fd = (*fds)[*nfds + i]; 435 if (fd < 0) { 436 continue; 437 } 438 439 /* O_NONBLOCK is preserved across SCM_RIGHTS so reset it */ 440 qemu_set_block(fd); 441 442 #ifndef MSG_CMSG_CLOEXEC 443 qemu_set_cloexec(fd); 444 #endif 445 } 446 *nfds += gotfds; 447 } 448 } 449 450 451 static ssize_t qio_channel_socket_readv(QIOChannel *ioc, 452 const struct iovec *iov, 453 size_t niov, 454 int **fds, 455 size_t *nfds, 456 Error **errp) 457 { 458 QIOChannelSocket *sioc = QIO_CHANNEL_SOCKET(ioc); 459 ssize_t ret; 460 struct msghdr msg = { NULL, }; 461 char control[CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)]; 462 int sflags = 0; 463 464 memset(control, 0, CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)); 465 466 #ifdef MSG_CMSG_CLOEXEC 467 sflags |= MSG_CMSG_CLOEXEC; 468 #endif 469 470 msg.msg_iov = (struct iovec *)iov; 471 msg.msg_iovlen = niov; 472 if (fds && nfds) { 473 msg.msg_control = control; 474 msg.msg_controllen = sizeof(control); 475 } 476 477 retry: 478 ret = recvmsg(sioc->fd, &msg, sflags); 479 if (ret < 0) { 480 if (errno == EAGAIN) { 481 return QIO_CHANNEL_ERR_BLOCK; 482 } 483 if (errno == EINTR) { 484 goto retry; 485 } 486 487 error_setg_errno(errp, errno, 488 "Unable to read from socket"); 489 return -1; 490 } 491 492 if (fds && nfds) { 493 qio_channel_socket_copy_fds(&msg, fds, nfds); 494 } 495 496 return ret; 497 } 498 499 static ssize_t qio_channel_socket_writev(QIOChannel *ioc, 500 const struct iovec *iov, 501 size_t niov, 502 int *fds, 503 size_t nfds, 504 Error **errp) 505 { 506 QIOChannelSocket *sioc = QIO_CHANNEL_SOCKET(ioc); 507 ssize_t ret; 508 struct msghdr msg = { NULL, }; 509 char control[CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)]; 510 size_t fdsize = sizeof(int) * nfds; 511 struct cmsghdr *cmsg; 512 513 memset(control, 0, CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)); 514 515 msg.msg_iov = (struct iovec *)iov; 516 msg.msg_iovlen = niov; 517 518 if (nfds) { 519 if (nfds > SOCKET_MAX_FDS) { 520 error_setg_errno(errp, EINVAL, 521 "Only %d FDs can be sent, got %zu", 522 SOCKET_MAX_FDS, nfds); 523 return -1; 524 } 525 526 msg.msg_control = control; 527 msg.msg_controllen = CMSG_SPACE(sizeof(int) * nfds); 528 529 cmsg = CMSG_FIRSTHDR(&msg); 530 cmsg->cmsg_len = CMSG_LEN(fdsize); 531 cmsg->cmsg_level = SOL_SOCKET; 532 cmsg->cmsg_type = SCM_RIGHTS; 533 memcpy(CMSG_DATA(cmsg), fds, fdsize); 534 } 535 536 retry: 537 ret = sendmsg(sioc->fd, &msg, 0); 538 if (ret <= 0) { 539 if (errno == EAGAIN) { 540 return QIO_CHANNEL_ERR_BLOCK; 541 } 542 if (errno == EINTR) { 543 goto retry; 544 } 545 error_setg_errno(errp, errno, 546 "Unable to write to socket"); 547 return -1; 548 } 549 return ret; 550 } 551 #else /* WIN32 */ 552 static ssize_t qio_channel_socket_readv(QIOChannel *ioc, 553 const struct iovec *iov, 554 size_t niov, 555 int **fds, 556 size_t *nfds, 557 Error **errp) 558 { 559 QIOChannelSocket *sioc = QIO_CHANNEL_SOCKET(ioc); 560 ssize_t done = 0; 561 ssize_t i; 562 563 for (i = 0; i < niov; i++) { 564 ssize_t ret; 565 retry: 566 ret = recv(sioc->fd, 567 iov[i].iov_base, 568 iov[i].iov_len, 569 0); 570 if (ret < 0) { 571 if (errno == EAGAIN) { 572 if (done) { 573 return done; 574 } else { 575 return QIO_CHANNEL_ERR_BLOCK; 576 } 577 } else if (errno == EINTR) { 578 goto retry; 579 } else { 580 error_setg_errno(errp, errno, 581 "Unable to read from socket"); 582 return -1; 583 } 584 } 585 done += ret; 586 if (ret < iov[i].iov_len) { 587 return done; 588 } 589 } 590 591 return done; 592 } 593 594 static ssize_t qio_channel_socket_writev(QIOChannel *ioc, 595 const struct iovec *iov, 596 size_t niov, 597 int *fds, 598 size_t nfds, 599 Error **errp) 600 { 601 QIOChannelSocket *sioc = QIO_CHANNEL_SOCKET(ioc); 602 ssize_t done = 0; 603 ssize_t i; 604 605 for (i = 0; i < niov; i++) { 606 ssize_t ret; 607 retry: 608 ret = send(sioc->fd, 609 iov[i].iov_base, 610 iov[i].iov_len, 611 0); 612 if (ret < 0) { 613 if (errno == EAGAIN) { 614 if (done) { 615 return done; 616 } else { 617 return QIO_CHANNEL_ERR_BLOCK; 618 } 619 } else if (errno == EINTR) { 620 goto retry; 621 } else { 622 error_setg_errno(errp, errno, 623 "Unable to write to socket"); 624 return -1; 625 } 626 } 627 done += ret; 628 if (ret < iov[i].iov_len) { 629 return done; 630 } 631 } 632 633 return done; 634 } 635 #endif /* WIN32 */ 636 637 static int 638 qio_channel_socket_set_blocking(QIOChannel *ioc, 639 bool enabled, 640 Error **errp) 641 { 642 QIOChannelSocket *sioc = QIO_CHANNEL_SOCKET(ioc); 643 644 if (enabled) { 645 qemu_set_block(sioc->fd); 646 } else { 647 qemu_set_nonblock(sioc->fd); 648 } 649 return 0; 650 } 651 652 653 static void 654 qio_channel_socket_set_delay(QIOChannel *ioc, 655 bool enabled) 656 { 657 QIOChannelSocket *sioc = QIO_CHANNEL_SOCKET(ioc); 658 int v = enabled ? 0 : 1; 659 660 qemu_setsockopt(sioc->fd, 661 IPPROTO_TCP, TCP_NODELAY, 662 &v, sizeof(v)); 663 } 664 665 666 static void 667 qio_channel_socket_set_cork(QIOChannel *ioc, 668 bool enabled) 669 { 670 QIOChannelSocket *sioc = QIO_CHANNEL_SOCKET(ioc); 671 int v = enabled ? 1 : 0; 672 673 socket_set_cork(sioc->fd, v); 674 } 675 676 677 static int 678 qio_channel_socket_close(QIOChannel *ioc, 679 Error **errp) 680 { 681 QIOChannelSocket *sioc = QIO_CHANNEL_SOCKET(ioc); 682 683 if (sioc->fd != -1) { 684 #ifdef WIN32 685 WSAEventSelect(sioc->fd, NULL, 0); 686 #endif 687 if (closesocket(sioc->fd) < 0) { 688 sioc->fd = -1; 689 error_setg_errno(errp, errno, 690 "Unable to close socket"); 691 return -1; 692 } 693 sioc->fd = -1; 694 } 695 return 0; 696 } 697 698 static int 699 qio_channel_socket_shutdown(QIOChannel *ioc, 700 QIOChannelShutdown how, 701 Error **errp) 702 { 703 QIOChannelSocket *sioc = QIO_CHANNEL_SOCKET(ioc); 704 int sockhow; 705 706 switch (how) { 707 case QIO_CHANNEL_SHUTDOWN_READ: 708 sockhow = SHUT_RD; 709 break; 710 case QIO_CHANNEL_SHUTDOWN_WRITE: 711 sockhow = SHUT_WR; 712 break; 713 case QIO_CHANNEL_SHUTDOWN_BOTH: 714 default: 715 sockhow = SHUT_RDWR; 716 break; 717 } 718 719 if (shutdown(sioc->fd, sockhow) < 0) { 720 error_setg_errno(errp, errno, 721 "Unable to shutdown socket"); 722 return -1; 723 } 724 return 0; 725 } 726 727 static void qio_channel_socket_set_aio_fd_handler(QIOChannel *ioc, 728 AioContext *ctx, 729 IOHandler *io_read, 730 IOHandler *io_write, 731 void *opaque) 732 { 733 QIOChannelSocket *sioc = QIO_CHANNEL_SOCKET(ioc); 734 aio_set_fd_handler(ctx, sioc->fd, false, io_read, io_write, NULL, opaque); 735 } 736 737 static GSource *qio_channel_socket_create_watch(QIOChannel *ioc, 738 GIOCondition condition) 739 { 740 QIOChannelSocket *sioc = QIO_CHANNEL_SOCKET(ioc); 741 return qio_channel_create_socket_watch(ioc, 742 sioc->fd, 743 condition); 744 } 745 746 static void qio_channel_socket_class_init(ObjectClass *klass, 747 void *class_data G_GNUC_UNUSED) 748 { 749 QIOChannelClass *ioc_klass = QIO_CHANNEL_CLASS(klass); 750 751 ioc_klass->io_writev = qio_channel_socket_writev; 752 ioc_klass->io_readv = qio_channel_socket_readv; 753 ioc_klass->io_set_blocking = qio_channel_socket_set_blocking; 754 ioc_klass->io_close = qio_channel_socket_close; 755 ioc_klass->io_shutdown = qio_channel_socket_shutdown; 756 ioc_klass->io_set_cork = qio_channel_socket_set_cork; 757 ioc_klass->io_set_delay = qio_channel_socket_set_delay; 758 ioc_klass->io_create_watch = qio_channel_socket_create_watch; 759 ioc_klass->io_set_aio_fd_handler = qio_channel_socket_set_aio_fd_handler; 760 } 761 762 static const TypeInfo qio_channel_socket_info = { 763 .parent = TYPE_QIO_CHANNEL, 764 .name = TYPE_QIO_CHANNEL_SOCKET, 765 .instance_size = sizeof(QIOChannelSocket), 766 .instance_init = qio_channel_socket_init, 767 .instance_finalize = qio_channel_socket_finalize, 768 .class_init = qio_channel_socket_class_init, 769 }; 770 771 static void qio_channel_socket_register_types(void) 772 { 773 type_register_static(&qio_channel_socket_info); 774 } 775 776 type_init(qio_channel_socket_register_types); 777