Send at most 4096 bytes so that wii networking *can* work. The Wii can now

connect at least, but the connection (through the broker) still doesn't
work. Well, well, might be some other problem.
This commit is contained in:
simon.kagstrom 2009-03-16 20:56:04 +00:00
parent 0becbb20e4
commit 0916f0025d
4 changed files with 81 additions and 32 deletions

View File

@ -510,28 +510,29 @@ bool Network::ReceiveUpdate(struct timeval *tv)
bool Network::ReceiveUpdate(NetworkUpdate *dst, size_t total_sz, bool Network::ReceiveUpdate(NetworkUpdate *dst, size_t total_sz,
struct timeval *tv) struct timeval *tv)
{ {
Uint8 *pp = (Uint8*)dst; Uint8 *p = (Uint8*)dst;
NetworkUpdate *p;
size_t sz_left = total_sz; size_t sz_left = total_sz;
bool has_stop = false;
if (this->Select(this->sock, tv) == false) if (this->Select(this->sock, tv) == false)
return false; return false;
p = (NetworkUpdate*)pp;
size_t actual_sz;
if (sz_left <= 0) if (sz_left <= 0)
return false; return false;
/* Receive the header */ /* Receive the header */
actual_sz = this->ReceiveFrom(pp, this->sock, do {
sz_left, NULL); size_t actual_sz = this->ReceiveFrom(p, this->sock,
if (actual_sz < 0) 4096, NULL);
return false; if (actual_sz < 0)
return false;
if (this->DeMarshalAllData(p) == false) if (this->DeMarshalAllData((NetworkUpdate*)p, actual_sz,
return false; &has_stop) == false)
sz_left -= actual_sz; return false;
pp = pp + actual_sz; sz_left -= actual_sz;
p = p + actual_sz;
} while (!has_stop);
return true; return true;
} }
@ -555,14 +556,50 @@ bool Network::SendUpdate()
sz = this->GetNetworkUpdateSize(); sz = this->GetNetworkUpdateSize();
if (sz <= 0) if (sz <= 0)
return false; return false;
if (this->SendTo((void*)src, this->sock, size_t cur_sz = 0;
sz, &this->connection_addr) < 0) Uint8 *p = (Uint8*)src;
return false; do
this->traffic += sz; {
size_t size_to_send = this->FillNetworkBuffer((NetworkUpdate*)p);
ssize_t v;
v = this->SendTo((void*)p, this->sock,
size_to_send, &this->connection_addr);
if (v < 0 || v != size_to_send)
return false;
cur_sz += size_to_send;
p += size_to_send;
} while (cur_sz < sz);
this->traffic += cur_sz;
return true; return true;
} }
size_t Network::FillNetworkBuffer(NetworkUpdate *cur)
{
size_t sz = 0;
size_t cur_sz;
int cnt = 0;
while(1)
{
cur_sz = ntohl(cur->size);
if (sz + cur_sz >= 4096)
break;
cnt++;
sz += cur_sz;
if (ntohs(cur->type) == STOP)
break;
cur = (NetworkUpdate*)((Uint8*)cur + cur_sz);
}
assert(sz <= 4096);
return sz;
}
void Network::AddNetworkUpdate(NetworkUpdate *update) void Network::AddNetworkUpdate(NetworkUpdate *update)
{ {
Uint8 *next = (Uint8*)this->cur_ud + update->size; Uint8 *next = (Uint8*)this->cur_ud + update->size;
@ -691,18 +728,25 @@ bool Network::DeMarshalData(NetworkUpdate *p)
return true; return true;
} }
bool Network::DeMarshalAllData(NetworkUpdate *ud) bool Network::DeMarshalAllData(NetworkUpdate *ud, size_t max_size,
bool *has_stop)
{ {
NetworkUpdate *p = ud; NetworkUpdate *p = ud;
int cnt = 0;
size_t sz = 0;
while (ntohs(p->type) != STOP) while (ntohs(p->type) != STOP &&
sz + ntohl(p->size) < max_size)
{ {
if (this->DeMarshalData(p) == false) if (this->DeMarshalData(p) == false)
return false; return false;
sz += p->size;
cnt++;
p = this->GetNext(p); p = this->GetNext(p);
} }
/* The stop tag */ /* The stop tag (maybe) */
*has_stop = (ntohs(p->type) == STOP);
return this->DeMarshalData(p); return this->DeMarshalData(p);
} }

View File

@ -276,7 +276,8 @@ protected:
bool MarshalAllData(NetworkUpdate *p); bool MarshalAllData(NetworkUpdate *p);
bool DeMarshalAllData(NetworkUpdate *ud); bool DeMarshalAllData(NetworkUpdate *ud, size_t max_size,
bool *has_stop);
bool DeMarshalData(NetworkUpdate *ud); bool DeMarshalData(NetworkUpdate *ud);
@ -294,6 +295,8 @@ protected:
bool ConnectFSM(); bool ConnectFSM();
size_t FillNetworkBuffer(NetworkUpdate *p);
NetworkUpdate *GetNext(NetworkUpdate *p) NetworkUpdate *GetNext(NetworkUpdate *p)
{ {
return (NetworkUpdate*)((Uint8*)p + p->size); return (NetworkUpdate*)((Uint8*)p + p->size);

View File

@ -45,7 +45,7 @@ bool Network::InitSocket(const char *remote_host, int port)
if (this->sock < 0) if (this->sock < 0)
{ {
fprintf (stderr, "Could not init socket. Failed with %d\n", this->sock); fprintf (stderr, "Could not init socket. Failed with %d\n", this->sock);
sleep(1); sleep(5);
return false; return false;
} }
int _true = false; int _true = false;
@ -132,15 +132,5 @@ void Network::CloseSocket()
void Network::InitNetwork() void Network::InitNetwork()
{ {
char myIP[16]; fprintf(stderr, "\n\n");
/* From Snes9x-gx */
while (net_init() == -EAGAIN);
if (if_config(myIP, NULL, NULL, true) < 0)
{
fprintf(stderr, "\n\n\nError getting IP address via DHCP.\n");
sleep(2);
exit(1);
}
} }

View File

@ -9,6 +9,7 @@
#include <SDL.h> #include <SDL.h>
#include <fat.h> #include <fat.h>
#include <wiiuse/wpad.h> #include <wiiuse/wpad.h>
#include <network.h>
#include "menu.h" #include "menu.h"
@ -24,11 +25,22 @@ int fixme_tmp_network_server = 0;
extern "C" int main(int argc, char **argv) extern "C" int main(int argc, char **argv)
{ {
Frodo *the_app; Frodo *the_app;
char myIP[16];
timeval tv; timeval tv;
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
srand(tv.tv_usec); srand(tv.tv_usec);
/* From Snes9x-gx */
while (net_init() == -EAGAIN);
if (if_config(myIP, NULL, NULL, true) < 0)
{
fprintf(stderr, "\n\n\nError getting IP address via DHCP.\n");
sleep(2);
exit(1);
}
printf("%s by Christian Bauer\n", VERSION_STRING); printf("%s by Christian Bauer\n", VERSION_STRING);
if (!init_graphics()) if (!init_graphics())
{ {