mirror of
https://bitbucket.org/theswgsource/src-1.2.git
synced 2026-10-21 11:02:58 -04:00
this is a more "clean" conversion to 64 bit than the type-fixups branch, which does borrow some elements from it but has far less find and replace...it is about 98-99% done, notes to follow later
This commit is contained in:
+2
-1
@@ -6,8 +6,9 @@ class UdpManager;
|
||||
class UdpConnection;
|
||||
class LogicalPacket;
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef unsigned char uchar;
|
||||
typedef unsigned short ushort;
|
||||
typedef unsigned int uint;
|
||||
typedef unsigned long ulong;
|
||||
|
||||
|
||||
+17
-17
@@ -481,7 +481,7 @@ void UdpManager::CreateAndBindSocket(int usePort)
|
||||
// bind it to any address
|
||||
struct sockaddr_in addr_loc;
|
||||
addr_loc.sin_family = PF_INET;
|
||||
addr_loc.sin_port = htons((ushort)usePort);
|
||||
addr_loc.sin_port = htons((uint16_t)usePort);
|
||||
|
||||
addr_loc.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
if (mParams.bindIpAddress[0] != 0)
|
||||
@@ -954,7 +954,7 @@ void UdpManager::ActualSendHelper(const uchar *data, int dataLen, UdpIpAddress i
|
||||
struct sockaddr_in addr_dest;
|
||||
addr_dest.sin_family = PF_INET;
|
||||
addr_dest.sin_addr.s_addr = ip.GetAddress();
|
||||
addr_dest.sin_port = htons((ushort)port);
|
||||
addr_dest.sin_port = htons((uint16_t)port);
|
||||
if (SOCKET_ERROR == sendto(mUdpSocket, (const char *)data, dataLen, 0, (struct sockaddr *)&addr_dest, sizeof(addr_dest)))
|
||||
{
|
||||
// error writing to socket, what is the error?
|
||||
@@ -1432,7 +1432,7 @@ void UdpConnection::SendTerminatePacket(int connectCode, DisconnectReason reason
|
||||
buf[0] = 0;
|
||||
buf[1] = cUdpPacketTerminate;
|
||||
UdpMisc::PutValue32(buf + 2, connectCode);
|
||||
UdpMisc::PutValue16(buf + 6, (ushort)reason);
|
||||
UdpMisc::PutValue16(buf + 6, (uint16_t)reason);
|
||||
PhysicalSend(buf, 8, true);
|
||||
}
|
||||
|
||||
@@ -1529,7 +1529,7 @@ bool UdpConnection::InternalSend(UdpChannel channel, const uchar *data, int data
|
||||
uchar *bufPtr = tempBuffer;
|
||||
bufPtr[0] = 0;
|
||||
bufPtr[1] = cUdpPacketOrdered2;
|
||||
UdpMisc::PutValue16(bufPtr + 2, (ushort)(++mOrderedCountOutgoing2 & 0xffff));
|
||||
UdpMisc::PutValue16(bufPtr + 2, (uint16_t)(++mOrderedCountOutgoing2 & 0xffff));
|
||||
memcpy(bufPtr + 4, data, dataLen);
|
||||
if (data2 != nullptr)
|
||||
memcpy(bufPtr + 4 + dataLen, data2, dataLen2);
|
||||
@@ -1542,7 +1542,7 @@ bool UdpConnection::InternalSend(UdpChannel channel, const uchar *data, int data
|
||||
uchar *bufPtr = tempBuffer;
|
||||
bufPtr[0] = 0;
|
||||
bufPtr[1] = cUdpPacketOrdered2;
|
||||
UdpMisc::PutValue16(bufPtr + 2, (ushort)(++mOrderedCountOutgoing2 & 0xffff));
|
||||
UdpMisc::PutValue16(bufPtr + 2, (uint16_t)(++mOrderedCountOutgoing2 & 0xffff));
|
||||
memcpy(bufPtr + 4, data, dataLen);
|
||||
if (data2 != nullptr)
|
||||
memcpy(bufPtr + 4 + dataLen, data2, dataLen2);
|
||||
@@ -1933,7 +1933,7 @@ void UdpConnection::ProcessCookedPacket(const uchar *data, int dataLen)
|
||||
}
|
||||
case cUdpPacketOrdered:
|
||||
{
|
||||
ushort orderedStamp = UdpMisc::GetValue16(data + 2);
|
||||
uint16_t orderedStamp = UdpMisc::GetValue16(data + 2);
|
||||
int diff = (int)orderedStamp - (int)mOrderedStampLast;
|
||||
if (diff <= 0) // equal here makes it strip dupes too
|
||||
diff += 0x10000;
|
||||
@@ -1951,7 +1951,7 @@ void UdpConnection::ProcessCookedPacket(const uchar *data, int dataLen)
|
||||
}
|
||||
case cUdpPacketOrdered2:
|
||||
{
|
||||
ushort orderedStamp = UdpMisc::GetValue16(data + 2);
|
||||
uint16_t orderedStamp = UdpMisc::GetValue16(data + 2);
|
||||
int diff = (int)orderedStamp - (int)mOrderedStampLast2;
|
||||
if (diff <= 0) // equal here makes it strip dupes too
|
||||
diff += 0x10000;
|
||||
@@ -2095,7 +2095,7 @@ void UdpConnection::ProcessCookedPacket(const uchar *data, int dataLen)
|
||||
pp.ourSent = UdpMisc::GetValue64(data + 24);
|
||||
pp.ourReceived = UdpMisc::GetValue64(data + 32);
|
||||
|
||||
ushort curStamp = UdpMisc::LocalSyncStampShort();
|
||||
uint16_t curStamp = UdpMisc::LocalSyncStampShort();
|
||||
int roundTime = UdpMisc::SyncStampShortDeltaTime(pp.timeStamp, curStamp);
|
||||
|
||||
mSyncStatCount++;
|
||||
@@ -2555,7 +2555,7 @@ void UdpConnection::PhysicalSend(const uchar *data, int dataLen, bool appendAllo
|
||||
*crcPtr = (uchar)(crc & 0xff);
|
||||
break;
|
||||
case 2:
|
||||
UdpMisc::PutValue16(crcPtr, (ushort)(crc & 0xffff));
|
||||
UdpMisc::PutValue16(crcPtr, (uint16_t)(crc & 0xffff));
|
||||
break;
|
||||
case 3:
|
||||
UdpMisc::PutValue24(crcPtr, crc & 0xffffff);
|
||||
@@ -3360,7 +3360,7 @@ int UdpReliableChannel::GiveTime()
|
||||
bufPtr = buf;
|
||||
*bufPtr++ = 0;
|
||||
*bufPtr++ = (uchar)(((fragment) ? UdpConnection::cUdpPacketFragment1 : UdpConnection::cUdpPacketReliable1) + mChannelNumber); // mark us as a fragment if we are one
|
||||
bufPtr += UdpMisc::PutValue16(bufPtr, (ushort)(reliableId & 0xffff));
|
||||
bufPtr += UdpMisc::PutValue16(bufPtr, (uint16_t)(reliableId & 0xffff));
|
||||
if (fragment && entry->mDataPtr == parentBase)
|
||||
bufPtr += UdpMisc::PutValue32(bufPtr, entry->mParent->GetDataLen()); // first fragment has a total-length byte after the reliable header
|
||||
mUdpConnection->BufferedSend(buf, bufPtr - buf, entry->mDataPtr, entry->mDataLen, false);
|
||||
@@ -3507,7 +3507,7 @@ void UdpReliableChannel::ReliablePacket(const uchar *data, int dataLen)
|
||||
}
|
||||
|
||||
int packetType = data[1];
|
||||
ushort reliableStamp = UdpMisc::GetValue16(data + 2);
|
||||
uint16_t reliableStamp = UdpMisc::GetValue16(data + 2);
|
||||
udp_int64 reliableId = GetReliableIncomingId(reliableStamp);
|
||||
|
||||
if (reliableId >= mReliableIncomingId + mConfig.maxInstandingPackets)
|
||||
@@ -3577,13 +3577,13 @@ void UdpReliableChannel::ReliablePacket(const uchar *data, int dataLen)
|
||||
{
|
||||
// ack everything up to the current head of our chain (minus one since the stamp represents the next one we want to get)
|
||||
*bufPtr++ = (uchar)(UdpConnection::cUdpPacketAckAll1 + mChannelNumber);
|
||||
bufPtr += UdpMisc::PutValue16(bufPtr, (ushort)((mReliableIncomingId - 1) & 0xffff));
|
||||
bufPtr += UdpMisc::PutValue16(bufPtr, (uint16_t)((mReliableIncomingId - 1) & 0xffff));
|
||||
}
|
||||
else
|
||||
{
|
||||
// a simple ack for us only
|
||||
*bufPtr++ = (uchar)(UdpConnection::cUdpPacketAck1 + mChannelNumber);
|
||||
bufPtr += UdpMisc::PutValue16(bufPtr, (ushort)(reliableId & 0xffff));
|
||||
bufPtr += UdpMisc::PutValue16(bufPtr, (uint16_t)(reliableId & 0xffff));
|
||||
mBufferedAckPtr = nullptr; // not allowed to replace an old one with a selective-ack
|
||||
}
|
||||
|
||||
@@ -3640,7 +3640,7 @@ void UdpReliableChannel::ProcessPacket(ReliablePacketMode mode, const uchar *dat
|
||||
|
||||
void UdpReliableChannel::AckAllPacket(const uchar *data, int /*dataLen*/)
|
||||
{
|
||||
udp_int64 reliableId = GetReliableOutgoingId((ushort)UdpMisc::GetValue16(data + 2));
|
||||
udp_int64 reliableId = GetReliableOutgoingId((uint16_t)UdpMisc::GetValue16(data + 2));
|
||||
|
||||
if (mReliableOutgoingPendingId > reliableId)
|
||||
{
|
||||
@@ -3710,7 +3710,7 @@ void UdpReliableChannel::Ack(udp_int64 reliableId)
|
||||
// harm done is that the we may not resend some of the earlier sent packets quite as quickly. This will only
|
||||
// happen in situations where a packet that was truely lost gets acked on it's second attempt...we just
|
||||
// won't be using that ack for the purposes of accelerating other resends...since odds are a non-lost packet
|
||||
// will accelerate those other resends shortly anyhow, there really is no loss
|
||||
// will accelerate those other resends int16_tly anyhow, there really is no loss
|
||||
// (note: we used to only set this value forward for packets that were never lost (one time sends); however, if this stamp
|
||||
// ever got set way high for some reason (in theory it can't happen), then we would get into a situation where it would
|
||||
// rapidly resend and possibly never get reset, causing infinite rapid resends, so we now set it every time to the first-stamp)
|
||||
@@ -4127,9 +4127,9 @@ UdpMisc::ClockStamp UdpMisc::Clock()
|
||||
#endif
|
||||
}
|
||||
|
||||
int UdpMisc::SyncStampShortDeltaTime(ushort stamp1, ushort stamp2)
|
||||
int UdpMisc::SyncStampShortDeltaTime(uint16_t stamp1, uint16_t stamp2)
|
||||
{
|
||||
ushort delta = (ushort)(stamp1 - stamp2);
|
||||
uint16_t delta = (uint16_t)(stamp1 - stamp2);
|
||||
if (delta > 0x7fff)
|
||||
return((int)(0xffff - delta));
|
||||
return((int)delta);
|
||||
|
||||
+27
-25
@@ -1,6 +1,8 @@
|
||||
#ifndef UDPLIBRARY_HPP
|
||||
#define UDPLIBRARY_HPP
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include "UdpHandler.hpp"
|
||||
#include "Base/priority.hpp"
|
||||
@@ -130,7 +132,7 @@ class UdpMisc
|
||||
static int Random(int *seed); // random number generator
|
||||
static void Sleep(int milliseconds);
|
||||
|
||||
static ushort LocalSyncStampShort(); // gets a local-clock based sync-stamp. (only good for timings up to 32 seconds)
|
||||
static uint16_t LocalSyncStampShort(); // gets a local-clock based sync-stamp. (only good for timings up to 32 seconds)
|
||||
static uint LocalSyncStampLong(); // gets a local-clock based sync-stamp. (good for timings up to 23 days)
|
||||
|
||||
// returns the time difference between two sync-stamps that are based on the same clock
|
||||
@@ -139,7 +141,7 @@ class UdpMisc
|
||||
// you a sync-stamp that you can compare with ServerSyncStampShort values generated on other
|
||||
// machines that are synchronized against the same server. This ServerSyncStampShort function and
|
||||
// this delta time function serve as the basis for calculating one-way travel times for packets.
|
||||
static int SyncStampShortDeltaTime(ushort stamp1, ushort stamp2);
|
||||
static int SyncStampShortDeltaTime(uint16_t stamp1, uint16_t stamp2);
|
||||
static int SyncStampLongDeltaTime(uint stamp1, uint stamp2); // same as Short version only no limit
|
||||
|
||||
// used to alloc/resize/free an allocation previously created with this function
|
||||
@@ -163,12 +165,12 @@ class UdpMisc
|
||||
static int PutValue64(void *buffer, udp_int64 value); // puts a 64-bit value into the buffer in big-endian format, returns number of bytes used(8)
|
||||
static int PutValue32(void *buffer, uint value); // puts a 32-bit value into the buffer in big-endian format, returns number of bytes used(4)
|
||||
static int PutValue24(void *buffer, uint value); // puts a 24-bit value into the buffer in big-endian format, returns number of bytes used(4)
|
||||
static int PutValue16(void *buffer, ushort value); // puts a 16-bit value into the buffer in big-endian format, returns number of bytes used(2)
|
||||
static int PutValue16(void *buffer, uint16_t value); // puts a 16-bit value into the buffer in big-endian format, returns number of bytes used(2)
|
||||
|
||||
static udp_int64 GetValue64(const void *buffer); // gets a 64-bit value from the buffer in big-endian format
|
||||
static uint GetValue32(const void *buffer); // gets a 32-bit value from the buffer in big-endian format
|
||||
static uint GetValue24(const void *buffer); // gets a 24-bit value from the buffer in big-endian format
|
||||
static ushort GetValue16(const void *buffer); // gets a 16-bit value from the buffer in big-endian format
|
||||
static uint16_t GetValue16(const void *buffer); // gets a 16-bit value from the buffer in big-endian format
|
||||
|
||||
static LogicalPacket *CreateQuickLogicalPacket(const void *data, int dataLen, const void *data2 = nullptr, int dataLen2 = 0);
|
||||
|
||||
@@ -535,7 +537,7 @@ class UdpManager
|
||||
// to be kept alive, or at least kept alive very often (like for a chat server perhaps where nobody is talking much).
|
||||
// For some people, it may be necessary to send data more frequently in order to keep their NAT mapping fresh, or their
|
||||
// firewall software happy. However, we don't want to be in a situation where our server is receiving a lot more data
|
||||
// than it needs to just so these people can keep their port open. I have seen NAT's that lose mappings in as short
|
||||
// than it needs to just so these people can keep their port open. I have seen NAT's that lose mappings in as int16_t
|
||||
// as 20 seconds. What this feature does is a bit tricky. It changes the time-to-live (TTL) for a special keep-alive
|
||||
// packet to some small value (4) which is enough for the packet to get past firewalls and NAT's, but not make it all
|
||||
// the way to our server. In this manner, the port gets kept alive, but we don't waste bandwidth with these packets.
|
||||
@@ -583,7 +585,7 @@ class UdpManager
|
||||
// them and terminate the connection. When a packet is successfully received into the connection in question, the
|
||||
// retry period is reset, such that the next time an ICMP error comes in, it has another period of time for it
|
||||
// to resolve the issue. This servers a couple purpose, 1) it can allow for momentary outages that can be recovered
|
||||
// from in short order, and 2) it is necessary for the port-remapping feature to work properly in situations where
|
||||
// from in int16_t order, and 2) it is necessary for the port-remapping feature to work properly in situations where
|
||||
// the server may send data to the old-port before the remapping negotiations are completed. In order for the
|
||||
// remapping feature to work properly, this value should be set to larger than the longest time a connection typically
|
||||
// goes without receiving data from the other side. (0=no grace period)
|
||||
@@ -1189,9 +1191,9 @@ class UdpConnection : public PriorityQueueMember, public AddressHashTableMember,
|
||||
// packet travel times under 32 seconds, would should be completely safe. You must use the
|
||||
// UdpManager::SyncStampDeltaTime function in order to calculate the elapsed time between
|
||||
// the two stamps.
|
||||
ushort ServerSyncStampShort() const;
|
||||
uint16_t ServerSyncStampShort() const;
|
||||
uint ServerSyncStampLong() const;
|
||||
int ServerSyncStampShortElapsed(ushort syncStamp) const;
|
||||
int ServerSyncStampShortElapsed(uint16_t syncStamp) const;
|
||||
int ServerSyncStampLongElapsed(uint syncStamp) const;
|
||||
|
||||
// returns the IP address/port this connection is linked to
|
||||
@@ -1355,8 +1357,8 @@ class UdpConnection : public PriorityQueueMember, public AddressHashTableMember,
|
||||
|
||||
int mOrderedCountOutgoing;
|
||||
int mOrderedCountOutgoing2;
|
||||
ushort mOrderedStampLast;
|
||||
ushort mOrderedStampLast2;
|
||||
uint16_t mOrderedStampLast;
|
||||
uint16_t mOrderedStampLast2;
|
||||
|
||||
typedef int (UdpConnection::* IEncryptFunction)(uchar *destData, const uchar *sourceData, int sourceLen);
|
||||
typedef int (UdpConnection::* IDecryptFunction)(uchar *destData, const uchar *sourceData, int sourceLen);
|
||||
@@ -1461,7 +1463,7 @@ class UdpConnection : public PriorityQueueMember, public AddressHashTableMember,
|
||||
{
|
||||
uchar zeroByte;
|
||||
uchar packetType;
|
||||
ushort timeStamp;
|
||||
uint16_t timeStamp;
|
||||
int masterPingTime;
|
||||
int averagePingTime;
|
||||
int lowPingTime;
|
||||
@@ -1475,7 +1477,7 @@ class UdpConnection : public PriorityQueueMember, public AddressHashTableMember,
|
||||
{
|
||||
uchar zeroByte;
|
||||
uchar packetType;
|
||||
ushort timeStamp;
|
||||
uint16_t timeStamp;
|
||||
uint serverSyncStampLong;
|
||||
udp_int64 yourSent;
|
||||
udp_int64 yourReceived;
|
||||
@@ -1487,7 +1489,7 @@ class UdpConnection : public PriorityQueueMember, public AddressHashTableMember,
|
||||
{
|
||||
uchar zeroByte;
|
||||
uchar packetType;
|
||||
ushort reliableStamp;
|
||||
uint16_t reliableStamp;
|
||||
};
|
||||
|
||||
struct UdpPacketReliableFragmentStart
|
||||
@@ -1500,14 +1502,14 @@ class UdpConnection : public PriorityQueueMember, public AddressHashTableMember,
|
||||
{
|
||||
uchar zeroByte;
|
||||
uchar packetType;
|
||||
ushort reliableStamp;
|
||||
uint16_t reliableStamp;
|
||||
};
|
||||
|
||||
struct UdpPacketOrdered
|
||||
{
|
||||
uchar zeroByte;
|
||||
uchar packetType;
|
||||
ushort orderStamp;
|
||||
uint16_t orderStamp;
|
||||
};
|
||||
|
||||
|
||||
@@ -1702,9 +1704,9 @@ inline int UdpMisc::ClockDiff(ClockStamp start, ClockStamp stop)
|
||||
return((int)t);
|
||||
}
|
||||
|
||||
inline ushort UdpMisc::LocalSyncStampShort()
|
||||
inline uint16_t UdpMisc::LocalSyncStampShort()
|
||||
{
|
||||
return((ushort)(Clock() & 0xffff));
|
||||
return((uint16_t)(Clock() & 0xffff));
|
||||
}
|
||||
|
||||
inline uint UdpMisc::LocalSyncStampLong()
|
||||
@@ -1764,7 +1766,7 @@ inline uint UdpMisc::GetValue24(const void *buffer)
|
||||
return((*bufptr << 16) | (*(bufptr + 1) << 8) | *(bufptr + 2));
|
||||
}
|
||||
|
||||
inline int UdpMisc::PutValue16(void *buffer, ushort value)
|
||||
inline int UdpMisc::PutValue16(void *buffer, uint16_t value)
|
||||
{
|
||||
uchar *bufptr = (uchar *)buffer;
|
||||
*bufptr++ = (uchar)((value >> 8) & 0xff);
|
||||
@@ -1772,10 +1774,10 @@ inline int UdpMisc::PutValue16(void *buffer, ushort value)
|
||||
return(2);
|
||||
}
|
||||
|
||||
inline ushort UdpMisc::GetValue16(const void *buffer)
|
||||
inline uint16_t UdpMisc::GetValue16(const void *buffer)
|
||||
{
|
||||
const uchar *bufptr = (const uchar *)buffer;
|
||||
return((ushort)((*bufptr << 8) | *(bufptr + 1)));
|
||||
return((uint16_t)((*bufptr << 8) | *(bufptr + 1)));
|
||||
}
|
||||
|
||||
// UdpManager
|
||||
@@ -1874,7 +1876,7 @@ inline void UdpConnection::ScheduleTimeNow()
|
||||
{
|
||||
// if we are current in our GiveTime function getting time, then there is no need to reprioritize to 0 when we send a raw packet, since
|
||||
// the last thing we do in out GiveTime is do a scheduling calculation based on the last time a packet was sent. This little check
|
||||
// prevents us from reprioritizing to 0, only to shortly thereafter be reprioritized to where we actually belong.
|
||||
// prevents us from reprioritizing to 0, only to int16_tly thereafter be reprioritized to where we actually belong.
|
||||
if (!mGettingTime)
|
||||
{
|
||||
if (mUdpManager != nullptr)
|
||||
@@ -1950,9 +1952,9 @@ inline int UdpConnection::LastSend() const
|
||||
return(UdpMisc::ClockElapsed(mLastSendTime));
|
||||
}
|
||||
|
||||
inline ushort UdpConnection::ServerSyncStampShort() const
|
||||
inline uint16_t UdpConnection::ServerSyncStampShort() const
|
||||
{
|
||||
return((ushort)(UdpMisc::LocalSyncStampShort() + (mSyncTimeDelta & 0xffff)));
|
||||
return((uint16_t)(UdpMisc::LocalSyncStampShort() + (mSyncTimeDelta & 0xffff)));
|
||||
}
|
||||
|
||||
inline uint UdpConnection::ServerSyncStampLong() const
|
||||
@@ -1960,7 +1962,7 @@ inline uint UdpConnection::ServerSyncStampLong() const
|
||||
return(UdpMisc::LocalSyncStampLong() + mSyncTimeDelta);
|
||||
}
|
||||
|
||||
inline int UdpConnection::ServerSyncStampShortElapsed(ushort syncStamp) const
|
||||
inline int UdpConnection::ServerSyncStampShortElapsed(uint16_t syncStamp) const
|
||||
{
|
||||
return(UdpMisc::SyncStampShortDeltaTime(syncStamp, ServerSyncStampShort()));
|
||||
}
|
||||
@@ -2051,7 +2053,7 @@ inline int UdpConnection::GetKeepAliveDelay() const
|
||||
// UdpReliableChannel
|
||||
inline void UdpReliableChannel::AckPacket(const uchar *data, int /*dataLen*/)
|
||||
{
|
||||
Ack(GetReliableOutgoingId((ushort)UdpMisc::GetValue16(data + 2)));
|
||||
Ack(GetReliableOutgoingId((uint16_t)UdpMisc::GetValue16(data + 2)));
|
||||
}
|
||||
|
||||
inline int UdpReliableChannel::GetAveragePing() const
|
||||
|
||||
Reference in New Issue
Block a user