Soquete Linux C: bloqueado na chamada de recv

Na minha aplicação eu criei um segmento para um servidor http simples, em seguida, de dentro do meu aplicativo eu tentei conectar ao servidor http, mas o controle é bloqueado / enforcado na chamada recv.

Mas se tentar se conectar ao servidor http do meu aplicativo usando o comando linux GET, eu serei conectado ao servidor http com sucesso.

De acordo com o meu entendimento, pesquisando o google descobri que esta não é a abordagem correta.

Mas se eu quiser fazer isso, em que devo criar os soquetes para que eu possa conectar o meu servidor http de dentro do aplicativo.

Abaixo está como meu soquete de servidor http criado

pthread_create(&pt_server, NULL, http_srvr, NULL);

//http server handler
void *http_server()
{
    int sockfd, new_fd;             
    struct sockaddr_in my_addr;     
    struct sockaddr_in their_addr;  
    socklen_t sin_size;
    struct sigaction sa;
    int yes=1;

    if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1)
    {
    perror("socket");
    exit(1);
    }

    if (setsockopt(sockfd,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(int)) == -1)
    {
    perror("setsockopt");
    exit(1);
    }

    my_addr.sin_family = AF_INET;               // host byte order
    my_addr.sin_port = htons(HTTP_PORT);        // short, network byte order
    my_addr.sin_addr.s_addr = INADDR_ANY;       // automatically fill with my IP
    memset(&(my_addr.sin_zero), '\0', 8);       // zero the rest of the struct

    if (bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr))== -1)
    {
    perror("bind");
    exit(1);
    }

    printf("Listening to sockets\n");
    if (listen(sockfd, BACKLOG) == -1)
    {
    perror("listen");
    exit(1);
    }

    sa.sa_handler = sigchld_handler; // reap all dead processes
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = SA_RESTART;
    if (sigaction(SIGCHLD, &sa, NULL) == -1)
    {
    perror("sigaction");
    exit(1);
    }

    printf("server: waiting for connections...\n");

    while(1) {  // main accept() loop
        sin_size = sizeof(struct sockaddr_in);
        if ((new_fd = accept(sockfd, (struct sockaddr *)&their_addr,&sin_size)) == -1)
        {
          perror("accept");
          continue;
        }
        printf("server: got connection from %s\n",inet_ntoa(their_addr.sin_addr));

        handle_connection(new_fd);
    }
}

E seguir é como eu estou fazendo http POST para o meu servidor http

  /* create socket */
  if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0)
    return ERRSOCK;
  setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, 0, 0);


  /* connect to server */
  if (connect(s, &server, sizeof(server)) < 0) 
    ret=ERRCONN;
  else {
    if (pfd) *pfd=s;

    /* create header */
    if (proxy) {
      sprintf(header,
"%s http://%.128s:%d/%.256s HTTP/1.0\015\012User-Agent: %s\015\012%s\015\012",
          command,
          http_server1,
          http_port,
          url,
          http_user_agent,
          additional_header
          );
    } else {
      sprintf(header,
"%s /%.256s HTTP/1.0\015\012User-Agent: %s\015\012%s\015\012",
          command,
          url,
          http_user_agent,
          additional_header
          );
    }

    hlg=strlen(header);


    /* send header */   
    if (send(s,header,hlg,0)!=hlg)
      ret= ERRWRHD;

    /* send data */
    else if (length && data && (send(s,data,length,0)!=length) )
      ret= ERRWRDT;

    else {
      /* read result & check */
      ret=http_read_line(s,header,MAXBUF-1);

e seguintes são os conteúdos de http_read_line, e nesta função recv call bloqueada

static int http_read_line (fd,buffer,max) 
     int fd; /* file descriptor to read from */
     char *buffer; /* placeholder for data */
     int max; /* max number of bytes to read */
{ /* not efficient on long lines (multiple unbuffered 1 char reads) */
  int n=0;
  while (n<max) {
    if (recv(fd,buffer,1,0)!=1) {
      n= -n;
      break;
    }
    n++;
    if (*buffer=='\015') continue; /* ignore CR */
    if (*buffer=='\012') break;    /* LF is the separator */
    buffer++;
  }
  *buffer=0;
  return n;
}

questionAnswers(2)

yourAnswerToTheQuestion