| 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 class SocketListenerThread : public Thread { | 11 class SocketListenerThread : public Thread { |
| 12 public: | 12 public: |
| 13 explicit SocketListenerThread(Isolate* isolate, int port, int data_size) | 13 SocketListenerThread(int port, int data_size) |
| 14 : Thread(isolate, "SocketListenerThread"), | 14 : Thread("SocketListenerThread"), |
| 15 port_(port), | 15 port_(port), |
| 16 data_size_(data_size), | 16 data_size_(data_size), |
| 17 server_(NULL), | 17 server_(NULL), |
| 18 client_(NULL), | 18 client_(NULL), |
| 19 listening_(OS::CreateSemaphore(0)) { | 19 listening_(OS::CreateSemaphore(0)) { |
| 20 data_ = new char[data_size_]; | 20 data_ = new char[data_size_]; |
| 21 } | 21 } |
| 22 ~SocketListenerThread() { | 22 ~SocketListenerThread() { |
| 23 // Close both sockets. | 23 // Close both sockets. |
| 24 delete client_; | 24 delete client_; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 static const char* kLocalhost = "localhost"; | 85 static const char* kLocalhost = "localhost"; |
| 86 | 86 |
| 87 bool ok; | 87 bool ok; |
| 88 | 88 |
| 89 // Make a string with the port number. | 89 // Make a string with the port number. |
| 90 const int kPortBuferLen = 6; | 90 const int kPortBuferLen = 6; |
| 91 char port_str[kPortBuferLen]; | 91 char port_str[kPortBuferLen]; |
| 92 OS::SNPrintF(Vector<char>(port_str, kPortBuferLen), "%d", port); | 92 OS::SNPrintF(Vector<char>(port_str, kPortBuferLen), "%d", port); |
| 93 | 93 |
| 94 // Create a socket listener. | 94 // Create a socket listener. |
| 95 SocketListenerThread* listener = new SocketListenerThread(Isolate::Current(), | 95 SocketListenerThread* listener = new SocketListenerThread(port, len); |
| 96 port, len); | |
| 97 listener->Start(); | 96 listener->Start(); |
| 98 listener->WaitForListening(); | 97 listener->WaitForListening(); |
| 99 | 98 |
| 100 // Connect and write some data. | 99 // Connect and write some data. |
| 101 Socket* client = OS::CreateSocket(); | 100 Socket* client = OS::CreateSocket(); |
| 102 CHECK(client != NULL); | 101 CHECK(client != NULL); |
| 103 ok = client->Connect(kLocalhost, port_str); | 102 ok = client->Connect(kLocalhost, port_str); |
| 104 CHECK(ok); | 103 CHECK(ok); |
| 105 | 104 |
| 106 // Send all the data. | 105 // Send all the data. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 } | 157 } |
| 159 | 158 |
| 160 | 159 |
| 161 TEST(HToNNToH) { | 160 TEST(HToNNToH) { |
| 162 uint16_t x = 1234; | 161 uint16_t x = 1234; |
| 163 CHECK_EQ(x, Socket::NToH(Socket::HToN(x))); | 162 CHECK_EQ(x, Socket::NToH(Socket::HToN(x))); |
| 164 | 163 |
| 165 uint32_t y = 12345678; | 164 uint32_t y = 12345678; |
| 166 CHECK(y == Socket::NToH(Socket::HToN(y))); | 165 CHECK(y == Socket::NToH(Socket::HToN(y))); |
| 167 } | 166 } |
| OLD | NEW |