Remove %NODE_NAME% from variable names
This commit is contained in:
parent
7574cf9dd0
commit
ec17a10562
5 changed files with 74 additions and 74 deletions
|
@ -30,8 +30,8 @@ void OnTcpReceive(dword socket, long result, dword address, dword port, byte buf
|
|||
{
|
||||
// Size of zero indicates that the socket was closed by the communication peer.
|
||||
writeLineEx(0, 2, "<%NODE_NAME%> OnTcpReceive: Socket closed by peer");
|
||||
g_%NODE_NAME%_Socket.Close();
|
||||
g_%NODE_NAME%_SocketState = CLOSED;
|
||||
gSocket.Close();
|
||||
gSocketState = CLOSED;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -42,10 +42,10 @@ void OnTcpReceive(dword socket, long result, dword address, dword port, byte buf
|
|||
}
|
||||
else
|
||||
{
|
||||
gIpLastErr = g_%NODE_NAME%_Socket.GetLastSocketError();
|
||||
g_%NODE_NAME%_Socket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
|
||||
gIpLastErr = gSocket.GetLastSocketError();
|
||||
gSocket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
|
||||
writeLineEx(0, 2, "<%NODE_NAME%> OnTcpReceive error (%d): %s", gIpLastErr, gIpLastErrStr);
|
||||
g_%NODE_NAME%_Socket.Close();
|
||||
g_%NODE_NAME%_SocketState = CLOSED;
|
||||
gSocket.Close();
|
||||
gSocketState = CLOSED;
|
||||
}
|
||||
}
|
|
@ -30,8 +30,8 @@ void OnUdpReceiveFrom(dword socket, long result, dword address, dword port, byte
|
|||
{
|
||||
// Size of zero indicates that the socket was closed by the communication peer.
|
||||
writeLineEx(0, 2, "<%BASE_FILE_NAME%> OnTcpReceive: Socket closed by peer");
|
||||
g_%NODE_NAME%_Socket.Close();
|
||||
g_%NODE_NAME%_SocketState = CLOSED;
|
||||
gSocket.Close();
|
||||
gSocketState = CLOSED;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -42,10 +42,10 @@ void OnUdpReceiveFrom(dword socket, long result, dword address, dword port, byte
|
|||
}
|
||||
else
|
||||
{
|
||||
gIpLastErr = g_%NODE_NAME%_Socket.GetLastSocketError();
|
||||
g_%NODE_NAME%_Socket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
|
||||
gIpLastErr = gSocket.GetLastSocketError();
|
||||
gSocket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
|
||||
writeLineEx(0, 2, "<%BASE_FILE_NAME%> OnTcpReceive error (%d): %s", gIpLastErr, gIpLastErrStr);
|
||||
g_%NODE_NAME%_Socket.Close();
|
||||
g_%NODE_NAME%_SocketState = CLOSED;
|
||||
gSocket.Close();
|
||||
gSocketState = CLOSED;
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@ includes
|
|||
|
||||
variables
|
||||
{
|
||||
TcpSocket g_%NODE_NAME%_Socket;
|
||||
TcpSocket gSocket;
|
||||
|
||||
byte gRxBuffer[8192];
|
||||
}
|
||||
|
@ -30,19 +30,19 @@ word TcpOpenSocket()
|
|||
// Try to open socket
|
||||
do
|
||||
{
|
||||
g_%NODE_NAME%_Socket = TcpSocket::Open(localIp, localPort);
|
||||
if (g_%NODE_NAME%_Socket.GetLastSocketError() != 0)
|
||||
gSocket = TcpSocket::Open(localIp, localPort);
|
||||
if (gSocket.GetLastSocketError() != 0)
|
||||
{
|
||||
g_%NODE_NAME%_Socket.GetLastSocketErrorAsString(errorText, elcount(errorText));
|
||||
writeLineEx(0, 1, "<%NODE_NAME%> Error: could not open Tcp socket on %s:%d, %s (%d)!", Local_IP, localPort, errorText, g_%NODE_NAME%_Socket.GetLastSocketError());
|
||||
gSocket.GetLastSocketErrorAsString(errorText, elcount(errorText));
|
||||
writeLineEx(0, 1, "<%NODE_NAME%> Error: could not open Tcp socket on %s:%d, %s (%d)!", Local_IP, localPort, errorText, gSocket.GetLastSocketError());
|
||||
}
|
||||
}
|
||||
while (g_%NODE_NAME%_Socket.GetLastSocketError() != 0 && i++ < 9);
|
||||
while (gSocket.GetLastSocketError() != 0 && i++ < 9);
|
||||
|
||||
if (g_%NODE_NAME%_Socket.GetLastSocketError() != 0)
|
||||
if (gSocket.GetLastSocketError() != 0)
|
||||
{
|
||||
writeLineEx(0, 1, "<%NODE_NAME%> Error: could not open Tcp socket!");
|
||||
return g_%NODE_NAME%_Socket.GetLastSocketError();
|
||||
return gSocket.GetLastSocketError();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -76,23 +76,23 @@ word TcpConnectTo(dword remoteIp, word remotePort)
|
|||
fehler = TcpOpenSocket();
|
||||
if (fehler != 0)
|
||||
{
|
||||
g_%NODE_NAME%_SocketState = ERROR;
|
||||
gSocketState = ERROR;
|
||||
return fehler;
|
||||
}
|
||||
|
||||
g_%NODE_NAME%_RemoteIP = remoteIp;
|
||||
g_%NODE_NAME%_RemotePort = remotePort;
|
||||
gRemoteIP = remoteIp;
|
||||
gRemotePort = remotePort;
|
||||
|
||||
|
||||
// Connect to Server
|
||||
if (g_%NODE_NAME%_Socket.Connect(remoteIp, remotePort) != 0)
|
||||
if (gSocket.Connect(remoteIp, remotePort) != 0)
|
||||
{
|
||||
fehler = g_%NODE_NAME%_Socket.GetLastSocketError();
|
||||
fehler = gSocket.GetLastSocketError();
|
||||
|
||||
if (fehler != WSAEWOULDBLOCK) // OnTcpConnect will be called otherwise
|
||||
{
|
||||
write("<%NODE_NAME%> No Port-Connection: %d", fehler);
|
||||
g_%NODE_NAME%_SocketState = ERROR;
|
||||
gSocketState = ERROR;
|
||||
return fehler;
|
||||
}
|
||||
return 0;
|
||||
|
@ -100,7 +100,7 @@ word TcpConnectTo(dword remoteIp, word remotePort)
|
|||
else
|
||||
{
|
||||
writeLineEx(0, 1, "<%NODE_NAME%> Successfully connected to server");
|
||||
g_%NODE_NAME%_SocketState = OK;
|
||||
gSocketState = OK;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -109,15 +109,15 @@ void OnTcpConnect(dword socket, long result)
|
|||
{
|
||||
if (result != 0)
|
||||
{
|
||||
g_%NODE_NAME%_Socket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
|
||||
writeLineEx(0, 2, "<%NODE_NAME%> OnTcpConnect error (%d): %s", g_%NODE_NAME%_Socket.GetLastSocketError(), gIpLastErrStr);
|
||||
g_%NODE_NAME%_SocketState = ERROR;
|
||||
gSocket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
|
||||
writeLineEx(0, 2, "<%NODE_NAME%> OnTcpConnect error (%d): %s", gSocket.GetLastSocketError(), gIpLastErrStr);
|
||||
gSocketState = ERROR;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
writeLineEx(0, 1, "<%NODE_NAME%> Successfully connected to server");
|
||||
g_%NODE_NAME%_SocketState = OK;
|
||||
gSocketState = OK;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,24 +125,24 @@ void TcpRecv()
|
|||
{
|
||||
int result;
|
||||
|
||||
if (g_%NODE_NAME%_SocketState != OK)
|
||||
if (gSocketState != OK)
|
||||
{
|
||||
writeLineEx(0, 2, "TcpRecv: Socket status is not OK!");
|
||||
return;
|
||||
}
|
||||
|
||||
result = g_%NODE_NAME%_Socket.Receive(gRxBuffer, elcount(gRxBuffer));
|
||||
result = gSocket.Receive(gRxBuffer, elcount(gRxBuffer));
|
||||
|
||||
if (result != 0) // Calling OnTcpReceive otherwise
|
||||
{
|
||||
gIpLastErr = g_%NODE_NAME%_Socket.GetLastSocketError();
|
||||
gIpLastErr = gSocket.GetLastSocketError();
|
||||
|
||||
if (gIpLastErr != WSA_IO_PENDING) // Calling OnTcpReceive otherwise
|
||||
{
|
||||
g_%NODE_NAME%_Socket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
|
||||
gSocket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
|
||||
writeLineEx(0, 2, "<%NODE_NAME%> TcpReceive error (%d): %s", gIpLastErr, gIpLastErrStr);
|
||||
g_%NODE_NAME%_Socket.Close();
|
||||
g_%NODE_NAME%_SocketState = CLOSED;
|
||||
gSocket.Close();
|
||||
gSocketState = CLOSED;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,11 +153,11 @@ void TcpSnd(byte buffer[])
|
|||
{
|
||||
char str[20*3];
|
||||
|
||||
switch (g_%NODE_NAME%_SocketState)
|
||||
switch (gSocketState)
|
||||
{
|
||||
case CLOSED:
|
||||
TcpConnectTo(g_%NODE_NAME%_RemoteIP, g_%NODE_NAME%_RemotePort);
|
||||
if (g_%NODE_NAME%_SocketState != OK)
|
||||
TcpConnectTo(gRemoteIP, gRemotePort);
|
||||
if (gSocketState != OK)
|
||||
{
|
||||
writeLineEx(0, 2, "TcpSnd: Reconnecting failed!");
|
||||
return;
|
||||
|
@ -172,16 +172,16 @@ void TcpSnd(byte buffer[])
|
|||
bin_to_strhex(buffer, str);
|
||||
writeLineEx(0, 1, "<%NODE_NAME%> TcpSnd: %s (Länge: %d)", str, elCount(buffer));
|
||||
|
||||
if (g_%NODE_NAME%_Socket.Send(buffer, elCount(buffer)) != 0)
|
||||
if (gSocket.Send(buffer, elCount(buffer)) != 0)
|
||||
{
|
||||
gIpLastErr = g_%NODE_NAME%_Socket.GetLastSocketError();
|
||||
gIpLastErr = gSocket.GetLastSocketError();
|
||||
|
||||
if (gIpLastErr != WSA_IO_PENDING)
|
||||
{
|
||||
g_%NODE_NAME%_Socket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
|
||||
gSocket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
|
||||
writeLineEx(0, 2, "<%NODE_NAME%> TcpSnd error (%d): %s", gIpLastErr, gIpLastErrStr);
|
||||
g_%NODE_NAME%_Socket.Close();
|
||||
g_%NODE_NAME%_SocketState = CLOSED;
|
||||
gSocket.Close();
|
||||
gSocketState = CLOSED;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,10 +10,10 @@ variables
|
|||
char gIpLastErrStr[512] = "";
|
||||
|
||||
enum SocketState { NULL, OK, ERROR, CLOSED };
|
||||
enum SocketState g_%NODE_NAME%_SocketState = NULL;
|
||||
enum SocketState gSocketState = NULL;
|
||||
|
||||
dword g_%NODE_NAME%_RemoteIP = INVALID_IP;
|
||||
word g_%NODE_NAME%_RemotePort = 0;
|
||||
dword gRemoteIP = INVALID_IP;
|
||||
word gRemotePort = 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ includes
|
|||
|
||||
variables
|
||||
{
|
||||
UdpSocket g_%NODE_NAME%_Socket;
|
||||
UdpSocket gSocket;
|
||||
|
||||
byte gRxBuffer[8192];
|
||||
}
|
||||
|
@ -30,19 +30,19 @@ word UdpOpenSocket()
|
|||
// Try to open socket
|
||||
do
|
||||
{
|
||||
g_%NODE_NAME%_Socket = UdpSocket::Open(localIp, localPort);
|
||||
if (g_%NODE_NAME%_Socket.GetLastSocketError() != 0)
|
||||
gSocket = UdpSocket::Open(localIp, localPort);
|
||||
if (gSocket.GetLastSocketError() != 0)
|
||||
{
|
||||
g_%NODE_NAME%_Socket.GetLastSocketErrorAsString(errorText, elcount(errorText));
|
||||
writeLineEx(0, 1, "<%BASE_FILE_NAME%> Error: could not open Udp socket on %s:%d, %s (%d)!", Local_IP, localPort, errorText, g_%NODE_NAME%_Socket.GetLastSocketError());
|
||||
gSocket.GetLastSocketErrorAsString(errorText, elcount(errorText));
|
||||
writeLineEx(0, 1, "<%BASE_FILE_NAME%> Error: could not open Udp socket on %s:%d, %s (%d)!", Local_IP, localPort, errorText, gSocket.GetLastSocketError());
|
||||
}
|
||||
}
|
||||
while (g_%NODE_NAME%_Socket.GetLastSocketError() != 0 && i++ < 9);
|
||||
while (gSocket.GetLastSocketError() != 0 && i++ < 9);
|
||||
|
||||
if (g_%NODE_NAME%_Socket.GetLastSocketError() != 0)
|
||||
if (gSocket.GetLastSocketError() != 0)
|
||||
{
|
||||
writeLineEx(0, 1, "<%BASE_FILE_NAME%> Error: could not open Udp socket!");
|
||||
return g_%NODE_NAME%_Socket.GetLastSocketError();
|
||||
return gSocket.GetLastSocketError();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -76,13 +76,13 @@ word UdpConnectTo(dword remoteIp, word remotePort)
|
|||
fehler = UdpOpenSocket();
|
||||
if (fehler != 0)
|
||||
{
|
||||
g_%NODE_NAME%_SocketState = ERROR;
|
||||
gSocketState = ERROR;
|
||||
return fehler;
|
||||
}
|
||||
|
||||
g_%NODE_NAME%_RemoteIP = remoteIp;
|
||||
g_%NODE_NAME%_RemotePort = remotePort;
|
||||
g_%NODE_NAME%_SocketState = OK;
|
||||
gRemoteIP = remoteIp;
|
||||
gRemotePort = remotePort;
|
||||
gSocketState = OK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -90,24 +90,24 @@ void UdpRecv()
|
|||
{
|
||||
int result;
|
||||
|
||||
if (g_%NODE_NAME%_SocketState != OK)
|
||||
if (gSocketState != OK)
|
||||
{
|
||||
writeLineEx(0, 2, "UdpRecv: Socket status is not OK!");
|
||||
return;
|
||||
}
|
||||
|
||||
result = g_%NODE_NAME%_Socket.ReceiveFrom(gRxBuffer, elcount(gRxBuffer));
|
||||
result = gSocket.ReceiveFrom(gRxBuffer, elcount(gRxBuffer));
|
||||
|
||||
if (result != 0) // Calling OnUdpReceive otherwise
|
||||
{
|
||||
gIpLastErr = g_%NODE_NAME%_Socket.GetLastSocketError();
|
||||
gIpLastErr = gSocket.GetLastSocketError();
|
||||
|
||||
if (gIpLastErr != WSA_IO_PENDING) // Calling OnUdpReceive otherwise
|
||||
{
|
||||
g_%NODE_NAME%_Socket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
|
||||
gSocket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
|
||||
writeLineEx(0, 2, "<%BASE_FILE_NAME%> UdpRecv Error (%d): %s", gIpLastErr, gIpLastErrStr);
|
||||
g_%NODE_NAME%_Socket.Close();
|
||||
g_%NODE_NAME%_SocketState = CLOSED;
|
||||
gSocket.Close();
|
||||
gSocketState = CLOSED;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,11 +118,11 @@ void UdpSnd(byte buffer[])
|
|||
{
|
||||
char str[20*3];
|
||||
|
||||
switch (g_%NODE_NAME%_SocketState)
|
||||
switch (gSocketState)
|
||||
{
|
||||
case CLOSED:
|
||||
UdpConnectTo(g_%NODE_NAME%_RemoteIP, g_%NODE_NAME%_RemotePort);
|
||||
if (g_%NODE_NAME%_SocketState != OK)
|
||||
UdpConnectTo(gRemoteIP, gRemotePort);
|
||||
if (gSocketState != OK)
|
||||
{
|
||||
writeLineEx(0, 2, "UdpSnd: Reconnecting failed!");
|
||||
return;
|
||||
|
@ -137,16 +137,16 @@ void UdpSnd(byte buffer[])
|
|||
bin_to_strhex(buffer, str);
|
||||
writeLineEx(0, 1, "<%BASE_FILE_NAME%> UdpSnd: %s (Länge: %d)", str, elCount(buffer));
|
||||
|
||||
if (g_%NODE_NAME%_Socket.SendTo(g_%NODE_NAME%_RemoteIP, g_%NODE_NAME%_RemotePort, buffer, elCount(buffer)) != 0)
|
||||
if (gSocket.SendTo(gRemoteIP, gRemotePort, buffer, elCount(buffer)) != 0)
|
||||
{
|
||||
gIpLastErr = g_%NODE_NAME%_Socket.GetLastSocketError();
|
||||
gIpLastErr = gSocket.GetLastSocketError();
|
||||
|
||||
if (gIpLastErr != WSA_IO_PENDING)
|
||||
{
|
||||
g_%NODE_NAME%_Socket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
|
||||
gSocket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
|
||||
writeLineEx(0, 2, "<%BASE_FILE_NAME%> UdpSnd error (%d): %s", gIpLastErr, gIpLastErrStr);
|
||||
g_%NODE_NAME%_Socket.Close();
|
||||
g_%NODE_NAME%_SocketState = CLOSED;
|
||||
gSocket.Close();
|
||||
gSocketState = CLOSED;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue