Debugging the Gateway functionality.
This commit is contained in:
parent
5e6b6a4061
commit
9296316ffe
6 changed files with 32 additions and 29 deletions
|
@ -112,9 +112,6 @@ bool CNetwork::writePoll()
|
|||
buffer[12U] = ' ';
|
||||
buffer[13U] = ' ';
|
||||
|
||||
if (m_debug)
|
||||
CUtils::dump(1U, "YSF Network Poll Sent", buffer, 14U);
|
||||
|
||||
return m_socket.write(buffer, 14U, m_address, m_port);
|
||||
}
|
||||
|
||||
|
|
|
@ -31,8 +31,7 @@ m_socket(port),
|
|||
m_address(),
|
||||
m_port(0U),
|
||||
m_debug(debug),
|
||||
m_buffer(1000U, "YSF Network"),
|
||||
m_pollTimer(1000U, 5U)
|
||||
m_buffer(1000U, "YSF Network")
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -44,16 +43,14 @@ bool CNetwork::open()
|
|||
{
|
||||
::fprintf(stdout, "Opening YSF network connection\n");
|
||||
|
||||
if (m_address.s_addr == INADDR_NONE)
|
||||
return false;
|
||||
|
||||
m_pollTimer.start();
|
||||
|
||||
return m_socket.open();
|
||||
}
|
||||
|
||||
bool CNetwork::write(const unsigned char* data)
|
||||
{
|
||||
if (m_port == 0U)
|
||||
return true;
|
||||
|
||||
assert(data != NULL);
|
||||
|
||||
if (m_debug)
|
||||
|
@ -62,7 +59,7 @@ bool CNetwork::write(const unsigned char* data)
|
|||
return m_socket.write(data, 155U, m_address, m_port);
|
||||
}
|
||||
|
||||
bool CNetwork::writePoll()
|
||||
bool CNetwork::writePoll(const in_addr& address, unsigned int port)
|
||||
{
|
||||
unsigned char buffer[20U];
|
||||
|
||||
|
@ -82,20 +79,11 @@ bool CNetwork::writePoll()
|
|||
buffer[12U] = ' ';
|
||||
buffer[13U] = ' ';
|
||||
|
||||
if (m_debug)
|
||||
CUtils::dump(1U, "YSF Network Poll Sent", buffer, 14U);
|
||||
|
||||
return m_socket.write(buffer, 14U, m_address, m_port);
|
||||
return m_socket.write(buffer, 14U, address, port);
|
||||
}
|
||||
|
||||
void CNetwork::clock(unsigned int ms)
|
||||
{
|
||||
m_pollTimer.clock(ms);
|
||||
if (m_pollTimer.hasExpired()) {
|
||||
writePoll();
|
||||
m_pollTimer.start();
|
||||
}
|
||||
|
||||
unsigned char buffer[BUFFER_LENGTH];
|
||||
|
||||
in_addr address;
|
||||
|
@ -104,12 +92,11 @@ void CNetwork::clock(unsigned int ms)
|
|||
if (length <= 0)
|
||||
return;
|
||||
|
||||
m_address.s_addr = address.s_addr;
|
||||
m_port = port;
|
||||
|
||||
// Ignore incoming polls
|
||||
if (::memcmp(buffer, "YSFP", 4U) == 0)
|
||||
// Handle incoming polls
|
||||
if (::memcmp(buffer, "YSFP", 4U) == 0) {
|
||||
writePoll(address, port);
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle the status command
|
||||
if (::memcmp(buffer, "YSFS", 4U) == 0) {
|
||||
|
@ -123,6 +110,9 @@ void CNetwork::clock(unsigned int ms)
|
|||
if (::memcmp(buffer, "YSFD", 4U) != 0)
|
||||
return;
|
||||
|
||||
m_address.s_addr = address.s_addr;
|
||||
m_port = port;
|
||||
|
||||
if (m_debug)
|
||||
CUtils::dump(1U, "YSF Network Data Received", buffer, length);
|
||||
|
||||
|
@ -141,6 +131,11 @@ unsigned int CNetwork::read(unsigned char* data)
|
|||
return 155U;
|
||||
}
|
||||
|
||||
void CNetwork::end()
|
||||
{
|
||||
m_port = 0U;
|
||||
}
|
||||
|
||||
void CNetwork::close()
|
||||
{
|
||||
m_socket.close();
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include "YSFDefines.h"
|
||||
#include "RingBuffer.h"
|
||||
#include "UDPSocket.h"
|
||||
#include "Timer.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
@ -38,6 +37,8 @@ public:
|
|||
|
||||
unsigned int read(unsigned char* data);
|
||||
|
||||
void end();
|
||||
|
||||
void close();
|
||||
|
||||
void clock(unsigned int ms);
|
||||
|
@ -48,9 +49,8 @@ private:
|
|||
unsigned int m_port;
|
||||
bool m_debug;
|
||||
CRingBuffer<unsigned char> m_buffer;
|
||||
CTimer m_pollTimer;
|
||||
|
||||
bool writePoll();
|
||||
bool writePoll(const in_addr& address, unsigned int port);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -57,6 +57,12 @@ void CParrot::end()
|
|||
m_ptr = 0U;
|
||||
}
|
||||
|
||||
void CParrot::clear()
|
||||
{
|
||||
m_used = 0U;
|
||||
m_ptr = 0U;
|
||||
}
|
||||
|
||||
unsigned int CParrot::read(unsigned char* data)
|
||||
{
|
||||
assert(data != NULL);
|
||||
|
|
|
@ -31,6 +31,8 @@ public:
|
|||
|
||||
void end();
|
||||
|
||||
void clear();
|
||||
|
||||
private:
|
||||
unsigned char* m_data;
|
||||
unsigned int m_length;
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "Parrot.h"
|
||||
#include "Network.h"
|
||||
#include "Version.h"
|
||||
#include "Timer.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
@ -105,6 +106,8 @@ void CYSFParrot::run()
|
|||
network.write(buffer);
|
||||
count++;
|
||||
} else {
|
||||
parrot.clear();
|
||||
network.end();
|
||||
turnaroundTimer.stop();
|
||||
playing = false;
|
||||
count = wanted;
|
||||
|
|
Loading…
Reference in a new issue