예제 #1
0
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 );
	}
}
예제 #2
0
			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;
			}
예제 #3
0
			~std_pipe() {
				close_read();
				close_write();
			}
예제 #4
0
void close_client( SP_TestClient * client )
{
	close_write( client );
	close_read( client );
}
예제 #5
0
파일: pipe.hpp 프로젝트: JerYme/stlsoft
 /// \brief Closes the read and write handles, if not already closed
 void close()
 {
     close_read();
     close_write();
 }
예제 #6
0
파일: pipe.c 프로젝트: gswirski/mshell
void close_pipe(struct pipe *p) {
  close_read(p);
  close_write(p);
}
예제 #7
0
파일: irep_pipe.cpp 프로젝트: diffblue/cbmc
void irep_pipet::close()
{
    if (!read_closed) close_read();
    if (!write_closed) close_write();
}