<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p><font face="Helvetica, Arial, sans-serif">Hi team,</font></p>
    <p><font face="Helvetica, Arial, sans-serif">            i have
        Faced issue on  Data transfer on buffers.  just like proxy . in
        Both end create and  establish the Connection. while Data
        transferring website has  Loading  infinity.  but i Got content
        partially. can any one help this!</font></p>
    <p><font face="Helvetica, Arial, sans-serif">i copied code here can
        any one help , or suggestion from the Data transfer both end.</font></p>
    <p><font face="Helvetica, Arial, sans-serif">---------------------------------------------------------------------------------------------------------------------------------</font></p>
    <p><font face="Helvetica, Arial, sans-serif">int<br>
        handle_epollin(tproxy_conn_t *conn) {<br>
        <br>
                int numbytes,i;<br>
                int fd_in, fd_out, ret;<br>
                char *data_buf;<br>
                void *buff = malloc(80 * MEBYTE);<br>
                void *sndbuff = malloc(2 * MEBYTE);<br>
                const char *method, *path;<br>
                int pret, minor_version;<br>
                struct phr_header headers[100];<br>
                size_t buflen = 0, prevbuflen = 0,method_len, path_len,
        num_headers;<br>
        <br>
                unsigned int server_session = 0;<br>
        <br>
                //Easy way to determin which socket is ready for reading<br>
                //TODO: Optimize. This one allows me quick lookup for
        conn, but<br>
                //I need to make a system call to determin which socket<br>
                //FILE *stream;<br>
                size_t bufferd_size = gnutls_record_check_pending(conn
        -> serv_session);<br>
                if(bufferd_size)<br>
                        log_trace("data contains on server Record %lu",
        bufferd_size);<br>
                else<br>
                        log_trace("data contains on server Record %lu",
        bufferd_size);<br>
        <br>
                bufferd_size = gnutls_record_check_pending(conn ->
        cli_session);<br>
                if(bufferd_size)<br>
                        log_trace("data contains on client Record %lu",
        bufferd_size);<br>
                else<br>
                        log_trace("data contains on client Record %lu",
        bufferd_size);<br>
        <br>
                if(ioctl(conn->local_fd, FIONREAD, &numbytes) !=
        -1<br>
                                && numbytes > 0){<br>
        <br>
                        server_session = 1;<br>
                        log_trace("IN:[Server Socket is READY for
        Reading]");<br>
                        fd_in = conn->local_fd;<br>
                        fd_out = conn->remote_fd;<br>
        <br>
                } else {<br>
                        server_session = 0;<br>
                        log_trace("IN:[client Socket is READY for
        Reading(origin server)]");<br>
                        fd_in = conn->remote_fd;<br>
                        fd_out = conn->local_fd;<br>
                }<br>
        <br>
                //Optimize with SPLICE_F_MORE later<br>
                /*numbytes = splice(fd_in, NULL,
        conn->splice_pipe[1], NULL, <br>
                  SPLICE_LEN, SPLICE_F_MOVE);*/<br>
        <br>
                log_trace("Hostname : %s", conn -> hostname);<br>
        <br>
                int direction = gnutls_record_get_direction(conn ->
        serv_session);<br>
                if(direction)<br>
                        log_trace("[gnutls serv write Data Direction
        ]");<br>
                else<br>
                        log_trace("[gnutls serv read Data Direction is
        ");<br>
        <br>
                direction = gnutls_record_get_direction(conn ->
        cli_session);<br>
                if(direction)<br>
                        log_trace("[origin Client write Data Direction
        ]");<br>
                else<br>
             log_trace("[origin Client write Data Direction ]");<br>
        <br>
                if(server_session) {<br>
        <br>
                        log_trace("check : Entering Server Session");<br>
                        memset(buff,'\0', MAX_BUF);<br>
        <br>
                        LOOP_CHECK(ret, gnutls_record_recv(conn ->
        serv_session, buff , MAX_BUF));<br>
                        if (ret == 0) {<br>
                                log_error("\n- Peer has closed the
        GnuTLS connection");<br>
        <br>
                        } else if (ret < 0 &&
        gnutls_error_is_fatal(ret) == 0) {<br>
        <br>
                                log_error( "*** Warning:
        %s\n",gnutls_strerror(ret));<br>
                        } else if (ret < 0) {<br>
                                log_error("\n*** Received corrupted "<br>
                                                "data(%d). Closing the
        connection.\n", ret);<br>
                                return -1;<br>
                        } else if (ret > 0) {<br>
        <br>
                        if(read_done == false) {<br>
                                read_done = true;<br>
                                numbytes = ret;<br>
                                prevbuflen = buflen;<br>
                                buflen += ret;<br>
                                num_headers = sizeof(headers) /
        sizeof(headers[0]);<br>
                                pret = phr_parse_request(buff, buflen,
        &method, &method_len, &path, &path_len,<br>
                                                &minor_version,
        headers, &num_headers, prevbuflen);<br>
        <br>
                                if (pret > 0)<br>
                                        log_trace("parsering success");
        /* successfully parsed the request */<br>
                                else if (pret == -1) {<br>
                                        log_error("PArse the Request
        incompleted!");<br>
                                        //TODO: expermental  Need to
        receive again by check checking tls records<br>
                                        return 0; /* request is
        incomplete, continue the loop */<br>
                                }<br>
        <br>
                                if(pret == -2);<br>
                                if (buflen == sizeof(buff)){<br>
                                        log_error(" Error: To long the
        Buffer Failed to Parse the Request");<br>
                                        return 0;<br>
                                }<br>
        <br>
        <br>
                                log_debug("request is %d bytes long",
        pret);<br>
                                log_debug("**method is %.*s",
        (int)method_len, method);<br>
                                log_debug("**path is %.*s",
        (int)path_len, path);<br>
                                log_debug("**HTTP version is 1.%d",
        minor_version);<br>
                                log_debug("**headers:");<br>
                                for (i = 0; i != num_headers; ++i) {<br>
                                        log_debug("**%.*s: %.*s",
        (int)headers[i].name_len, headers[i].name,<br>
                                                       
        (int)headers[i].value_len, headers[i].value);<br>
                                }<br>
        <br>
                                //"GET /
        HTTP/1.1\r\nHost:www.google.org\r\n\r\n"<br>
                                memset(sndbuff,'\0', MAX_BUF);<br>
                                //sprintf(sndbuff,"%s %s
        HTTP/1.%d\r\nHost:%s\r\n\n",method,path,minor_version,conn ->
        hostname);<br>
                                sprintf(sndbuff,"%s %s
        HTTP/1.%d\r\nHost:%s\r\n\n","GET","/",1,conn -> hostname);<br>
        <br>
                                log_debug(" ---- Sndbuff
        contains:%s-----",(char *)sndbuff);<br>
                                /*if(numbytes > 0){<br>
                                  numbytes =
        splice(conn->splice_pipe[0], NULL, fd_out, NULL,<br>
                                  numbytes, SPLICE_F_MOVE);*/<br>
                                //numbytes = splice_all(conn ->
        pipes[0], bp, SPLICE_LEN);<br>
                                log_debug("IN: Handle EPOLL IN inside
        client session");<br>
        <br>
                                LOOP_CHECK(ret, gnutls_record_send(conn
        -> cli_session, sndbuff, strlen(buff)));<br>
                                memset(buff,'\0', MAX_BUF);<br>
                                }<br>
                                else {<br>
                                        LOOP_CHECK(ret,
        gnutls_record_send(conn -> cli_session, buff, strlen(buff)));<br>
                                        memset(buff,'\0', MAX_BUF);<br>
                                }<br>
                        }<br>
        <br>
                        } else {<br>
                                memset(buff,'\0', MAX_BUF);<br>
                                LOOP_CHECK(ret, gnutls_record_recv(conn
        -> cli_session, buff , MAX_BUF));<br>
        <br>
                                if (ret == 0) {<br>
                                        log_debug("\n- Peer has closed
        the GnuTLS connection");<br>
                                } else if (ret < 0<br>
                                                &&
        gnutls_error_is_fatal(ret) == 0) {<br>
                                        log_error("*** Warning: %s",<br>
                                                       
        gnutls_strerror(ret));<br>
                                } else if (ret < 0) {<br>
                                        log_error("\n*** Received
        corrupted "<br>
                                                        "data(%d).
        Closing the connection.\n", ret);<br>
                                        return -1;<br>
                                } else if (ret > 0) {<br>
                                        numbytes = ret;<br>
                                        /*if(numbytes > 0){<br>
                                          numbytes =
        splice(conn->splice_pipe[0], NULL, fd_out, NULL,<br>
                                          numbytes, SPLICE_F_MOVE);*/<br>
        <br>
                                LOOP_CHECK(ret, gnutls_record_send(conn
        -> serv_session, buff, strlen(buff)));<br>
                                //ret = gnutls_record_send(conn ->
        serv_session, buff, strlen(buff));<br>
                                memset(buff,'\0', MAX_BUF);<br>
        <br>
                                if (ret == 0) {<br>
                                        log_debug("\n- Peer has closed
        the GnuTLS connection");<br>
                                } else if (ret < 0<br>
                                                &&
        gnutls_error_is_fatal(ret) == 0) {<br>
                                        log_error("*** Warning: %s\n",<br>
                                                       
        gnutls_strerror(ret));<br>
                                } else if (ret < 0) {<br>
                                        log_error("*** Received
        corrupted "<br>
                                                        "data(%d).
        Closing the connection.\n", ret);<br>
                                        return -1;<br>
                                }<br>
                        }<br>
                }<br>
                return numbytes;<br>
                free(buff);<br>
        }<br>
        <br>
      </font></p>
    <pre class="moz-signature" cols="72">-- 
Thanks,
udhayakumar</pre>
  </body>
</html>