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

Side by Side Diff: test/cctest/test-sockets.cc

Issue 40104: Removed function SendAll from Socket (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 9 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 | « src/platform-win32.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 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 the V8 project authors. All rights reserved.
2 2
3 #include "v8.h" 3 #include "v8.h"
4 #include "platform.h" 4 #include "platform.h"
5 #include "cctest.h" 5 #include "cctest.h"
6 6
7 7
8 using namespace ::v8::internal; 8 using namespace ::v8::internal;
9 9
10 10
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 CHECK(client_ != NULL); 56 CHECK(client_ != NULL);
57 57
58 // Read the expected niumber of bytes of data. 58 // Read the expected niumber of bytes of data.
59 int bytes_read = 0; 59 int bytes_read = 0;
60 while (bytes_read < data_size_) { 60 while (bytes_read < data_size_) {
61 bytes_read += client_->Receive(data_ + bytes_read, data_size_ - bytes_read); 61 bytes_read += client_->Receive(data_ + bytes_read, data_size_ - bytes_read);
62 } 62 }
63 } 63 }
64 64
65 65
66 static bool SendAll(Socket* socket, const char* data, int len) {
67 int sent_len = 0;
68 while (sent_len < len) {
69 int status = socket->Send(data, len);
70 if (status <= 0) {
71 return false;
72 }
73 sent_len += status;
74 }
75 return true;
76 }
77
78
66 static void SendAndReceive(char *data, int len) { 79 static void SendAndReceive(char *data, int len) {
67 bool ok; 80 bool ok;
68 81
69 // Create a socket listener. 82 // Create a socket listener.
70 SocketListenerThread* listener = new SocketListenerThread(len); 83 SocketListenerThread* listener = new SocketListenerThread(len);
71 listener->Start(); 84 listener->Start();
72 listener->WaitForListening(); 85 listener->WaitForListening();
73 86
74 // Connect and write some data. 87 // Connect and write some data.
75 Socket* client = OS::CreateSocket(); 88 Socket* client = OS::CreateSocket();
76 CHECK(client != NULL); 89 CHECK(client != NULL);
77 ok = client->Connect(kLocalhost, kPort); 90 ok = client->Connect(kLocalhost, kPort);
78 CHECK(ok); 91 CHECK(ok);
79 92
80 // Send all the data. 93 // Send all the data.
81 ok = client->SendAll(data, len); 94 ok = SendAll(client, data, len);
82 CHECK(ok); 95 CHECK(ok);
83 96
84 // Wait until data is received. 97 // Wait until data is received.
85 listener->Join(); 98 listener->Join();
86 99
87 // Check that data received is the same as data send. 100 // Check that data received is the same as data send.
88 for (int i = 0; i < len; i++) { 101 for (int i = 0; i < len; i++) {
89 CHECK(data[i] == listener->data()[i]); 102 CHECK(data[i] == listener->data()[i]);
90 } 103 }
91 104
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 } 138 }
126 139
127 140
128 TEST(HToNNToH) { 141 TEST(HToNNToH) {
129 uint16_t x = 1234; 142 uint16_t x = 1234;
130 CHECK_EQ(x, Socket::NToH(Socket::HToN(x))); 143 CHECK_EQ(x, Socket::NToH(Socket::HToN(x)));
131 144
132 uint32_t y = 12345678; 145 uint32_t y = 12345678;
133 CHECK(y == Socket::NToH(Socket::HToN(y))); 146 CHECK(y == Socket::NToH(Socket::HToN(y)));
134 } 147 }
OLDNEW
« no previous file with comments | « src/platform-win32.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698