fix fgets bug & redis sockReadLine bug

Summary: doc for ``fgets`` from php.net::

    Reading ends when length - 1 bytes have been read, or a newline (which is included in the return value), or an EOF (whichever comes first). If no length is specified, it will keep reading from the stream until it reaches the end of the line.

3 situation when fgets return:

1. read got '\n'
2. eof
3. read length-1 bytes

**but in the code, there is one more situation** ::

         m_writepos = filteredReadToBuffer();
         m_readpos = 0;
         if (bufferedLen() == 0) {
           break;                              /////////////////////////  if read got 0 bytes
         }

Socket::readImpl (hphp/runtime/base/socket.cpp) may return 0 bytes if ``poll`` got timeouted.

so fgets may return a string not endwith '\n'

Closes https://github.com/facebook/hhvm/pull/3713

Reviewed By: @sgolemon

Differential Revision: D1552835
Fix segfault in readline_clear_history

Summary: One test remaining.
Closes https://github.com/facebook/hhvm/pull/3724

Reviewed By: @sgolemon

Differential Revision: D1548684