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 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 ASSERT_EQ(reply_len, ki_send(new_socket, server_reply, reply_len, 0)); | 672 ASSERT_EQ(reply_len, ki_send(new_socket, server_reply, reply_len, 0)); |
673 | 673 |
674 // Recv reply on client socket | 674 // Recv reply on client socket |
675 ASSERT_EQ(reply_len, ki_recv(client_sock, inbuf, sizeof(inbuf), 0)); | 675 ASSERT_EQ(reply_len, ki_recv(client_sock, inbuf, sizeof(inbuf), 0)); |
676 inbuf[reply_len] = 0; | 676 inbuf[reply_len] = 0; |
677 ASSERT_STREQ(inbuf, server_reply); | 677 ASSERT_STREQ(inbuf, server_reply); |
678 | 678 |
679 ASSERT_EQ(0, ki_close(new_socket)); | 679 ASSERT_EQ(0, ki_close(new_socket)); |
680 } | 680 } |
681 | 681 |
| 682 TEST_F(SocketTestTCP, BindAndGetSockName) { |
| 683 sockaddr_in addr; |
| 684 socklen_t addrlen = sizeof(addr); |
| 685 |
| 686 // Bind |
| 687 ASSERT_EQ(0, Bind(sock1_, LOCAL_HOST, 0)); |
| 688 EXPECT_EQ(0, ki_getsockname(sock1_, (struct sockaddr*)&addr, &addrlen)); |
| 689 EXPECT_NE(0, addr.sin_port); |
| 690 } |
| 691 |
682 TEST_F(SocketTestTCP, ListenNonBlocking) { | 692 TEST_F(SocketTestTCP, ListenNonBlocking) { |
683 int server_sock = sock1_; | 693 int server_sock = sock1_; |
684 | 694 |
685 // Set non-blocking | 695 // Set non-blocking |
686 SetNonBlocking(server_sock); | 696 SetNonBlocking(server_sock); |
687 | 697 |
688 // bind and listen | 698 // bind and listen |
689 ASSERT_EQ(0, Bind(server_sock, LOCAL_HOST, PORT1)); | 699 ASSERT_EQ(0, Bind(server_sock, LOCAL_HOST, PORT1)); |
690 ASSERT_EQ(0, ki_listen(server_sock, 10)) | 700 ASSERT_EQ(0, ki_listen(server_sock, 10)) |
691 << "listen failed with: " << strerror(errno); | 701 << "listen failed with: " << strerror(errno); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
840 while (remainder > 0) { | 850 while (remainder > 0) { |
841 int rtn = ki_recv(new_sock, buffer, remainder, 0); | 851 int rtn = ki_recv(new_sock, buffer, remainder, 0); |
842 ASSERT_GT(rtn, 0); | 852 ASSERT_GT(rtn, 0); |
843 remainder -= rtn; | 853 remainder -= rtn; |
844 } | 854 } |
845 | 855 |
846 ASSERT_EQ(0, ki_close(new_sock)); | 856 ASSERT_EQ(0, ki_close(new_sock)); |
847 } | 857 } |
848 | 858 |
849 #endif // PROVIDES_SOCKET_API | 859 #endif // PROVIDES_SOCKET_API |
OLD | NEW |