OLD | NEW |
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 |
11 static const char* kPort = "5858"; | 11 static const char* kPort = "5858"; |
12 static const char* kLocalhost = "localhost"; | 12 static const char* kLocalhost = "localhost"; |
13 | 13 |
14 class SocketListenerThread : public Thread { | 14 class SocketListenerThread : public Thread { |
15 public: | 15 public: |
16 explicit SocketListenerThread(int data_size) | 16 explicit SocketListenerThread(int data_size) |
17 : data_size_(data_size), server_(NULL), client_(NULL), | 17 : data_size_(data_size), server_(NULL), client_(NULL), |
18 listening_(OS::CreateSemaphore(0)) { | 18 listening_(OS::CreateSemaphore(0)) { |
19 data_ = new char[data_size_]; | 19 data_ = new char[data_size_]; |
20 } | 20 } |
21 ~SocketListenerThread() { | 21 ~SocketListenerThread() { |
22 // Close both sockets. | 22 // Close both sockets. |
23 delete client_; | 23 delete client_; |
24 delete server_; | 24 delete server_; |
| 25 delete listening_; |
| 26 delete[] data_; |
25 } | 27 } |
26 | 28 |
27 void Run(); | 29 void Run(); |
28 void WaitForListening() { listening_->Wait(); } | 30 void WaitForListening() { listening_->Wait(); } |
29 char* data() { return data_; } | 31 char* data() { return data_; } |
30 | 32 |
31 private: | 33 private: |
32 char* data_; | 34 char* data_; |
33 int data_size_; | 35 int data_size_; |
34 Socket* server_; // Server socket used for bind/accept. | 36 Socket* server_; // Server socket used for bind/accept. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 char small_data[kBufferSizeSmall + 1] = "1234567890abcdefghij"; | 122 char small_data[kBufferSizeSmall + 1] = "1234567890abcdefghij"; |
121 SendAndReceive(small_data, kBufferSizeSmall); | 123 SendAndReceive(small_data, kBufferSizeSmall); |
122 | 124 |
123 // Send and receive some more data. | 125 // Send and receive some more data. |
124 static const int kBufferSizeMedium = 10000; | 126 static const int kBufferSizeMedium = 10000; |
125 char* medium_data = new char[kBufferSizeMedium]; | 127 char* medium_data = new char[kBufferSizeMedium]; |
126 for (int i = 0; i < kBufferSizeMedium; i++) { | 128 for (int i = 0; i < kBufferSizeMedium; i++) { |
127 medium_data[i] = i % 256; | 129 medium_data[i] = i % 256; |
128 } | 130 } |
129 SendAndReceive(medium_data, kBufferSizeMedium); | 131 SendAndReceive(medium_data, kBufferSizeMedium); |
| 132 delete[] medium_data; |
130 | 133 |
131 // Send and receive even more data. | 134 // Send and receive even more data. |
132 static const int kBufferSizeLarge = 1000000; | 135 static const int kBufferSizeLarge = 1000000; |
133 char* large_data = new char[kBufferSizeLarge]; | 136 char* large_data = new char[kBufferSizeLarge]; |
134 for (int i = 0; i < kBufferSizeLarge; i++) { | 137 for (int i = 0; i < kBufferSizeLarge; i++) { |
135 large_data[i] = i % 256; | 138 large_data[i] = i % 256; |
136 } | 139 } |
137 SendAndReceive(large_data, kBufferSizeLarge); | 140 SendAndReceive(large_data, kBufferSizeLarge); |
| 141 delete[] large_data; |
138 } | 142 } |
139 | 143 |
140 | 144 |
141 TEST(HToNNToH) { | 145 TEST(HToNNToH) { |
142 uint16_t x = 1234; | 146 uint16_t x = 1234; |
143 CHECK_EQ(x, Socket::NToH(Socket::HToN(x))); | 147 CHECK_EQ(x, Socket::NToH(Socket::HToN(x))); |
144 | 148 |
145 uint32_t y = 12345678; | 149 uint32_t y = 12345678; |
146 CHECK(y == Socket::NToH(Socket::HToN(y))); | 150 CHECK(y == Socket::NToH(Socket::HToN(y))); |
147 } | 151 } |
OLD | NEW |