public int FCGIaccept() {
        int acceptResult = 0;

        /*
         * If first call, mark it and if fcgi save original system properties,
         * If not first call, and  we are cgi, we should be gone.
         */
        if (!acceptCalled){
            isFCGI = System.getProperties().containsKey("FCGI_PORT");
            acceptCalled = true;
            if (isFCGI) {
                /*
                 * save original system properties (nonrequest)
                 * and get a server socket
                 */
                startupProps = new Properties(System.getProperties());
                String str =
                    new String(System.getProperty("FCGI_PORT"));
                if (str.length() <= 0) {
                    return -1;
                }
                int portNum = Integer.parseInt(str);

                try {
                    srvSocket = new ServerSocket(portNum);
                } catch (IOException e) {
                    if (request != null)
                    {
                        request.socket = null;
                    }
                    srvSocket = null;
                    request = null;
                    return -1;
                }
            }
        }
        else {
            if (!isFCGI){
                return -1;
            }
        }
        /*
         * If we are cgi, just leave everything as is, otherwise set up env
         */
        if (isFCGI){
            try {
                acceptResult = FCGIAccept();
            } catch (IOException e) {
                return -1;
            }
            if (acceptResult < 0){
                return -1;
            }

            /*
            * redirect stdin, stdout and stderr to fcgi socket
            */
            System.setIn(new BufferedInputStream(request.inStream, 8192));
            System.setOut(new PrintStream(new BufferedOutputStream(
                request.outStream, 8192)));
            System.setErr(new PrintStream(new BufferedOutputStream(
                request.errStream, 512)));
            System.setProperties(request.params);
        }
        return 0;
    }