void on_write( int fd, short events, void *arg ) { SP_TestClient * client = ( SP_TestClient * ) arg; if( EV_WRITE & events ) { client->mSendMsgs++; if( client->mSendMsgs >= gMsgs ) { snprintf( client->mBuffer, sizeof( client->mBuffer ), "quit\n" ); } else { snprintf( client->mBuffer, sizeof( client->mBuffer ), "mail #%d, It's good to see how people hire; " "that tells us how to market ourselves to them.\n", client->mSendMsgs ); } int len = send( fd, client->mBuffer, strlen( client->mBuffer ), 0 ); if( len <= 0 && EAGAIN != errno ) { fprintf( stderr, "#%d on_write error, errno %d, %s\n", fd, errno, strerror( errno ) ); close_client( client ); } else { if( client->mSendMsgs >= gMsgs ) close_write( client ); } } else { fprintf( stderr, "#%d on_write timeout\n", fd ); close_client( client ); } }
std::string read() { close_write(); size_t buffer_size = 2048; auto buffer = std::unique_ptr<char[]>(new char[buffer_size]); std::string s; for (;;) { DWORD read_count = 0; BOOL read_success = ::ReadFile(_read, buffer.get(), buffer_size, &read_count, 0); if (!read_success || read_count == 0) { break; } //std::min in case full buffer_size has been read in! buffer.get()[std::min(buffer_size - 1, static_cast<size_t>(read_count))] = '\0'; s.append(buffer.get()); } return s; }
~std_pipe() { close_read(); close_write(); }
void close_client( SP_TestClient * client ) { close_write( client ); close_read( client ); }
/// \brief Closes the read and write handles, if not already closed void close() { close_read(); close_write(); }
void close_pipe(struct pipe *p) { close_read(p); close_write(p); }
void irep_pipet::close() { if (!read_closed) close_read(); if (!write_closed) close_write(); }