| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <arpa/inet.h> | 5 #include <arpa/inet.h> |
| 6 #include <errno.h> | 6 #include <errno.h> |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <netinet/in.h> | 8 #include <netinet/in.h> |
| 9 #include <pthread.h> | 9 #include <pthread.h> |
| 10 #include <sys/types.h> | 10 #include <sys/types.h> |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 | 577 |
| 578 free(inbuf); | 578 free(inbuf); |
| 579 free(outbuf); | 579 free(outbuf); |
| 580 } | 580 } |
| 581 | 581 |
| 582 TEST_F(SocketTestUDP, Listen) { | 582 TEST_F(SocketTestUDP, Listen) { |
| 583 EXPECT_EQ(-1, ki_listen(sock1_, 10)); | 583 EXPECT_EQ(-1, ki_listen(sock1_, 10)); |
| 584 EXPECT_EQ(errno, ENOTSUP); | 584 EXPECT_EQ(errno, ENOTSUP); |
| 585 } | 585 } |
| 586 | 586 |
| 587 TEST_F(SocketTestUDP, Sockopt_BUFSIZE) { |
| 588 int option = 1024*1024; |
| 589 socklen_t len = sizeof(option); |
| 590 |
| 591 ASSERT_EQ(0, Bind(sock1_, LOCAL_HOST, ANY_PORT)); |
| 592 |
| 593 // Modify the test to verify the change by calling getsockopt |
| 594 // once UDPInterface supports GetOption() call |
| 595 ASSERT_EQ(0, ki_setsockopt(sock1_, SOL_SOCKET, SO_RCVBUF, &option, len)) |
| 596 << "failed with: " << strerror(errno); |
| 597 ASSERT_EQ(0, ki_setsockopt(sock1_, SOL_SOCKET, SO_SNDBUF, &option, len)) |
| 598 << "failed with: " << strerror(errno); |
| 599 } |
| 600 |
| 587 TEST_F(SocketTestTCP, Listen) { | 601 TEST_F(SocketTestTCP, Listen) { |
| 588 sockaddr_in addr; | 602 sockaddr_in addr; |
| 589 socklen_t addrlen = sizeof(addr); | 603 socklen_t addrlen = sizeof(addr); |
| 590 const char* client_greeting = "hello"; | 604 const char* client_greeting = "hello"; |
| 591 const char* server_reply = "reply"; | 605 const char* server_reply = "reply"; |
| 592 const int greeting_len = strlen(client_greeting); | 606 const int greeting_len = strlen(client_greeting); |
| 593 const int reply_len = strlen(server_reply); | 607 const int reply_len = strlen(server_reply); |
| 594 | 608 |
| 595 int server_sock = sock1_; | 609 int server_sock = sock1_; |
| 596 | 610 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 int remainder = SEND_BYTES; | 819 int remainder = SEND_BYTES; |
| 806 while (remainder > 0) { | 820 while (remainder > 0) { |
| 807 int rtn = ki_recv(new_sock, buffer, remainder, 0); | 821 int rtn = ki_recv(new_sock, buffer, remainder, 0); |
| 808 ASSERT_GT(rtn, 0); | 822 ASSERT_GT(rtn, 0); |
| 809 remainder -= rtn; | 823 remainder -= rtn; |
| 810 } | 824 } |
| 811 | 825 |
| 812 ASSERT_EQ(0, ki_close(new_sock)); | 826 ASSERT_EQ(0, ki_close(new_sock)); |
| 813 } | 827 } |
| 814 | 828 |
| 829 TEST_F(SocketTestTCP, Sockopt_BUFSIZE) { |
| 830 int option = 1024*1024; |
| 831 socklen_t len = sizeof(option); |
| 832 sockaddr_in addr; |
| 833 socklen_t addrlen = sizeof(addr); |
| 834 |
| 835 int server_sock = sock1_; |
| 836 int client_sock = sock2_; |
| 837 |
| 838 // bind and listen |
| 839 ASSERT_EQ(0, Bind(server_sock, LOCAL_HOST, PORT1)); |
| 840 ASSERT_EQ(0, ki_listen(server_sock, 10)) |
| 841 << "listen failed with: " << strerror(errno); |
| 842 |
| 843 // connect to listening socket |
| 844 IP4ToSockAddr(LOCAL_HOST, PORT1, &addr); |
| 845 ASSERT_EQ(0, ki_connect(client_sock, (sockaddr*)&addr, addrlen)) |
| 846 << "Failed with " << errno << ": " << strerror(errno); |
| 847 |
| 848 addrlen = sizeof(addr); |
| 849 int new_sock = ki_accept(server_sock, (sockaddr*)&addr, &addrlen); |
| 850 ASSERT_NE(-1, new_sock); |
| 851 |
| 852 // Modify the test to verify the change by calling getsockopt |
| 853 // once TCPInterface supports GetOption() call |
| 854 ASSERT_EQ(0, ki_setsockopt(sock2_, SOL_SOCKET, SO_RCVBUF, &option, len)) |
| 855 << "failed with: " << strerror(errno); |
| 856 ASSERT_EQ(0, ki_setsockopt(sock2_, SOL_SOCKET, SO_SNDBUF, &option, len)) |
| 857 << "failed with: " << strerror(errno); |
| 858 } |
| 859 |
| 815 #endif // PROVIDES_SOCKET_API | 860 #endif // PROVIDES_SOCKET_API |
| OLD | NEW |