|
From: <bra...@us...> - 2003-06-05 20:43:26
|
Update of /cvsroot/csp/APPLICATIONS/Networking
In directory sc8-pr-cvs1:/tmp/cvs-serv466
Modified Files:
NetworkingClass.h NetworkingClass.cpp
Log Message:
Updated to use STL strings/vectors and fixed the 5 issues listed on webpage.
Index: NetworkingClass.h
===================================================================
RCS file: /cvsroot/csp/APPLICATIONS/Networking/NetworkingClass.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** NetworkingClass.h 31 May 2003 14:21:16 -0000 1.1
--- NetworkingClass.h 5 Jun 2003 20:43:22 -0000 1.2
***************
*** 5,8 ****
--- 5,12 ----
#include <time.h>
+ #include <vector>
+ #include <deque>
+ #include <algorithm>
+
#ifdef CCXX_NAMESPACES
using namespace std;
***************
*** 13,16 ****
--- 17,22 ----
typedef short NET_ERROR;
+ const NET_ERROR NET_INVALID_PACKET = -5;
+ const NET_ERROR NET_EXCEPTION = -4;
const NET_ERROR NET_NO_MORE_DATA = -3;
const NET_ERROR NET_INVALID_STATE = -2;
***************
*** 42,46 ****
const short PACKET_IDENTIFIER = 0x5E10;
const short DATARATE_TIMEOUT = 1000;
! const short DROPPED_TIMEOUT = 2500;
const short KEEPALIVE_TIMEOUT = 5000;
const short KEEPALIVE_COUNTER = 6;
--- 48,52 ----
const short PACKET_IDENTIFIER = 0x5E10;
const short DATARATE_TIMEOUT = 1000;
! const short DROPPED_TIMEOUT = 500;
const short KEEPALIVE_TIMEOUT = 5000;
const short KEEPALIVE_COUNTER = 6;
***************
*** 55,71 ****
private:
! // buffer struct
! struct NetBuffer
{
! bool processed;
! NET_TYPE type;
!
! short packetseqnbr;
! short packetlength;
! void *packet;
!
! short dataoffset;
! short datalength;
!
};
--- 61,70 ----
private:
! // Recv struct
! struct NetRecv
{
! short ConnectionId;
! NET_TYPE Type;
! string Data;
};
***************
*** 75,83 ****
short StartFiller;
NET_TYPE Type;
! unsigned char SeqNbr;
! unsigned char AckSeqNbr;
short Time;
};
// Internal Struct to hold information.
struct NetConnections
--- 74,90 ----
short StartFiller;
NET_TYPE Type;
! short SeqNbr;
! short AckSeqNbr;
short Time;
};
+ // Packet
+ struct NetBuffer
+ {
+ bool processed;
+ NetHeader header;
+ string data;
+ };
+
// Internal Struct to hold information.
struct NetConnections
***************
*** 85,97 ****
// Connection
- bool inuse; // if we have open connection this is true
- bool pendingclose; // if we get a disconnect we need to still Recv
- // the message so we need to pending close
- // to keep the inuse open until all messages
- // are read from buffer.
-
InetHostAddress addr; // address of connection
tpport_t port; // port of connection
short todo; // what shall we do next send packet?
--- 92,100 ----
// Connection
InetHostAddress addr; // address of connection
tpport_t port; // port of connection
+ short connectionid; // Connection ID for app.
+
short todo; // what shall we do next send packet?
***************
*** 117,134 ****
// Buffer
unsigned long recvdatarate;
! unsigned char recvcount;
! unsigned char recvseqnbr;
! unsigned char recvwritepointer;
! unsigned char recvreadpointer;
! NetBuffer recvbuffer[256];
unsigned long senddatarate;
! unsigned char sendcount;
! unsigned char sendwritepointer;
! unsigned char sendreadpointer;
! NetBuffer sendbuffer[256];
};
// Thread functions
void initial();
--- 120,141 ----
// Buffer
unsigned long recvdatarate;
! short recvseqnbr;
! vector<NetBuffer> recvbuffer;
unsigned long senddatarate;
! short sendseqnbr;
! vector<NetBuffer> sendbuffer;
};
+ // Class variables
+ bool p_bListen;
+
+ UDPSocket *p_Socket;
+ Mutex *p_MutexShared;
+
+ vector<NetConnections> p_Connect;
+ deque<NetRecv> p_Recv;
+
// Thread functions
void initial();
***************
*** 136,151 ****
void final();
! // Class variables
! unsigned char p_sConnectionCount;
! bool p_bShutdown;
! UDPSocket *p_Socket;
! Mutex *p_MutexShared;
! NetConnections p_Connect[256];
- short Resend(short ConnectionId, NetBuffer *Packet);
- short Reject(InetHostAddress Addr, tpport_t Port, void *Data, short Length);
short ReportLocalMessage(short ConnectionId, NET_TYPE Type);
public:
--- 143,166 ----
void final();
! // Private functions
! short LowLevelRecv();
! short InternalSend(short ArrayEntry, bool Guaranteed);
! short InternalSend(short ArrayEntry, bool Guaranteed, string Data);
!
! short LowLevelSend(InetHostAddress Addr,
! tpport_t Port,
! short Type,
! short SeqNbr,
! short AckSeqNbr,
! short Time,
! string *Data,
! short *Length);
!
! short ConnectionIdToArrayEntry(short ConnectionId);
short ReportLocalMessage(short ConnectionId, NET_TYPE Type);
+ short ReportLocalMessage(short ConnectionId, NET_TYPE Type, string *Data);
public:
***************
*** 157,177 ****
// Operations
! short Connect(short ConnectionId, char *IP, char *Port, void*Data, short Length);
! short Send(short ConnectionId, bool Guaranteed, void *Data, short Length);
! short Recv(short ConnectionId, NET_TYPE *Type, void *Data, short *Length);
! short Accept(short ConnectionId, void *Data, short Length);
! short Reject(short ConnectionId, void *Data, short Length);
! short Disconnect(short ConnectionId, void *Data, short Length);
// Query Performance
short GetConnections(); // How many others we're connected to.
- bool GetActive(short ConnectionId); // See if this connection is active.
short GetPing(short ConnectionId); // Time to go over internet.
short GetLatency(short ConnectionId); // Time the server takes to ack.
- short GetRecvMessages(short ConnectionId); // How many messages are waiting to be recv'd.
short GetSendBufferCount(short ConnectionId); // How many packets are in the sendbuffer yet to be acknowledged from server.
short GetRecvBufferCount(short ConnectionId); // How many packets are in the recvbuffer waiting to be acknowledged from us.
! unsigned long GetSendDataRate(short ConnectionId); // How many bytes per second are being sent.
! unsigned long GetRecvDataRate(short ConnectionId); // How many bytes per second are being recv.
// FlipFlop functions, used to convert Endians.
--- 172,200 ----
// Operations
! short Connect(short ConnectionId, char *IP, char *Port, string Data);
! short Connect(short ConnectionId, char *IP, char *Port);
!
! short Send(short ConnectionId, bool Guaranteed, string Data);
! short Recv(short *ConnectionId, NET_TYPE *Type, string *Data);
!
! short Listen(bool On);
!
! short Accept(short ConnectionId, string Data);
! short Accept(short ConnectionId);
!
! short Reject(short ConnectionId, string Data);
! short Reject(short ConnectionId);
!
! short Disconnect(short ConnectionId, string Data);
! short Disconnect(short ConnectionId);
// Query Performance
short GetConnections(); // How many others we're connected to.
short GetPing(short ConnectionId); // Time to go over internet.
short GetLatency(short ConnectionId); // Time the server takes to ack.
short GetSendBufferCount(short ConnectionId); // How many packets are in the sendbuffer yet to be acknowledged from server.
short GetRecvBufferCount(short ConnectionId); // How many packets are in the recvbuffer waiting to be acknowledged from us.
! short GetSendDataRate(short ConnectionId); // How many bytes per second are being sent.
! short GetRecvDataRate(short ConnectionId); // How many bytes per second are being recv.
// FlipFlop functions, used to convert Endians.
Index: NetworkingClass.cpp
===================================================================
RCS file: /cvsroot/csp/APPLICATIONS/Networking/NetworkingClass.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** NetworkingClass.cpp 31 May 2003 14:21:16 -0000 1.1
--- NetworkingClass.cpp 5 Jun 2003 20:43:22 -0000 1.2
***************
*** 4,11 ****
{
! p_bShutdown = true;
! p_sConnectionCount = 0;
!
! memset(p_Connect, 0, sizeof(p_Connect));
// Setup variables
--- 4,8 ----
{
[...2928 lines suppressed...]
! }
!
! // ------------------------------------
!
! return (short)p_Connect[ArrayEntry].senddatarate;
}
+
void NetworkingClass::FlipFlop(unsigned short &number)
{
***************
*** 1787,1789 ****
return;
! }
\ No newline at end of file
--- 1416,1418 ----
return;
! }
|