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