LVS
lvs-users
Google
 
Web LinuxVirtualServer.org

Re: data piping

To: Michael McConnell <michael@xxxxxxxxxxxxxx>
Subject: Re: data piping
Cc: debian-firewalls@xxxxxxxxxxxxxxxx, lvs-users@xxxxxxxxxxxxxxxxxxxxxx
From: Terje Eggestad <terje.eggestad@xxxxxxxx>
Date: Thu, 09 Nov 2000 10:19:29 +0100
Hey Mike

You solve this by writing a proxy server. I did this once at my prev employer.
What you do is to rely on a unix system call "select()". Read the man page carefully,
its a bit tricky to use. You can do this in perl, and oetherthings but the sceleton code
here is in C (NB: I haven't checked all the syntak down to parameter order, etc).

main()
{
    int listen_socket, CSsocket;
    fd_set openset, readset;

    /* first we create the socket for incoming connections
    and connect to the Chat Server. */

    /* make sure you read man 7 tcp, man 7 socket, and
    man man 2 socket */

    listen_socket = socket(PF_INET, SOCK_STREAM, 0);
    bind(listen_socket, ...); /* to whatever port, see man bind */
    listen(listen_socket, 10); /* see man listen */

    CSsocket = socket(PF_INET, SOCK_STREAM, 0);
    connect(CSsocket, address of chat server, ...); /* see man connect() */

    FD_ZERO(openset);
    FD_SET(openset, listensocket);
    FD_SET(openset, CSsocket);
 
    while(1) {
        memcpy(readset, openset, sizeof(fd_set);
 
        /* select will go into blocking wait until one of
        the files have something to be read */
        n = select(maxfd, &readset, NULL, NULL, NULL);

        /* we must read from CS first, or we risk deadlock! */
        if (FD_ISSET(openset, CSsocket) {
            rc = read(CSsocket, ..., O_NONBLOCK);

            if(rc == -1 and errno == EAGAIN) break;
            /* figure out which connection to write on */
            write(some_connection, ...);
            continue;
        }
        FD_CLR(CSsocket, openset);
 
        /* accept new connections */
        if (FD_ISSET(listen_socket, openset) {
            new_connection = accept(listen_socket);
            FD_SET(new_connection, openset);
            /* set new maxfd */
        };
        FD_CLR(listen_socket , readset);

        /* now read from clients and send to chat server */
        for (i = 0; i < maxfd, i++) {
            if (FD_ISSET(i, readset);
            read(i, ...);
            if EOF  {
                close (i);
                FD_CLR(i, openset);
                reset maxfd;
                continue;
            }
            write (CSsocket);
        }
    }
}

Michael McConnell wrote:

Yes, I definately should go into more detail about what I want to do.
Seeing as how Windows NT doesn't do socket handling very well it seems
a bad idea to have a Chat server that is dealing with multiple socket
connect,
and since our only developers at this company are Windows NT developers,
there is no way to get this application wrote in Linux. I believe that if I
can
get linux to handle the TCP Handshaking and such, it would prove to be more
stable than having Window NT do it. So the plan is to to have Linux accept
the
connects and do the socket spooling. I would like to take all the data and
direct
it to a stream that would point to the NT Chat Server. The Linux box would
then
deside based on headers and such in the chat server as to which client the
data
belongs to.

Make sense?

Mike
 

-- 
_________________________________________________________________________

Terje Eggestad                  terje.eggestad@xxxxxxxx
Scali Scalable Linux Systems    http://www.scali.com

Olaf Helsets Vei 6              tel:    +47 22 62 89 61 (OFFICE)
P.O.Box 70 Bogerud                      +47 975 31 574  (MOBILE)
N-0621 Oslo                     fax:    +47 22 62 89 51
NORWAY            
_________________________________________________________________________
 
<Prev in Thread] Current Thread [Next in Thread>