Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(756)

Side by Side Diff: native_client_sdk/src/tests/nacl_io_socket_test/socket_test.cc

Issue 304373008: Add support for modifying TCP and UDP socket buffer size in nacl_io (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Corrected the unit tests Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/socket/udp_node.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 ASSERT_EQ(0, ki_setsockopt(sock1_, SOL_SOCKET, SO_RCVBUF, &option, len))
593 << "failed with: " << strerror(errno);
594 ASSERT_EQ(0, ki_setsockopt(sock1_, SOL_SOCKET, SO_SNDBUF, &option, len))
595 << "failed with: " << strerror(errno);
Sam Clegg 2014/06/03 00:07:54 Can you verify the result with getsockopt()?
mbajpai 2014/06/03 05:11:07 It is not clear to me how to do it. Unlike SetOpti
596 }
597
587 TEST_F(SocketTestTCP, Listen) { 598 TEST_F(SocketTestTCP, Listen) {
588 sockaddr_in addr; 599 sockaddr_in addr;
589 socklen_t addrlen = sizeof(addr); 600 socklen_t addrlen = sizeof(addr);
590 const char* client_greeting = "hello"; 601 const char* client_greeting = "hello";
591 const char* server_reply = "reply"; 602 const char* server_reply = "reply";
592 const int greeting_len = strlen(client_greeting); 603 const int greeting_len = strlen(client_greeting);
593 const int reply_len = strlen(server_reply); 604 const int reply_len = strlen(server_reply);
594 605
595 int server_sock = sock1_; 606 int server_sock = sock1_;
596 607
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 int remainder = SEND_BYTES; 816 int remainder = SEND_BYTES;
806 while (remainder > 0) { 817 while (remainder > 0) {
807 int rtn = ki_recv(new_sock, buffer, remainder, 0); 818 int rtn = ki_recv(new_sock, buffer, remainder, 0);
808 ASSERT_GT(rtn, 0); 819 ASSERT_GT(rtn, 0);
809 remainder -= rtn; 820 remainder -= rtn;
810 } 821 }
811 822
812 ASSERT_EQ(0, ki_close(new_sock)); 823 ASSERT_EQ(0, ki_close(new_sock));
813 } 824 }
814 825
826 TEST_F(SocketTestTCP, Sockopt_BUFSIZE) {
827 int option = 1024*1024;
828 socklen_t len = sizeof(option);
829 sockaddr_in addr;
830 socklen_t addrlen = sizeof(addr);
831
832 int server_sock = sock1_;
833 int client_sock = sock2_;
834
835 // bind and listen
836 ASSERT_EQ(0, Bind(server_sock, LOCAL_HOST, ANY_PORT));
837 ASSERT_EQ(0, ki_listen(server_sock, 10))
838 << "listen failed with: " << strerror(errno);
839
840 // connect to listening socket
841 IP4ToSockAddr(LOCAL_HOST, PORT1, &addr);
842 ASSERT_EQ(0, ki_connect(client_sock, (sockaddr*)&addr, addrlen))
843 << "Failed with " << errno << ": " << strerror(errno);
844
845 addrlen = sizeof(addr);
846 int new_sock = accept(server_sock, (sockaddr*)&addr, &addrlen);
847 ASSERT_NE(-1, new_sock);
848
849 ASSERT_EQ(0, ki_setsockopt(sock2_, SOL_SOCKET, SO_RCVBUF, &option, len))
850 << "failed with: " << strerror(errno);
851 ASSERT_EQ(0, ki_setsockopt(sock2_, SOL_SOCKET, SO_SNDBUF, &option, len))
852 << "failed with: " << strerror(errno);
Sam Clegg 2014/06/03 00:07:54 ditto.
853 }
854
815 #endif // PROVIDES_SOCKET_API 855 #endif // PROVIDES_SOCKET_API
OLDNEW
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/socket/udp_node.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698