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

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

Issue 23498015: [NaCl SDK] Support non blocking TCP/UDP (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge Created 7 years, 3 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
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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 int len2 = 167 int len2 =
168 recvfrom(sock2, inbuf, sizeof(inbuf), 0, (sockaddr *) &addr, &addrlen); 168 recvfrom(sock2, inbuf, sizeof(inbuf), 0, (sockaddr *) &addr, &addrlen);
169 EXPECT_EQ(sizeof(outbuf), len2); 169 EXPECT_EQ(sizeof(outbuf), len2);
170 EXPECT_EQ(sizeof(sockaddr_in), addrlen); 170 EXPECT_EQ(sizeof(sockaddr_in), addrlen);
171 EXPECT_EQ(PORT1, htons(addr.sin_port)); 171 EXPECT_EQ(PORT1, htons(addr.sin_port));
172 172
173 // Now they should be the same 173 // Now they should be the same
174 EXPECT_EQ(0, memcmp(outbuf, inbuf, sizeof(outbuf))); 174 EXPECT_EQ(0, memcmp(outbuf, inbuf, sizeof(outbuf)));
175 } 175 }
176 176
177 #if 0 177 const size_t queue_size = 65536 * 8;
178 TEST_F(SocketTestTCP, Connect) { 178 TEST_F(SocketTestUDP, FullFifo) {
179 char outbuf[16 * 1024];
180
181 EXPECT_EQ(Bind(sock1, LOCAL_HOST, PORT1), ENONE);
182 EXPECT_EQ(Bind(sock2, LOCAL_HOST, PORT2), ENONE);
183
184 sockaddr_in addr;
185 socklen_t addrlen = sizeof(addr);
186 IP4ToSockAddr(LOCAL_HOST, PORT2, &addr);
187
188 size_t total = 0;
189 while (total < queue_size * 8) {
190 int len = sendto(sock1, outbuf, sizeof(outbuf), MSG_DONTWAIT,
191 (sockaddr *) &addr, addrlen);
192
193 if (len <= 0) {
194 EXPECT_EQ(-1, len);
195 EXPECT_EQ(errno, EWOULDBLOCK);
196 break;
197 }
198
199 if (len >= 0) {
200 EXPECT_EQ(sizeof(outbuf), len);
201 total += len;
202 }
203
204 }
205 EXPECT_GT(total, queue_size -1);
206 EXPECT_LT(total, queue_size * 8);
207 }
208
209 // TODO(noelallen) BUG=294412
210 // Re-enable testing on bots when server sockets are available.
211 TEST_F(SocketTestTCP, DISABLED_Connect) {
212 char outbuf[256];
213 char inbuf[512];
214
215 memset(outbuf, 1, sizeof(outbuf));
216 memset(inbuf, 0, sizeof(inbuf));
217
179 int sock = socket(AF_INET, SOCK_STREAM, 0); 218 int sock = socket(AF_INET, SOCK_STREAM, 0);
180 EXPECT_NE(-1, sock); 219 EXPECT_NE(-1, sock);
181 220
182 sockaddr_in addr; 221 sockaddr_in addr;
183 socklen_t addrlen = sizeof(addr); 222 socklen_t addrlen = sizeof(addr);
184 223
185 IP4ToSockAddr(LOCAL_HOST, PORT1, &addr); 224 IP4ToSockAddr(LOCAL_HOST, PORT1, &addr);
186 int err = connect(sock, (sockaddr*) &addr, addrlen); 225 int err = connect(sock, (sockaddr*) &addr, addrlen);
226
187 EXPECT_EQ(ENONE, err) << "Failed with errno: " << errno << "\n"; 227 EXPECT_EQ(ENONE, err) << "Failed with errno: " << errno << "\n";
228
229 EXPECT_EQ(sizeof(outbuf), write(sock, outbuf, sizeof(outbuf)));
230 EXPECT_EQ(sizeof(outbuf), read(sock, inbuf, sizeof(inbuf)));
231
232 // Now they should be the same
233 EXPECT_EQ(0, memcmp(outbuf, inbuf, sizeof(outbuf)));
188 } 234 }
189 #endif
190 235
191 #endif // PROVIDES_SOCKETPAIR_API 236 #endif // PROVIDES_SOCKET_API
OLDNEW
« no previous file with comments | « native_client_sdk/src/tests/nacl_io_socket_test/event_test.cc ('k') | native_client_sdk/src/tests/nacl_io_test/event_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698