More network stuff.

This commit is contained in:
simon.kagstrom 2010-02-15 19:24:52 +00:00
parent a9fffcce87
commit 5895e06a29

View File

@ -567,10 +567,12 @@ bool Network::ReceiveUpdate(NetworkUpdate *dst, size_t total_sz,
if (sz_left <= 0) if (sz_left <= 0)
return false; return false;
printf("Have something\n");
/* Receive the header */ /* Receive the header */
do { do {
ssize_t actual_sz = this->ReceiveFrom(p, this->sock, ssize_t actual_sz = this->ReceiveFrom(p, this->sock,
4096, NULL); 4096, NULL);
printf("AS: %d\n", actual_sz);
if (actual_sz <= 0) if (actual_sz <= 0)
return false; return false;
@ -902,6 +904,7 @@ bool Network::DecodeUpdate(C64Display *display, uint8 *js, MOS6581 *dst)
while (p->type != STOP) while (p->type != STOP)
{ {
printf("decoding %d\n", p->type);
switch(p->type) switch(p->type)
{ {
case SOUND_UPDATE: case SOUND_UPDATE:
@ -995,6 +998,8 @@ bool Network::AppendScreenshot(NetworkUpdatePeerInfo *pi)
png = sdl_surface_to_png(scr, &sz); png = sdl_surface_to_png(scr, &sz);
if (!png) if (!png)
goto out_scr; goto out_scr;
if ((sz & 3) != 0)
sz += 4 - (sz & 3);
ud = InitNetworkUpdate(this->cur_ud, REGISTER_DATA, ud = InitNetworkUpdate(this->cur_ud, REGISTER_DATA,
sizeof(NetworkUpdate) + sizeof(NetworkUpdateRegisterData) + sz); sizeof(NetworkUpdate) + sizeof(NetworkUpdateRegisterData) + sz);
@ -1116,6 +1121,14 @@ network_connection_error_t Network::WaitForPeerList()
this->ResetNetworkUpdate(); this->ResetNetworkUpdate();
return AGAIN_ERROR; return AGAIN_ERROR;
} }
if (this->ud->type == REGISTER_DATA)
{
NetworkUpdateRegisterData *rd = (NetworkUpdateRegisterData *)this->ud->data;
DataStore::ds->registerNetworkData(rd->key, rd->metadata, rd->data,
this->ud->size - (sizeof(NetworkUpdateRegisterData) + sizeof(NetworkUpdate)));
return AGAIN_ERROR;
}
if (ud->type != LIST_PEERS) if (ud->type != LIST_PEERS)
return SERVER_GARBAGE_ERROR; return SERVER_GARBAGE_ERROR;
@ -1296,7 +1309,7 @@ network_connection_error_t Network::ConnectFSM()
this->network_connection_state = CONN_WAIT_FOR_PEER_ADDRESS; this->network_connection_state = CONN_WAIT_FOR_PEER_ADDRESS;
this->is_master = true; this->is_master = true;
} }
else else if (err == OK)
this->network_connection_state = CONN_WAIT_FOR_PEER_SELECT; this->network_connection_state = CONN_WAIT_FOR_PEER_SELECT;
break; break;
case CONN_WAIT_FOR_PEER_SELECT: case CONN_WAIT_FOR_PEER_SELECT: