Sha256: 85de6336b3cb49f05c895724f446e1e1a0396f8f4755ddf683a38c6999ecf0d9
Contents?: true
Size: 1.26 KB
Versions: 5
Compression:
Stored size: 1.26 KB
Contents
#include "util.h" rResponse::rResponse() : has_headers(false), m_response(NULL), m_use_pipe(false) { } rResponse::~rResponse() { if( m_use_pipe) close(m_pipe[0]); if( m_response ) delete m_response; } bool rResponse::init() { if( pipe(m_pipe) ) { perror("pipe"); return false; } m_use_pipe = true; return true; } static const int READ_SIZE = 1024; static char READ_BUFFER[READ_SIZE]; int rResponse::read_body_partial() { int fd = m_pipe[0]; fd_set rd; struct timeval tv; tv.tv_sec = 1; tv.tv_usec = 0; //1000000; // timeout within a 10th of a second memset(READ_BUFFER, '\0', READ_SIZE); FD_ZERO(&rd); FD_SET(fd, &rd); int retval = select( (fd+1), &rd, NULL, NULL, &tv ); if( retval == 0 ) { printf("select timedout\n"); return 1; } // timeout if( retval == -1 && errno == EINTR ) { return 1; } // not ready yet if( retval < 0 ){ perror("select"); return -1; } // something went wrong if( FD_ISSET(fd, &rd) ) { retval = read(fd,READ_BUFFER,READ_SIZE); if( retval >= 0 ) { // write to the string m_buffer.append(READ_BUFFER, retval); if( retval == 0 ) { FD_CLR(fd,&rd); // remove the file descriptor } return retval; } else { perror("read"); return -1; } } return 0; }
Version data entries
5 entries across 5 versions & 1 rubygems