OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/udp/udp_client_socket.h" | 5 #include "net/udp/udp_client_socket.h" |
6 #include "net/udp/udp_server_socket.h" | 6 #include "net/udp/udp_server_socket.h" |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
519 TestCompletionCallback callback; | 519 TestCompletionCallback callback; |
520 IPEndPoint from; | 520 IPEndPoint from; |
521 rv = server.RecvFrom(buffer_, kMaxRead, &from, callback.callback()); | 521 rv = server.RecvFrom(buffer_, kMaxRead, &from, callback.callback()); |
522 EXPECT_EQ(rv, ERR_IO_PENDING); | 522 EXPECT_EQ(rv, ERR_IO_PENDING); |
523 | 523 |
524 server.Close(); | 524 server.Close(); |
525 | 525 |
526 EXPECT_FALSE(callback.have_result()); | 526 EXPECT_FALSE(callback.have_result()); |
527 } | 527 } |
528 | 528 |
529 #if defined(OS_ANDROID) | |
530 // Some Android devices does not support multicast socket. | |
wtc
2013/04/22 19:19:53
Typo: does not => do not
socket => sockets
Bei Zhang
2013/04/23 17:26:53
Done.
| |
531 // Ones supporting multicast need WifiManager.MulitcastLock to enable it. | |
wtc
2013/04/22 19:19:53
Typo: Ones => The ones
Bei Zhang
2013/04/23 17:26:53
Done.
| |
532 // http://goo.gl/jjAk9 | |
533 TEST_F(UDPSocketTest, DISABLED_JoinMulticastGroup) { | |
534 #else | |
535 TEST_F(UDPSocketTest, JoinMulticastGroup) { | |
536 #endif // defined(OS_ANDROID) | |
wtc
2013/04/22 19:19:53
This is usually done as follows:
#if defined(OS_A
Bei Zhang
2013/04/23 17:26:53
Done.
| |
537 const int kPort = 9999; | |
538 const char* const kGroup = "237.132.100.17"; | |
539 | |
540 IPEndPoint bind_address; | |
541 CreateUDPAddress("0.0.0.0", kPort, &bind_address); | |
542 IPAddressNumber group_ip; | |
543 EXPECT_TRUE(ParseIPLiteralToNumber(kGroup, &group_ip)); | |
544 | |
545 UDPSocket socket(DatagramSocket::DEFAULT_BIND, | |
546 RandIntCallback(), | |
547 NULL, | |
548 NetLog::Source()); | |
549 EXPECT_EQ(OK, socket.Bind(bind_address)); | |
550 EXPECT_EQ(OK, socket.JoinGroup(group_ip)); | |
551 // Joining group multiple times. | |
552 EXPECT_NE(OK, socket.JoinGroup(group_ip)); | |
wtc
2013/04/22 19:19:53
Why can't we check for a specific error code here
Bei Zhang
2013/04/23 17:26:53
The setsockopt function creates different errno on
wtc
2013/04/23 18:01:07
It is not necessary to get a consistent error code
| |
553 EXPECT_EQ(OK, socket.LeaveGroup(group_ip)); | |
554 // Leaving group multiple times. | |
555 EXPECT_NE(OK, socket.LeaveGroup(group_ip)); | |
556 | |
557 socket.Close(); | |
558 } | |
559 | |
560 TEST_F(UDPSocketTest, MulticastOptions) { | |
561 const int kPort = 9999; | |
562 IPEndPoint bind_address; | |
563 CreateUDPAddress("0.0.0.0", kPort, &bind_address); | |
564 | |
565 UDPSocket socket(DatagramSocket::DEFAULT_BIND, | |
566 RandIntCallback(), | |
567 NULL, | |
568 NetLog::Source()); | |
569 // Before binding. | |
570 EXPECT_EQ(OK, socket.SetMulticastLoopbackMode(false)); | |
571 EXPECT_EQ(OK, socket.SetMulticastLoopbackMode(true)); | |
572 EXPECT_EQ(OK, socket.SetMulticastTimeToLive(0)); | |
573 EXPECT_EQ(OK, socket.SetMulticastTimeToLive(3)); | |
574 EXPECT_NE(OK, socket.SetMulticastTimeToLive(-1)); | |
575 | |
576 EXPECT_EQ(OK, socket.Bind(bind_address)); | |
577 | |
578 socket.Close(); | |
579 } | |
580 | |
529 } // namespace | 581 } // namespace |
530 | 582 |
531 } // namespace net | 583 } // namespace net |
OLD | NEW |