Network cleanup (merge some stuff into the wii part)

This commit is contained in:
simon.kagstrom 2009-03-01 14:41:18 +00:00
parent a81356aee7
commit ae2a0a2fb2
2 changed files with 1 additions and 89 deletions

View File

@ -83,84 +83,6 @@ bool Network::InitSocket(const char *remote_host, int port)
return true;
}
#if 0
bool Network::StartNetworkServer(int port)
{
Network::listen_sock = make_socket(port);
if (Network::listen_sock < 0)
return false;
return true;
}
bool Network::CheckNewConnection()
{
struct timeval tv;
struct sockaddr_in peer_addr;
fd_set listen_fds;
/* Not initialized yet */
if (Network::listen_sock <= 0)
return false;
/* Only one peer allowed */
if (Network::n_peers > 0)
return false;
FD_ZERO(&listen_fds);
FD_SET(Network::listen_sock, &listen_fds);
/* If something connects, create a new client */
memset(&tv, 0, sizeof(tv));
int v = select(Network::listen_sock + 1, &listen_fds, NULL, NULL, &tv);
if ( v < 0)
{
perror("select");
exit(1);
}
else if ( v == 0 )
return false;
/* The name, please (but drop the packet after this. FIX this...) */
char tmp[1];
socklen_t from_sz = sizeof(struct sockaddr_in);
recvfrom(Network::listen_sock, tmp, 1, 0,
(struct sockaddr*)&peer_addr, &from_sz);
/* And add the new one (the connection data will be read by
* the network object) */
Network::AddPeer(new Network(Network::listen_sock, &peer_addr, true));
return true;
}
bool Network::ConnectTo(const char *hostname, int port)
{
/* Again from glibc docs */
struct sockaddr_in server_addr;
int sock;
/* Create the socket. */
sock = socket (PF_INET, SOCK_DGRAM, 0);
if (sock < 0)
{
perror ("socket (client)");
return false;
}
set_sock_opts(sock);
/* Connect to the server. */
init_sockaddr (&server_addr, hostname, port);
Network::AddPeer( new Network(sock, &server_addr, false) );
return true;
}
#endif
bool Network::ReceiveData(void *dst, int sock, size_t sz)
{
size_t received_sz = 0;

View File

@ -79,16 +79,6 @@ bool Network::InitSocket(const char *remote_host, int port)
/* Connect to the server. */
this->InitSockaddr(&this->connection_addr, remote_host, port);
if (this->is_master)
{
if (net_bind(this->sock, (struct sockaddr *)&this->connection_addr,
sizeof (this->connection_addr)) < 0)
{
perror ("bind");
return false;
}
}
return true;
}
@ -128,7 +118,7 @@ ssize_t Network::SendTo(void *src, int sock, size_t sz, struct sockaddr_in *to)
bool Network::SendData(void *src, int sock, size_t sz)
{
size_t sent_sz = 0;
while (sent_sz < sz)
{
int v = net_write(sock, (void*)src, sz);