This commit is contained in:
root 2011-06-21 13:07:04 +02:00
parent a2a2c5064f
commit 16719bad00
2 changed files with 113 additions and 12 deletions

View file

@ -6,18 +6,18 @@ DRIVERDIRS = drivers/net drivers/char
KERNDIRS = libkern kernel mm fs arch/$(ARCH)/kernel arch/$(ARCH)/mm arch/$(ARCH)/scc $(LWIPDIRS) $(DRIVERDIRS)
SUBDIRS = $(KERNDIRS)
CC_FOR_TARGET=gcc
CXX_FOR_TARGET=g++
GCC_FOR_TARGET=gcc
AR_FOR_TARGET=ar
AS_FOR_TARGET=as
LD_FOR_TARGET=ld
NM_FOR_TARGET=nm
OBJDUMP_FOR_TARGET=objdump
OBJCOPY_FOR_TARGET=objcopy
RANLIB_FOR_TARGET=ranlib
STRIP_FOR_TARGET=strip
READELF_FOR_TARGET=readelf
CC_FOR_TARGET=i386-unknown-linux-gnu-gcc
CXX_FOR_TARGET=i386-unknown-linux-gnu-g++
GCC_FOR_TARGET=i386-unknown-linux-gnu-gcc
AR_FOR_TARGET=i386-unknown-linux-gnu-ar
AS_FOR_TARGET=i386-unknown-linux-gnu-as
LD_FOR_TARGET=i386-unknown-linux-gnu-ld
NM_FOR_TARGET=i386-unknown-linux-gnu-nm
OBJDUMP_FOR_TARGET=i386-unknown-linux-gnu-objdump
OBJCOPY_FOR_TARGET=i386-unknown-linux-gnu-objcopy
RANLIB_FOR_TARGET=i386-unknown-linux-gnu-ranlib
STRIP_FOR_TARGET=i386-unknown-linux-gnu-strip
READELF_FOR_TARGET=i386-unknown-linux-gnu-readelf
NASM = nasm
EMU=qemu
GDB=gdb

View file

@ -33,6 +33,7 @@
#include <asm/iRCCE_lib.h>
#include <asm/SCC_API.h>
#include <lwip/sockets.h>
#endif
static sem_t consuming, producing;
@ -145,12 +146,112 @@ __inline int get_core_no(void)
void* server_task(void* e)
{
int sockfd, newsockfd, portno, clilen;
char buffer[256];
struct sockaddr_in serv_addr, cli_addr;
int n;
/* First call to socket() function */
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
{
kprintf("ERROR opening socket");
return;
}
/* Initialize socket structure */
memset((char *) &serv_addr,0, sizeof(serv_addr));
portno = 5001;
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = INADDR_ANY;
serv_addr.sin_port = htons(portno);
/* Now bind the host address using bind() call.*/
if (bind(sockfd, (struct sockaddr *) &serv_addr,
sizeof(serv_addr)) < 0)
{
kprintf("ERROR on binding");
return;
}
/* Now start listening for the clients, here process will
* go in sleep mode and will wait for the incoming connection
*/
listen(sockfd,5);
clilen = sizeof(cli_addr);
/* Accept actual connection from the client */
newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr,
&clilen);
if (newsockfd < 0)
{
kprintf("ERROR on accept");
return;
}
/* If connection is established then start communicating */
memset(buffer,0,256);
n = read( newsockfd,buffer,255 );
if (n < 0)
{
kprintf("ERROR reading from socket");
return;
}
kprintf("Here is the message: %s\n",buffer);
/* Write a response to the client */
n = write(newsockfd,"I got your message",18);
if (n < 0)
{
kprintf("ERROR writing to socket");
return;
}
return 0;
}
void* client_task(void* e)
{
char dir[256];
int sd;
struct sockaddr_in sin;
struct sockaddr_in pin;
struct hostent *hp;
/* fill in the socket structure with host information */
memset(&pin, 0, sizeof(pin));
pin.sin_family = AF_INET;
pin.sin_addr.s_addr = inet_addr("192.168.0.1");
pin.sin_port = htons(5001);
/* grab an Internet domain socket */
if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
kprintf("socket");
return;
}
/* connect to PORT on HOST */
if (connect(sd,(struct sockaddr *) &pin, sizeof(pin)) == -1) {
kprintf("connect");
return;
}
/* send a message to the server PORT on machine HOST */
if (send(sd, "HELLO THERE", strlen("HELLO THERE"), 0) == -1) {
kprintf("send");
return;
}
/* wait for a message to come back from the server */
if (recv(sd, dir, 256, 0) == -1) {
kprintf("recv");
return;
}
/* spew-out the results and bail out of here! */
kprintf("%s\n", dir);
close(sd);
return NULL;
}
int test_init(void)