Merge pull request #111 from birarda/avatar-from-mixer

return int of bytes read from parseData, removing AvatarData const, fix socketMatch NULL socket crash
This commit is contained in:
ZappoMan 2013-04-22 18:07:32 -07:00
commit 19e7e73b5d
11 changed files with 47 additions and 37 deletions

View file

@ -114,7 +114,7 @@ float VoxelSystem::getVoxelsBytesReadPerSecondAverage() {
}
void VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) {
int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) {
unsigned char command = *sourceBuffer;
unsigned char *voxelData = sourceBuffer + 1;
@ -154,6 +154,7 @@ void VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) {
}
setupNewVoxelsForDrawing();
return numBytes;
}
void VoxelSystem::setupNewVoxelsForDrawing() {

View file

@ -26,7 +26,7 @@ public:
VoxelSystem();
~VoxelSystem();
void parseData(unsigned char* sourceBuffer, int numBytes);
int parseData(unsigned char* sourceBuffer, int numBytes);
VoxelSystem* clone() const;
void init();

View file

@ -1456,8 +1456,7 @@ void *networkReceive(void *args)
case PACKET_HEADER_BULK_AVATAR_DATA:
AgentList::getInstance()->processBulkAgentData(&senderAddress,
incomingPacket,
bytesReceived,
BYTES_PER_AVATAR);
bytesReceived);
break;
default:
AgentList::getInstance()->processAgentData(&senderAddress, incomingPacket, bytesReceived);

View file

@ -95,7 +95,9 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) {
}
// called on the other agents - assigns it to my views of the others
void AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
unsigned char* startPosition = sourceBuffer;
// increment to push past the packet header
sourceBuffer++;
@ -126,6 +128,8 @@ void AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
sourceBuffer += sizeof(_cameraNearClip);
memcpy(&_cameraFarClip, sourceBuffer, sizeof(_cameraFarClip));
sourceBuffer += sizeof(_cameraFarClip);
return sourceBuffer - startPosition;
}
glm::vec3 AvatarData::getBodyPosition() {

View file

@ -13,8 +13,6 @@
#include <AgentData.h>
const int BYTES_PER_AVATAR = 94;
class AvatarData : public AgentData {
public:
AvatarData();
@ -27,7 +25,7 @@ public:
void setHandPosition(glm::vec3 handPosition);
int getBroadcastData(unsigned char* destinationBuffer);
void parseData(unsigned char* sourceBuffer, int numBytes);
int parseData(unsigned char* sourceBuffer, int numBytes);
float getBodyYaw();
void setBodyYaw(float bodyYaw);

View file

@ -12,7 +12,7 @@
class AgentData {
public:
virtual ~AgentData() = 0;
virtual void parseData(unsigned char* sourceBuffer, int numBytes) = 0;
virtual int parseData(unsigned char* sourceBuffer, int numBytes) = 0;
virtual AgentData* clone() const = 0;
};

View file

@ -106,7 +106,7 @@ void AgentList::processAgentData(sockaddr *senderAddress, unsigned char *packetD
}
}
void AgentList::processBulkAgentData(sockaddr *senderAddress, unsigned char *packetData, int numTotalBytes, int numBytesPerAgent) {
void AgentList::processBulkAgentData(sockaddr *senderAddress, unsigned char *packetData, int numTotalBytes) {
// find the avatar mixer in our agent list and update the lastRecvTime from it
int bulkSendAgentIndex = indexOfMatchingAgent(senderAddress);
@ -118,7 +118,7 @@ void AgentList::processBulkAgentData(sockaddr *senderAddress, unsigned char *pac
unsigned char *startPosition = packetData;
unsigned char *currentPosition = startPosition + 1;
unsigned char packetHolder[numBytesPerAgent + 1];
unsigned char packetHolder[numTotalBytes];
packetHolder[0] = PACKET_HEADER_HEAD_DATA;
@ -126,7 +126,7 @@ void AgentList::processBulkAgentData(sockaddr *senderAddress, unsigned char *pac
while ((currentPosition - startPosition) < numTotalBytes) {
currentPosition += unpackAgentId(currentPosition, &agentID);
memcpy(packetHolder + 1, currentPosition, numBytesPerAgent);
memcpy(packetHolder + 1, currentPosition, numTotalBytes - (currentPosition - startPosition));
int matchingAgentIndex = indexOfMatchingAgent(agentID);
@ -138,22 +138,24 @@ void AgentList::processBulkAgentData(sockaddr *senderAddress, unsigned char *pac
matchingAgentIndex = indexOfMatchingAgent(agentID);
}
updateAgentWithData(&agents[matchingAgentIndex], packetHolder, numBytesPerAgent + 1);
currentPosition += numBytesPerAgent;
currentPosition += updateAgentWithData(&agents[matchingAgentIndex],
packetHolder,
numTotalBytes - (currentPosition - startPosition));
}
}
void AgentList::updateAgentWithData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes) {
int AgentList::updateAgentWithData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes) {
// find the agent by the sockaddr
int agentIndex = indexOfMatchingAgent(senderAddress);
if (agentIndex != -1) {
updateAgentWithData(&agents[agentIndex], packetData, dataBytes);
return updateAgentWithData(&agents[agentIndex], packetData, dataBytes);
} else {
return 0;
}
}
void AgentList::updateAgentWithData(Agent *agent, unsigned char *packetData, int dataBytes) {
int AgentList::updateAgentWithData(Agent *agent, unsigned char *packetData, int dataBytes) {
agent->setLastRecvTimeUsecs(usecTimestampNow());
agent->recordBytesReceived(dataBytes);
@ -163,7 +165,7 @@ void AgentList::updateAgentWithData(Agent *agent, unsigned char *packetData, int
}
}
agent->getLinkedData()->parseData(packetData, dataBytes);
return agent->getLinkedData()->parseData(packetData, dataBytes);
}
int AgentList::indexOfMatchingAgent(sockaddr *senderAddress) {

View file

@ -50,10 +50,10 @@ public:
bool addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket, char agentType, uint16_t agentId);
void processAgentData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes);
void processBulkAgentData(sockaddr *senderAddress, unsigned char *packetData, int numTotalBytes, int numBytesPerAgent);
void processBulkAgentData(sockaddr *senderAddress, unsigned char *packetData, int numTotalBytes);
void updateAgentWithData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes);
void updateAgentWithData(Agent *agent, unsigned char *packetData, int dataBytes);
int updateAgentWithData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes);
int updateAgentWithData(Agent *agent, unsigned char *packetData, int dataBytes);
void broadcastToAgents(unsigned char *broadcastData, size_t dataBytes, const char* agentTypes, int numAgentTypes);
char getOwnerType();

