Changeset 47b27b40 in mainline
- Timestamp:
- 2013-09-12T14:14:13Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 870f78c
- Parents:
- 38c822e
- Location:
- uspace/srv/hid/rfb
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/rfb/main.c
r38c822e r47b27b40 34 34 #include <abi/ipc/methods.h> 35 35 #include <inttypes.h> 36 #include <io/log.h> 36 37 37 38 #include <abi/fb/visuals.h> … … 158 159 int main(int argc, char **argv) 159 160 { 161 log_init(NAME); 162 160 163 if (argc <= 3) { 161 164 syntax_print(); … … 258 261 259 262 rc = rfb_listen(&rfb, port); 260 if (rc != EOK) 263 if (rc != EOK) { 264 fprintf(stderr, NAME ": Unable to listen at rfb port\n"); 261 265 return 2; 266 } 262 267 263 268 fid_t fib = fibril_create(socket_fibril, NULL); -
uspace/srv/hid/rfb/rfb.c
r38c822e r47b27b40 36 36 #include <byteorder.h> 37 37 #include <macros.h> 38 #include <io/log.h> 38 39 39 40 #include <net/in.h> … … 59 60 60 61 ssize_t rc = recv(fd, rbuf, BUFFER_SIZE, 0); 61 if (rc <= 0) { 62 fprintf(stderr, "recv() failed (%zd)\n", rc); 62 if (rc <= 0) 63 63 return rc; 64 }65 64 66 65 rbuf_in = rc; … … 544 543 rfb->palette = NULL; 545 544 rfb->palette_used = 0; 545 log_msg(LOG_DEFAULT, LVL_DEBUG, 546 "changed pixel format to %d-bit true color (%x<<%d, %x<<%d, %x<<%d)", 547 pixel_format->depth, pixel_format->r_max, pixel_format->r_shift, 548 pixel_format->g_max, pixel_format->g_shift, pixel_format->b_max, 549 pixel_format->b_shift); 546 550 } 547 551 else { … … 553 557 rfb->palette_used = 0; 554 558 } 559 log_msg(LOG_DEFAULT, LVL_DEBUG, "changed pixel format to %d-bit palette", 560 pixel_format->depth); 555 561 } 556 562 return EOK; … … 561 567 /* Version handshake */ 562 568 int rc = send(conn_sd, "RFB 003.008\n", 12, 0); 563 if (rc != EOK) 564 return; 569 if (rc != EOK) { 570 log_msg(LOG_DEFAULT, LVL_WARN, "Failed sending server version %d", rc); 571 return; 572 } 565 573 566 574 char client_version[12]; 567 575 rc = recv_chars(conn_sd, client_version, 12); 568 if (rc != EOK) 569 return; 570 571 if (memcmp(client_version, "RFB 003.008\n", 12) != 0) 572 return; 576 if (rc != EOK) { 577 log_msg(LOG_DEFAULT, LVL_WARN, "Failed receiving client version: %d", rc); 578 return; 579 } 580 581 if (memcmp(client_version, "RFB 003.008\n", 12) != 0) { 582 log_msg(LOG_DEFAULT, LVL_WARN, "Client version is not RFB 3.8"); 583 return; 584 } 573 585 574 586 /* Security handshake … … 579 591 sec_types[1] = RFB_SECURITY_NONE; 580 592 rc = send(conn_sd, sec_types, 2, 0); 581 if (rc != EOK) 582 return; 593 if (rc != EOK) { 594 log_msg(LOG_DEFAULT, LVL_WARN, 595 "Failed sending security handshake: %d", rc); 596 return; 597 } 583 598 584 599 char selected_sec_type = 0; 585 600 rc = recv_char(conn_sd, &selected_sec_type); 586 if (rc != EOK) 587 return; 588 if (selected_sec_type != RFB_SECURITY_NONE) 589 return; 601 if (rc != EOK) { 602 log_msg(LOG_DEFAULT, LVL_WARN, "Failed receiving security type: %d", rc); 603 return; 604 } 605 if (selected_sec_type != RFB_SECURITY_NONE) { 606 log_msg(LOG_DEFAULT, LVL_WARN, 607 "Client selected security type other than none"); 608 return; 609 } 590 610 uint32_t security_result = RFB_SECURITY_HANDSHAKE_OK; 591 611 rc = send(conn_sd, &security_result, sizeof(uint32_t), 0); 592 if (rc != EOK) 593 return; 612 if (rc != EOK) { 613 log_msg(LOG_DEFAULT, LVL_WARN, "Failed sending security result: %d", rc); 614 return; 615 } 594 616 595 617 /* Client init */ 596 618 char shared_flag; 597 619 rc = recv_char(conn_sd, &shared_flag); 598 if (rc != EOK) 599 return; 620 if (rc != EOK) { 621 log_msg(LOG_DEFAULT, LVL_WARN, "Failed receiving client init: %d", rc); 622 return; 623 } 600 624 601 625 /* Server init */ … … 605 629 rfb_server_init_t *server_init = malloc(msg_length); 606 630 if (server_init == NULL) { 631 log_msg(LOG_DEFAULT, LVL_WARN, "Cannot allocate memory for server init"); 607 632 fibril_mutex_unlock(&rfb->lock); 608 633 return; … … 616 641 fibril_mutex_unlock(&rfb->lock); 617 642 rc = send(conn_sd, server_init, msg_length, 0); 618 if (rc != EOK) 619 return; 643 if (rc != EOK) { 644 log_msg(LOG_DEFAULT, LVL_WARN, "Failed sending server init: %d", rc); 645 return; 646 } 620 647 621 648 while (true) { 622 649 char message_type = 0; 623 650 rc = recv_char(conn_sd, &message_type); 624 if (rc != EOK) 651 if (rc != EOK) { 652 log_msg(LOG_DEFAULT, LVL_WARN, 653 "Failed receiving client message type"); 625 654 return; 655 } 626 656 627 657 rfb_set_pixel_format_t spf; … … 635 665 recv_message(conn_sd, message_type, &spf, sizeof(spf)); 636 666 rfb_pixel_format_to_host(&spf.pixel_format, &spf.pixel_format); 667 log_msg(LOG_DEFAULT, LVL_DEBUG2, "Received SetPixelFormat message"); 637 668 fibril_mutex_lock(&rfb->lock); 638 669 rc = rfb_set_pixel_format(rfb, &spf.pixel_format); … … 640 671 if (rc != EOK) 641 672 return; 642 printf("set pixel format\n");643 673 break; 644 674 case RFB_CMSG_SET_ENCODINGS: 645 675 recv_message(conn_sd, message_type, &se, sizeof(se)); 646 676 rfb_set_encodings_to_host(&se, &se); 677 log_msg(LOG_DEFAULT, LVL_DEBUG2, "Received SetEncodings message"); 647 678 for (uint16_t i = 0; i < se.count; i++) { 648 679 int32_t encoding = 0; … … 651 682 return; 652 683 encoding = uint32_t_be2host(encoding); 653 if (encoding == RFB_ENCODING_TRLE) 684 if (encoding == RFB_ENCODING_TRLE) { 685 log_msg(LOG_DEFAULT, LVL_DEBUG, 686 "Client supports TRLE encoding"); 654 687 rfb->supports_trle = true; 655 688 } 656 689 } 657 printf("set encodings\n");658 690 break; 659 691 case RFB_CMSG_FRAMEBUFFER_UPDATE_REQUEST: 660 692 recv_message(conn_sd, message_type, &fbur, sizeof(fbur)); 661 693 rfb_framebuffer_update_request_to_host(&fbur, &fbur); 662 printf("framebuffer update request\n"); 694 log_msg(LOG_DEFAULT, LVL_DEBUG2, 695 "Received FramebufferUpdateRequest message"); 663 696 fibril_mutex_lock(&rfb->lock); 664 697 rfb_send_framebuffer_update(rfb, conn_sd, fbur.incremental); … … 668 701 recv_message(conn_sd, message_type, &ke, sizeof(ke)); 669 702 rfb_key_event_to_host(&ke, &ke); 703 log_msg(LOG_DEFAULT, LVL_DEBUG2, "Received KeyEvent message"); 670 704 break; 671 705 case RFB_CMSG_POINTER_EVENT: 672 706 recv_message(conn_sd, message_type, &pe, sizeof(pe)); 673 707 rfb_pointer_event_to_host(&pe, &pe); 708 log_msg(LOG_DEFAULT, LVL_DEBUG2, "Received PointerEvent message"); 674 709 break; 675 710 case RFB_CMSG_CLIENT_CUT_TEXT: 676 711 recv_message(conn_sd, message_type, &cct, sizeof(cct)); 677 712 rfb_client_cut_text_to_host(&cct, &cct); 713 log_msg(LOG_DEFAULT, LVL_DEBUG2, "Received ClientCutText message"); 678 714 recv_skip_chars(conn_sd, cct.length); 679 715 break; 680 716 default: 717 log_msg(LOG_DEFAULT, LVL_WARN, 718 "Invalid client message type encountered"); 681 719 return; 682 720 } … … 693 731 &addr.sin_addr.s_addr); 694 732 if (rc != EOK) { 695 fprintf(stderr, "Error parsing network address (%s)\n",733 log_msg(LOG_DEFAULT, LVL_ERROR, "Error parsing network address (%s)", 696 734 str_error(rc)); 697 735 return rc; … … 700 738 int listen_sd = socket(PF_INET, SOCK_STREAM, 0); 701 739 if (listen_sd < 0) { 702 fprintf(stderr, "Error creating listening socket (%s)\n",740 log_msg(LOG_DEFAULT, LVL_ERROR, "Error creating listening socket (%s)", 703 741 str_error(listen_sd)); 704 742 return rc; … … 707 745 rc = bind(listen_sd, (struct sockaddr *) &addr, sizeof(addr)); 708 746 if (rc != EOK) { 709 fprintf(stderr, "Error binding socket (%s)\n",747 log_msg(LOG_DEFAULT, LVL_ERROR, "Error binding socket (%s)", 710 748 str_error(rc)); 711 749 return rc; … … 714 752 rc = listen(listen_sd, 2); 715 753 if (rc != EOK) { 716 fprintf(stderr, "listen() failed (%s)\n", str_error(rc));754 log_msg(LOG_DEFAULT, LVL_ERROR, "listen() failed (%s)", str_error(rc)); 717 755 return rc; 718 756 } … … 732 770 733 771 if (conn_sd < 0) { 734 fprintf(stderr, "accept() failed (%s)\n", str_error(conn_sd)); 772 log_msg(LOG_DEFAULT, LVL_WARN, "accept() failed (%s)", 773 str_error(conn_sd)); 735 774 continue; 736 775 } 776 777 log_msg(LOG_DEFAULT, LVL_DEBUG, "Connection accepted"); 737 778 738 779 rbuf_out = 0;
Note:
See TracChangeset
for help on using the changeset viewer.