Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7911919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:25:50+00:00 2026-06-03T13:25:50+00:00

I’m trying to write a proxy server and right now I want to implement

  • 0

I’m trying to write a proxy server and right now I want to implement pipelining. I came across a problem though and need assistance. I checked this question but I think it doesn’t apply since I do have data to read from the socket.

The main idea is the following. For each connection I create a thread that handles it and for each request in this connection I want to create a thread that handles that request. So far I have managed to write the code for the first part and it works properly (the thread also handles all the requests of the connection).

Now when I’m trying to read from the socket, from a request handling thread, it hangs. The function that I use to read data is the same as before (in the working version).

void copydata(int from, int to, int len)
{
    char tbuff[BSIZ];
    int n;
    while (len > 0)
    {
        if ((n = read(from, tbuff, BSIZ)) <= 0) break;
        if (write(to, tbuff, n) < n) break;
        len -= n;
    }
}

The from, to and len variables have appropriate values (I checked them). Is there anything that can cause such behaviour?

PS: If more code is required for something please let me know.

EDIT

Here is how the len is acquired:

int contentlength(char *header)
{
    int len = INT_MAX;
    char line[MAX_LINE];

    if (HTTPheadervalue_case(header, "Content-Length", line)) sscanf(line, "%d", &len);
    return len;
}

Calling copydata (where activesocket is a function that opens the socket):

if ((srv = activesocket(host, portno)) < 0)
    {
        sprintf(reshead, "HTTP/1.1 503\r\nContent-Length: 12\r\nConnection: close\r\n\r\nNon-existent");
        write(cli, reshead, strlen(reshead));
    } else
    {
        sprintf(reqhead1, "%s %s HTTP/1.1\r\n", "GET", path);
        if (HTTPheadervalue_case(reqhead1, "Connection", result)) if (strcasecmp(result, "close") == 0) cli_terminate[cli] = TRUE;
        strcat(reqhead1, reqhead);
        write(srv, reqhead1, strlen(reqhead1));
        while (completed[cli] != id)
            ;
        copydata(cli, srv, contentlength(reqhead));
        parseResponse(&srv, cli);
        completed[cli] = (completed[cli] + 1) % ULONG_MAX;
    }

EDIT

One example request header is the following:

Host: www.google.com
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.1.16) Gecko/20120421 Iceweasel/3.5.16 (like Firefox/3.5.16)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Proxy-Connection: keep-alive
Cookie: cookie content

I tried to also strip the keep-alive flag but still the same happens.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T13:25:51+00:00Added an answer on June 3, 2026 at 1:25 pm

    I am guessing this is your problem (from accept(2)):

    On Linux, the new socket returned by accept() does not inherit file status flags such as O_NONBLOCK and O_ASYNC from the listening socket.

    I.e. you need to explicitly make every new accepted socket non-blocking.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.