mirror of
https://github.com/Oibaf66/frodo-wii.git
synced 2024-11-26 05:24:21 +01:00
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:
parent
0becbb20e4
commit
0916f0025d
@ -510,28 +510,29 @@ bool Network::ReceiveUpdate(struct timeval *tv)
|
||||
bool Network::ReceiveUpdate(NetworkUpdate *dst, size_t total_sz,
|
||||
struct timeval *tv)
|
||||
{
|
||||
Uint8 *pp = (Uint8*)dst;
|
||||
NetworkUpdate *p;
|
||||
Uint8 *p = (Uint8*)dst;
|
||||
size_t sz_left = total_sz;
|
||||
bool has_stop = false;
|
||||
|
||||
if (this->Select(this->sock, tv) == false)
|
||||
return false;
|
||||
p = (NetworkUpdate*)pp;
|
||||
size_t actual_sz;
|
||||
|
||||
if (sz_left <= 0)
|
||||
return false;
|
||||
|
||||
/* Receive the header */
|
||||
actual_sz = this->ReceiveFrom(pp, this->sock,
|
||||
sz_left, NULL);
|
||||
if (actual_sz < 0)
|
||||
return false;
|
||||
do {
|
||||
size_t actual_sz = this->ReceiveFrom(p, this->sock,
|
||||
4096, NULL);
|
||||
if (actual_sz < 0)
|
||||
return false;
|
||||
|
||||
if (this->DeMarshalAllData(p) == false)
|
||||
return false;
|
||||
sz_left -= actual_sz;
|
||||
pp = pp + actual_sz;
|
||||
if (this->DeMarshalAllData((NetworkUpdate*)p, actual_sz,
|
||||
&has_stop) == false)
|
||||
return false;
|
||||
sz_left -= actual_sz;
|
||||
p = p + actual_sz;
|
||||
} while (!has_stop);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -555,14 +556,50 @@ bool Network::SendUpdate()
|
||||
sz = this->GetNetworkUpdateSize();
|
||||
if (sz <= 0)
|
||||
return false;
|
||||
if (this->SendTo((void*)src, this->sock,
|
||||
sz, &this->connection_addr) < 0)
|
||||
return false;
|
||||
this->traffic += sz;
|
||||
size_t cur_sz = 0;
|
||||
Uint8 *p = (Uint8*)src;
|
||||
do
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
Uint8 *next = (Uint8*)this->cur_ud + update->size;
|
||||
@ -691,18 +728,25 @@ bool Network::DeMarshalData(NetworkUpdate *p)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Network::DeMarshalAllData(NetworkUpdate *ud)
|
||||
bool Network::DeMarshalAllData(NetworkUpdate *ud, size_t max_size,
|
||||
bool *has_stop)
|
||||
{
|
||||
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)
|
||||
return false;
|
||||
sz += p->size;
|
||||
cnt++;
|
||||
p = this->GetNext(p);
|
||||
}
|
||||
|
||||
/* The stop tag */
|
||||
/* The stop tag (maybe) */
|
||||
*has_stop = (ntohs(p->type) == STOP);
|
||||
return this->DeMarshalData(p);
|
||||
}
|
||||
|
||||
|
@ -276,7 +276,8 @@ protected:
|
||||
|
||||
bool MarshalAllData(NetworkUpdate *p);
|
||||
|
||||
bool DeMarshalAllData(NetworkUpdate *ud);
|
||||
bool DeMarshalAllData(NetworkUpdate *ud, size_t max_size,
|
||||
bool *has_stop);
|
||||
|
||||
bool DeMarshalData(NetworkUpdate *ud);
|
||||
|
||||
@ -294,6 +295,8 @@ protected:
|
||||
|
||||
bool ConnectFSM();
|
||||
|
||||
size_t FillNetworkBuffer(NetworkUpdate *p);
|
||||
|
||||
NetworkUpdate *GetNext(NetworkUpdate *p)
|
||||
{
|
||||
return (NetworkUpdate*)((Uint8*)p + p->size);
|
||||
|
@ -45,7 +45,7 @@ bool Network::InitSocket(const char *remote_host, int port)
|
||||
if (this->sock < 0)
|
||||
{
|
||||
fprintf (stderr, "Could not init socket. Failed with %d\n", this->sock);
|
||||
sleep(1);
|
||||
sleep(5);
|
||||
return false;
|
||||
}
|
||||
int _true = false;
|
||||
@ -132,15 +132,5 @@ void Network::CloseSocket()
|
||||
|
||||
void Network::InitNetwork()
|
||||
{
|
||||
char myIP[16];
|
||||
|
||||
/* 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);
|
||||
}
|
||||
fprintf(stderr, "\n\n");
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <SDL.h>
|
||||
#include <fat.h>
|
||||
#include <wiiuse/wpad.h>
|
||||
#include <network.h>
|
||||
|
||||
#include "menu.h"
|
||||
|
||||
@ -24,11 +25,22 @@ int fixme_tmp_network_server = 0;
|
||||
extern "C" int main(int argc, char **argv)
|
||||
{
|
||||
Frodo *the_app;
|
||||
char myIP[16];
|
||||
|
||||
timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
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);
|
||||
if (!init_graphics())
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user