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

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

Issue 458563002: [NaCl SDK] Fix bug in TCPNode::Connect (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/socket/tcp_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 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 ASSERT_EQ(1, ki_poll(&pollfd, 1, -1)); 385 ASSERT_EQ(1, ki_poll(&pollfd, 1, -1));
386 ASSERT_EQ(POLLOUT, pollfd.revents); 386 ASSERT_EQ(POLLOUT, pollfd.revents);
387 387
388 // Attempts to connect again should yield EISCONN 388 // Attempts to connect again should yield EISCONN
389 ASSERT_EQ(-1, ki_connect(sock_, (sockaddr*) &addr, addrlen)); 389 ASSERT_EQ(-1, ki_connect(sock_, (sockaddr*) &addr, addrlen));
390 ASSERT_EQ(EISCONN, errno); 390 ASSERT_EQ(EISCONN, errno);
391 391
392 // And SO_ERROR should be 0. 392 // And SO_ERROR should be 0.
393 } 393 }
394 394
395 TEST_F(SocketTestTCP, TCPConnectFails) {
396 sockaddr_in addr;
397 socklen_t addrlen = sizeof(addr);
398
399 // 10 is an unassigned well-known port, nothing should be bound to it.
400 IP4ToSockAddr(LOCAL_HOST, 10, &addr);
401 ASSERT_EQ(-1, ki_connect(sock1_, (sockaddr*) &addr, addrlen));
402 ASSERT_EQ(ECONNREFUSED, errno);
403 }
404
395 TEST_F(SocketTest, Getsockopt) { 405 TEST_F(SocketTest, Getsockopt) {
396 sock1_ = ki_socket(AF_INET, SOCK_STREAM, 0); 406 sock1_ = ki_socket(AF_INET, SOCK_STREAM, 0);
397 EXPECT_GT(sock1_, -1); 407 EXPECT_GT(sock1_, -1);
398 int socket_error = 99; 408 int socket_error = 99;
399 socklen_t len = sizeof(socket_error); 409 socklen_t len = sizeof(socket_error);
400 410
401 // Test for valid option (SO_ERROR) which should be 0 when a socket 411 // Test for valid option (SO_ERROR) which should be 0 when a socket
402 // is first created. 412 // is first created.
403 ASSERT_EQ(0, ki_getsockopt(sock1_, SOL_SOCKET, SO_ERROR, 413 ASSERT_EQ(0, ki_getsockopt(sock1_, SOL_SOCKET, SO_ERROR,
404 &socket_error, &len)); 414 &socket_error, &len));
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 while (remainder > 0) { 840 while (remainder > 0) {
831 int rtn = ki_recv(new_sock, buffer, remainder, 0); 841 int rtn = ki_recv(new_sock, buffer, remainder, 0);
832 ASSERT_GT(rtn, 0); 842 ASSERT_GT(rtn, 0);
833 remainder -= rtn; 843 remainder -= rtn;
834 } 844 }
835 845
836 ASSERT_EQ(0, ki_close(new_sock)); 846 ASSERT_EQ(0, ki_close(new_sock));
837 } 847 }
838 848
839 #endif // PROVIDES_SOCKET_API 849 #endif // PROVIDES_SOCKET_API
OLDNEW
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/socket/tcp_node.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698