|
@@ -25,57 +25,59 @@
|
|
|
#include "platform/platformNet.h"
|
|
|
#include "core/util/journal/process.h"
|
|
|
|
|
|
-TEST(Net, TCPRequest)
|
|
|
+struct TcpHandle
|
|
|
{
|
|
|
- struct handle
|
|
|
+ NetSocket mSocket;
|
|
|
+ S32 mDataReceived;
|
|
|
+
|
|
|
+ void notify(NetSocket sock, U32 state)
|
|
|
{
|
|
|
- NetSocket mSocket;
|
|
|
- S32 mDataReceived;
|
|
|
+ // Only consider our own socket.
|
|
|
+ if(mSocket != sock)
|
|
|
+ return;
|
|
|
|
|
|
- void notify(NetSocket sock, U32 state)
|
|
|
+ // Ok - what's the state? We do some dumb responses to given states
|
|
|
+ // in order to fulfill the request.
|
|
|
+ if(state == Net::Connected)
|
|
|
{
|
|
|
- // Only consider our own socket.
|
|
|
- if(mSocket != sock)
|
|
|
- return;
|
|
|
-
|
|
|
- // Ok - what's the state? We do some dumb responses to given states
|
|
|
- // in order to fulfill the request.
|
|
|
- if(state == Net::Connected)
|
|
|
- {
|
|
|
- U8 reqBuffer[] = {
|
|
|
- "GET / HTTP/1.0\nUser-Agent: Torque/1.0\n\n"
|
|
|
- };
|
|
|
-
|
|
|
- Net::Error e = Net::sendtoSocket(mSocket, reqBuffer, sizeof(reqBuffer));
|
|
|
-
|
|
|
- ASSERT_EQ(Net::NoError, e)
|
|
|
- << "Got an error sending our HTTP request!";
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- Process::requestShutdown();
|
|
|
- mSocket = NULL;
|
|
|
- ASSERT_EQ(Net::Disconnected, state)
|
|
|
- << "Ended with a network error!";
|
|
|
- }
|
|
|
- }
|
|
|
+ U8 reqBuffer[] = {
|
|
|
+ "GET / HTTP/1.0\nUser-Agent: Torque/1.0\n\n"
|
|
|
+ };
|
|
|
|
|
|
- void receive(NetSocket sock, RawData incomingData)
|
|
|
- {
|
|
|
- // Only consider our own socket.
|
|
|
- if(mSocket != sock)
|
|
|
- return;
|
|
|
+ Net::Error e = Net::sendtoSocket(mSocket, reqBuffer, sizeof(reqBuffer));
|
|
|
|
|
|
- mDataReceived += incomingData.size;
|
|
|
+ ASSERT_EQ(Net::NoError, e)
|
|
|
+ << "Got an error sending our HTTP request!";
|
|
|
}
|
|
|
- } handler;
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Process::requestShutdown();
|
|
|
+ mSocket = NULL;
|
|
|
+ ASSERT_EQ(Net::Disconnected, state)
|
|
|
+ << "Ended with a network error!";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ void receive(NetSocket sock, RawData incomingData)
|
|
|
+ {
|
|
|
+ // Only consider our own socket.
|
|
|
+ if(mSocket != sock)
|
|
|
+ return;
|
|
|
+
|
|
|
+ mDataReceived += incomingData.size;
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+TEST(Net, TCPRequest)
|
|
|
+{
|
|
|
+ TcpHandle handler;
|
|
|
|
|
|
handler.mSocket = InvalidSocket;
|
|
|
handler.mDataReceived = 0;
|
|
|
|
|
|
// Hook into the signals.
|
|
|
- Net::smConnectionNotify. notify(&handler, &handle::notify);
|
|
|
- Net::smConnectionReceive.notify(&handler, &handle::receive);
|
|
|
+ Net::smConnectionNotify .notify(&handler, &TcpHandle::notify);
|
|
|
+ Net::smConnectionReceive.notify(&handler, &TcpHandle::receive);
|
|
|
|
|
|
// Open a TCP connection to garagegames.com
|
|
|
handler.mSocket = Net::openConnectTo("72.246.107.193:80");
|
|
@@ -83,79 +85,81 @@ TEST(Net, TCPRequest)
|
|
|
while(Process::processEvents() && (Platform::getRealMilliseconds() < limit) ) {}
|
|
|
|
|
|
// Unhook from the signals.
|
|
|
- Net::smConnectionNotify. remove(&handler, &handle::notify);
|
|
|
- Net::smConnectionReceive.remove(&handler, &handle::receive);
|
|
|
+ Net::smConnectionNotify .remove(&handler, &TcpHandle::notify);
|
|
|
+ Net::smConnectionReceive.remove(&handler, &TcpHandle::receive);
|
|
|
|
|
|
EXPECT_GT(handler.mDataReceived, 0)
|
|
|
<< "Didn't get any data back!";
|
|
|
}
|
|
|
|
|
|
-TEST(Net, JournalTCPRequest)
|
|
|
+struct JournalHandle
|
|
|
{
|
|
|
- struct handle
|
|
|
+ NetSocket mSocket;
|
|
|
+ S32 mDataReceived;
|
|
|
+
|
|
|
+ void notify(NetSocket sock, U32 state)
|
|
|
{
|
|
|
- NetSocket mSocket;
|
|
|
- S32 mDataReceived;
|
|
|
+ // Only consider our own socket.
|
|
|
+ if(mSocket != sock)
|
|
|
+ return;
|
|
|
|
|
|
- void notify(NetSocket sock, U32 state)
|
|
|
+ // Ok - what's the state? We do some dumb responses to given states
|
|
|
+ // in order to fulfill the request.
|
|
|
+ if(state == Net::Connected)
|
|
|
{
|
|
|
- // Only consider our own socket.
|
|
|
- if(mSocket != sock)
|
|
|
- return;
|
|
|
-
|
|
|
- // Ok - what's the state? We do some dumb responses to given states
|
|
|
- // in order to fulfill the request.
|
|
|
- if(state == Net::Connected)
|
|
|
- {
|
|
|
- U8 reqBuffer[] = {
|
|
|
- "GET / HTTP/1.0\nUser-Agent: Torque/1.0\n\n"
|
|
|
- };
|
|
|
-
|
|
|
- Net::Error e = Net::sendtoSocket(mSocket, reqBuffer, sizeof(reqBuffer));
|
|
|
-
|
|
|
- ASSERT_EQ(Net::NoError, e)
|
|
|
- << "Got an error sending our HTTP request!";
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- Process::requestShutdown();
|
|
|
- mSocket = NULL;
|
|
|
- ASSERT_EQ(Net::Disconnected, state)
|
|
|
- << "Ended with a network error!";
|
|
|
- }
|
|
|
- }
|
|
|
+ U8 reqBuffer[] = {
|
|
|
+ "GET / HTTP/1.0\nUser-Agent: Torque/1.0\n\n"
|
|
|
+ };
|
|
|
+
|
|
|
+ Net::Error e = Net::sendtoSocket(mSocket, reqBuffer, sizeof(reqBuffer));
|
|
|
|
|
|
- void receive(NetSocket sock, RawData incomingData)
|
|
|
+ ASSERT_EQ(Net::NoError, e)
|
|
|
+ << "Got an error sending our HTTP request!";
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- // Only consider our own socket.
|
|
|
- if(mSocket != sock)
|
|
|
- return;
|
|
|
- mDataReceived += incomingData.size;
|
|
|
+ Process::requestShutdown();
|
|
|
+ mSocket = NULL;
|
|
|
+ ASSERT_EQ(Net::Disconnected, state)
|
|
|
+ << "Ended with a network error!";
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- void makeRequest()
|
|
|
- {
|
|
|
- mSocket = InvalidSocket;
|
|
|
- mDataReceived = 0;
|
|
|
+ void receive(NetSocket sock, RawData incomingData)
|
|
|
+ {
|
|
|
+ // Only consider our own socket.
|
|
|
+ if(mSocket != sock)
|
|
|
+ return;
|
|
|
+ mDataReceived += incomingData.size;
|
|
|
+ }
|
|
|
|
|
|
- // Hook into the signals.
|
|
|
- Net::smConnectionNotify. notify(this, &handle::notify);
|
|
|
- Net::smConnectionReceive.notify(this, &handle::receive);
|
|
|
+ void makeRequest()
|
|
|
+ {
|
|
|
+ mSocket = InvalidSocket;
|
|
|
+ mDataReceived = 0;
|
|
|
|
|
|
- // Open a TCP connection to garagegames.com
|
|
|
- mSocket = Net::openConnectTo("72.246.107.193:80");
|
|
|
+ // Hook into the signals.
|
|
|
+ Net::smConnectionNotify .notify(this, &JournalHandle::notify);
|
|
|
+ Net::smConnectionReceive.notify(this, &JournalHandle::receive);
|
|
|
|
|
|
- // Let the callbacks enable things to process.
|
|
|
- while(Process::processEvents()) {}
|
|
|
+ // Open a TCP connection to garagegames.com
|
|
|
+ mSocket = Net::openConnectTo("72.246.107.193:80");
|
|
|
|
|
|
- // Unhook from the signals.
|
|
|
- Net::smConnectionNotify. remove(this, &handle::notify);
|
|
|
- Net::smConnectionReceive.remove(this, &handle::receive);
|
|
|
+ // Let the callbacks enable things to process.
|
|
|
+ while(Process::processEvents()) {}
|
|
|
|
|
|
- EXPECT_GT(mDataReceived, 0)
|
|
|
- << "Didn't get any data back!";
|
|
|
- }
|
|
|
- } handler;
|
|
|
+ // Unhook from the signals.
|
|
|
+ Net::smConnectionNotify .remove(this, &JournalHandle::notify);
|
|
|
+ Net::smConnectionReceive.remove(this, &JournalHandle::receive);
|
|
|
+
|
|
|
+ EXPECT_GT(mDataReceived, 0)
|
|
|
+ << "Didn't get any data back!";
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+TEST(Net, JournalTCPRequest)
|
|
|
+{
|
|
|
+ JournalHandle handler;
|
|
|
|
|
|
Journal::Record("journalTCP.jrn");
|
|
|
ASSERT_TRUE(Journal::IsRecording());
|