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 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
504 ASSERT_GT(sock1_, -1); | 504 ASSERT_GT(sock1_, -1); |
505 ASSERT_EQ(0, ki_setsockopt(sock1_, SOL_SOCKET, SO_REUSEADDR, &value, len)); | 505 ASSERT_EQ(0, ki_setsockopt(sock1_, SOL_SOCKET, SO_REUSEADDR, &value, len)); |
506 | 506 |
507 value = 0; | 507 value = 0; |
508 len = sizeof(value); | 508 len = sizeof(value); |
509 ASSERT_EQ(0, ki_getsockopt(sock1_, SOL_SOCKET, SO_REUSEADDR, &value, &len)); | 509 ASSERT_EQ(0, ki_getsockopt(sock1_, SOL_SOCKET, SO_REUSEADDR, &value, &len)); |
510 ASSERT_EQ(1, value); | 510 ASSERT_EQ(1, value); |
511 ASSERT_EQ(sizeof(int), len); | 511 ASSERT_EQ(sizeof(int), len); |
512 } | 512 } |
513 | 513 |
514 TEST_F(SocketTest, Sockopt_BUFSIZE) { | |
515 int option = 1024*1024; | |
516 socklen_t len = sizeof(option); | |
517 | |
518 sock1_ = ki_socket(AF_INET, SOCK_DGRAM, 0); | |
519 ASSERT_GT(sock1_, -1); | |
520 ASSERT_EQ(0, Bind(sock1_, LOCAL_HOST, PORT1)); | |
521 ASSERT_EQ(0, ki_setsockopt(sock1_, SOL_SOCKET, SO_RCVBUF, &option, len)) | |
522 << "failed with: " << strerror(errno); | |
523 ASSERT_EQ(0, ki_setsockopt(sock1_, SOL_SOCKET, SO_SNDBUF, &option, len)) | |
524 << "failed with: " << strerror(errno); | |
525 | |
526 sock2_ = socket(AF_INET, SOCK_STREAM, 0); | |
CodeByThePound
2014/06/02 19:38:18
I think you meant to call ki_socket here, instead
| |
527 ASSERT_GT(sock2_, -1); | |
528 ASSERT_EQ(0, Bind(sock2_, LOCAL_HOST, PORT2)); | |
529 | |
530 ASSERT_EQ(0, ki_setsockopt(sock2_, SOL_SOCKET, SO_RCVBUF, &option, len)) | |
531 << "failed with: " << strerror(errno); | |
532 ASSERT_EQ(0, ki_setsockopt(sock2_, SOL_SOCKET, SO_SNDBUF, &option, len)) | |
533 << "failed with: " << strerror(errno); | |
534 } | |
535 | |
514 // The size of the data to send is deliberately chosen to be | 536 // The size of the data to send is deliberately chosen to be |
515 // larger than the TCP buffer in nacl_io. | 537 // larger than the TCP buffer in nacl_io. |
516 // TODO(sbc): use ioctl to discover the actual buffer size at | 538 // TODO(sbc): use ioctl to discover the actual buffer size at |
517 // runtime. | 539 // runtime. |
518 #define LARGE_SEND_BYTES (800 * 1024) | 540 #define LARGE_SEND_BYTES (800 * 1024) |
519 TEST_F(SocketTestWithServer, LargeSend) { | 541 TEST_F(SocketTestWithServer, LargeSend) { |
520 char* outbuf = (char*)malloc(LARGE_SEND_BYTES); | 542 char* outbuf = (char*)malloc(LARGE_SEND_BYTES); |
521 char* inbuf = (char*)malloc(LARGE_SEND_BYTES); | 543 char* inbuf = (char*)malloc(LARGE_SEND_BYTES); |
522 int bytes_sent = 0; | 544 int bytes_sent = 0; |
523 int bytes_received = 0; | 545 int bytes_received = 0; |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
806 while (remainder > 0) { | 828 while (remainder > 0) { |
807 int rtn = ki_recv(new_sock, buffer, remainder, 0); | 829 int rtn = ki_recv(new_sock, buffer, remainder, 0); |
808 ASSERT_GT(rtn, 0); | 830 ASSERT_GT(rtn, 0); |
809 remainder -= rtn; | 831 remainder -= rtn; |
810 } | 832 } |
811 | 833 |
812 ASSERT_EQ(0, ki_close(new_sock)); | 834 ASSERT_EQ(0, ki_close(new_sock)); |
813 } | 835 } |
814 | 836 |
815 #endif // PROVIDES_SOCKET_API | 837 #endif // PROVIDES_SOCKET_API |
OLD | NEW |