Chromium Code Reviews| 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 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 601 ASSERT_EQ(0, Bind(sock1_, LOCAL_HOST, ANY_PORT)); | 601 ASSERT_EQ(0, Bind(sock1_, LOCAL_HOST, ANY_PORT)); |
| 602 | 602 |
| 603 // Modify the test to verify the change by calling getsockopt | 603 // Modify the test to verify the change by calling getsockopt |
| 604 // once UDPInterface supports GetOption() call | 604 // once UDPInterface supports GetOption() call |
| 605 ASSERT_EQ(0, ki_setsockopt(sock1_, SOL_SOCKET, SO_RCVBUF, &option, len)) | 605 ASSERT_EQ(0, ki_setsockopt(sock1_, SOL_SOCKET, SO_RCVBUF, &option, len)) |
| 606 << "failed with: " << strerror(errno); | 606 << "failed with: " << strerror(errno); |
| 607 ASSERT_EQ(0, ki_setsockopt(sock1_, SOL_SOCKET, SO_SNDBUF, &option, len)) | 607 ASSERT_EQ(0, ki_setsockopt(sock1_, SOL_SOCKET, SO_SNDBUF, &option, len)) |
| 608 << "failed with: " << strerror(errno); | 608 << "failed with: " << strerror(errno); |
| 609 } | 609 } |
| 610 | 610 |
| 611 TEST_F(SocketTestTCP, AcceptNoParams) { | |
| 612 sockaddr_in addr; | |
| 613 socklen_t addrlen = sizeof(addr); | |
| 614 int server_sock = sock1_; | |
| 615 | |
| 616 // Bind and Listen | |
| 617 ASSERT_EQ(0, Bind(server_sock, LOCAL_HOST, PORT1)); | |
| 618 ASSERT_EQ(0, ki_listen(server_sock, 10)); | |
|
Sam Clegg
2014/12/24 13:09:35
Remove extra space.
daiweili
2014/12/24 17:27:08
Done.
| |
| 619 | |
| 620 // Connect to listening socket, and send greeting | |
|
Sam Clegg
2014/12/24 13:09:35
Comment is inaccurate.
daiweili
2014/12/24 17:27:08
Done.
| |
| 621 int client_sock = sock2_; | |
| 622 IP4ToSockAddr(LOCAL_HOST, PORT1, &addr); | |
| 623 addrlen = sizeof(addr); | |
| 624 ASSERT_EQ(0, ki_connect(client_sock, (sockaddr*)&addr, addrlen)) | |
| 625 << "Failed with " << errno << ": " << strerror(errno); | |
| 626 | |
| 627 // Accept without addr and len should succeed | |
| 628 int new_socket = ki_accept(server_sock, NULL, NULL); | |
| 629 ASSERT_GT(new_socket, -1); | |
| 630 | |
| 631 ASSERT_EQ(0, ki_close(new_socket)); | |
| 632 } | |
| 633 | |
| 611 TEST_F(SocketTestTCP, Listen) { | 634 TEST_F(SocketTestTCP, Listen) { |
| 612 sockaddr_in addr; | 635 sockaddr_in addr; |
| 613 socklen_t addrlen = sizeof(addr); | 636 socklen_t addrlen = sizeof(addr); |
| 614 const char* client_greeting = "hello"; | 637 const char* client_greeting = "hello"; |
| 615 const char* server_reply = "reply"; | 638 const char* server_reply = "reply"; |
| 616 const int greeting_len = strlen(client_greeting); | 639 const int greeting_len = strlen(client_greeting); |
| 617 const int reply_len = strlen(server_reply); | 640 const int reply_len = strlen(server_reply); |
| 618 | 641 |
| 619 int server_sock = sock1_; | 642 int server_sock = sock1_; |
| 620 | 643 |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 896 | 919 |
| 897 // Modify the test to verify the change by calling getsockopt | 920 // Modify the test to verify the change by calling getsockopt |
| 898 // once TCPInterface supports GetOption() call | 921 // once TCPInterface supports GetOption() call |
| 899 ASSERT_EQ(0, ki_setsockopt(sock2_, SOL_SOCKET, SO_RCVBUF, &option, len)) | 922 ASSERT_EQ(0, ki_setsockopt(sock2_, SOL_SOCKET, SO_RCVBUF, &option, len)) |
| 900 << "failed with: " << strerror(errno); | 923 << "failed with: " << strerror(errno); |
| 901 ASSERT_EQ(0, ki_setsockopt(sock2_, SOL_SOCKET, SO_SNDBUF, &option, len)) | 924 ASSERT_EQ(0, ki_setsockopt(sock2_, SOL_SOCKET, SO_SNDBUF, &option, len)) |
| 902 << "failed with: " << strerror(errno); | 925 << "failed with: " << strerror(errno); |
| 903 } | 926 } |
| 904 | 927 |
| 905 #endif // PROVIDES_SOCKET_API | 928 #endif // PROVIDES_SOCKET_API |
| OLD | NEW |