View file

@ -105,7 +105,7 @@ void AudioRingBuffer::setBearing(float newBearing) {
bearing = newBearing;
}
void AudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) {
int AudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) {
if (numBytes > (bufferLengthSamples * sizeof(int16_t))) {
unsigned char *dataPtr = sourceBuffer + 1;
@ -140,7 +140,9 @@ void AudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) {
if (endOfLastWrite >= buffer + ringBufferLengthSamples) {
endOfLastWrite = buffer;
}
}
return numBytes;
}
short AudioRingBuffer::diffLastWriteNextOutput()

View file

@ -18,7 +18,7 @@ class AudioRingBuffer : public AgentData {
~AudioRingBuffer();
AudioRingBuffer(const AudioRingBuffer &otherRingBuffer);
void parseData(unsigned char* sourceBuffer, int numBytes);
int parseData(unsigned char* sourceBuffer, int numBytes);
AudioRingBuffer* clone() const;
int16_t* getNextOutput();

View file

@ -28,20 +28,24 @@ using shared_lib::printLog;
sockaddr_in destSockaddr, senderAddress;
bool socketMatch(sockaddr *first, sockaddr *second) {
// utility function that indicates if two sockets are equivalent
// currently only compares two IPv4 addresses
// expandable to IPv6 by adding else if for AF_INET6
if (first->sa_family != second->sa_family) {
// not the same family, can't be equal
return false;
} else if (first->sa_family == AF_INET) {
sockaddr_in *firstIn = (sockaddr_in *) first;
sockaddr_in *secondIn = (sockaddr_in *) second;
if (first != NULL && second != NULL) {
// utility function that indicates if two sockets are equivalent
return firstIn->sin_addr.s_addr == secondIn->sin_addr.s_addr
// currently only compares two IPv4 addresses
// expandable to IPv6 by adding else if for AF_INET6
if (first->sa_family != second->sa_family) {
// not the same family, can't be equal
return false;
} else if (first->sa_family == AF_INET) {
sockaddr_in *firstIn = (sockaddr_in *) first;
sockaddr_in *secondIn = (sockaddr_in *) second;
return firstIn->sin_addr.s_addr == secondIn->sin_addr.s_addr
&& firstIn->sin_port == secondIn->sin_port;
} else {
return false;
}
} else {
return false;
}