add a workaround to avoid the using of the missing select function

This commit is contained in:
Stefan Lankes 2011-10-19 04:47:19 -07:00
parent bdb0a895f2
commit 62f2038a6e

View file

@ -30,6 +30,8 @@
#include <asm/SCC_API.h>
#endif
#define USE_SOCKET_BYPASSING 1
/*
* This implements a netio server and client (only TCP version).
* The client sends a command word (4 bytes) then a data length word (4 bytes).
@ -45,8 +47,20 @@
/* See http://www.nwlab.net/art/netio/netio.html to get the netio tool */
#ifdef CONFIG_LWIP
#if USE_SOCKET_BYPASSING // for socket bypassing
#include <lwip/opt.h>
#undef LWIP_COMPAT_SOCKETS
#endif
#include <lwip/sockets.h>
#include <lwip/err.h>
#include <lwip/stats.h>
#if USE_SOCKET_BYPASSING // for socket bypassing
#include <net/mmnif.h>
#undef AF_INET
#define AF_INET AF_MMNIF_NET
#endif
typedef struct
{
@ -60,10 +74,10 @@ typedef struct
#define CMD_RES 3
#define CTLSIZE sizeof(CONTROL)
#define DEFAULTPORT 0x494F /* "IO" */
#define DEFAULTPORT 0x494F
#define TMAXSIZE 65536
static int tSizes[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32767};
static int tSizes[] = {/*1, 2, 4, 8, 16, */32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32767};
static size_t ntSizes = sizeof(tSizes) / sizeof(int);
static int nPort = DEFAULTPORT;
static const int sobufsize = 131072;
@ -153,6 +167,7 @@ static int TCPServer(void* arg)
setsockopt(server, SOL_SOCKET, SO_RCVBUF, (char *) &sobufsize, sizeof(sobufsize));
setsockopt(server, SOL_SOCKET, SO_SNDBUF, (char *) &sobufsize, sizeof(sobufsize));
memset((char *) &sa_server, 0x00, sizeof(sa_server));
sa_server.sin_family = AF_INET;
sa_server.sin_port = htons(nPort);
sa_server.sin_addr = addr_local;
@ -177,6 +192,7 @@ static int TCPServer(void* arg)
{
kprintf("TCP server listening.\n");
#ifdef select
FD_ZERO(&fds);
FD_SET(server, &fds);
tv.tv_sec = 3600;
@ -190,10 +206,16 @@ static int TCPServer(void* arg)
if (rc == 0 || FD_ISSET(server, &fds) == 0)
continue;
#endif
length = sizeof(sa_client);
if ((client = accept(server, (struct sockaddr *) &sa_client, &length)) == -1)
#if USE_SOCKET_BYPASSING
// TODO: Bug, not compatible with BSD sockets
memcpy(&sa_client, &sa_server, length);
#endif
if ((client = accept(server, (struct sockaddr *) &sa_client, &length)) < 0) {
kprintf("accept faild: %d\n", errno);
continue;
}
setsockopt(client, SOL_SOCKET, SO_RCVBUF, (char *) &sobufsize, sizeof(sobufsize));
setsockopt(client, SOL_SOCKET, SO_SNDBUF, (char *) &sobufsize, sizeof(sobufsize));
@ -215,7 +237,7 @@ static int TCPServer(void* arg)
kprintf("\nReceiving from client, packet size %s ... \n", PacketSize(ctl.data));
cBuffer[0] = 0;
nData = 0;
do {
for (nByte = 0; nByte < ctl.data; )
{