title: C socket read outputs empty string when using one line telnet statement
body: <p>I have a problem reading a client input through a TCP socket using telnet and echo in one line. It only works when i input the message in a 'normal' telnet session:</p>
  
  <p><strong>Client Console</strong></p>
  
  <pre><code>devbox cehrig # telnet 127.0.0.1 50231
  Trying 127.0.0.1...
  Connected to 127.0.0.1.
  Escape character is '^]'.
  Test Message
  Connection closed by foreign host.
  devbox cehrig # echo "One Liner" | telnet 127.0.0.1 50231
  Trying 127.0.0.1...
  Connected to 127.0.0.1.
  Escape character is '^]'.
  Connection closed by foreign host.
  devbox cehrig # 
  </code></pre>
  
  <p><strong>Server Console</strong></p>
  
  <pre><code>Mon Apr  6 16:36:41 2015: Accepting connections...
  Mon Apr  6 16:36:45 2015: Inbound connection from  127.0.0.1
  Client msg: Test Message
  Mon Apr  6 16:36:48 2015: Accepting connections...
  Mon Apr  6 16:44:06 2015: Inbound connection from  127.0.0.1
  Client msg: 
  Mon Apr  6 16:44:06 2015: Accepting connections...
  </code></pre>
  
  <p>"Client msg" keeps being empty when trying to send data with echo "" | telnet ....</p>
  
  <p>This is the function I'm using to read from the client socket:</p>
  
  <pre><code>void read_socket(int idntef, 
           config_t * cfg)
  {
      int n;
      char * _buf = (char *) malloc(512*sizeof(char));
      char * _cor = (char *) malloc(512*sizeof(char));
      char * _out = _cor;
  
      bzero(_buf, 512);
      bzero(_cor, 512);
  
  
      if((n = read(idntef, _buf, 511)) &lt; 0) {
          _print(stderr, "messages.socketreadfail", cfg, 1);
          _exit(0);
      }
  
      int x = 0;
      while(*_buf != '\n' &amp;&amp; x++ &lt;= 512) {
          *_cor++ = *_buf++;
      }
  
      printf("Client msg: %s\n", _out);
      fflush(stdout);
      shutdown(idntef, 2);
  }
  </code></pre>
  
  <p>Does sbd has a hint for me, what to improve here?</p>