Coder Social home page Coder Social logo

pstreams's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pstreams's Issues

The error stream doesn't seem to work

I have written a python file containing some junk. I am doing this to find whether pstreams::pstderr is working properly. But only the pstreams::pstdout seems to work. These are the codes I have written.

pstreams_test.cpp

#include <iostream>
#include "pstream.h"
using namespace redi;
main(){
    ipstream proc("python testfile.py", pstreams::pstdout | pstreams::pstderr);
    std::string line;
    while(getline(proc.out(), line))
    {
        std::cout<<line<<std::endl;
    }
    while(getline(proc.err(), line))
    {
        std::cout<<line<<std::endl;
    }
}

testfile.py

you can
write_whatever
junk you want to

If you write a valid python code in testfile.py, I am getting the expected result.

Is there any change I need to make for making the pstderr work? Thanks in advance.

A version of the mainpage.html example with stdin

The example in mainpage.html

const pstreams::pmode mode = pstreams::pstdout|pstreams::pstderr;
ipstream child("echo OUT1; sleep 1; echo ERR >&2; sleep 1; echo OUT2", mode);
char buf[1024];
std::streamsize n;
bool finished[2] = { false, false };
while (!finished[0] || !finished[1])
{
    if (!finished[0])
    {
        while ((n = child.err().readsome(buf, sizeof(buf))) > 0)
            std::cerr.write(buf, n).flush();
        if (child.eof())
        {
            finished[0] = true;
            if (!finished[1])
                child.clear();
        }
    }

    if (!finished[1])
    {
        while ((n = child.out().readsome(buf, sizeof(buf))) > 0)
            std::cout.write(buf, n).flush();
        if (child.eof())
        {
            finished[1] = true;
            if (!finished[0])
                child.clear();
        }
    }
}

Can anyone point me to understand how to change it to write a std::string to stdin before start looping for stdout/stderr output? Thanks.

clang-tidy complains of virtual function dispatch bypass

If you run clang-tidy test_pstreams.cc you get this complaint:

.../pstream.h:1621:7: note: Call to virtual method 'basic_pstreambuf::sync' during destruction bypasses virtual dispatch

I'm not sure what it's babbling about since sync() isn't virtual. Is clang-tidy stoned, or has it actually got a point here?

problem with block in read - glibc

Hi,

I've been using pstreams library for some time, but when I upgraded the kernel to 4.19 / 5.0 (I need patches for nftables API) I started noticing problems with blocked read in glibc. I've created class on top of pstreams since I needed timeout functionality etc. After I found the problem with blocking I extended the conditions to check rdbuf()->in_avail() > 0 before I call getline, but even then it blocks. It happens mostly in async threads, which then hang till I restart whole daemon. I've tried to inspect more in depth states and I'm suspecting some buffer problems. As you can see, there is malformed string at line no.2 s=0x7f87e4000d12 " 7.526 ms.101.84 7.339 ms 1975 ", n=30). It should be something similar to 4 10.26.101.84 7.339 ms 7.526 ms because it is output of traceroute command. I'm not really sure it is problem of pstreams, but I've to start somewhere and I would be grateful for any kind of advice. May be it is problem in glibc. I honestly don't know. I had my own old library to handle external processes and it has similar problems. It always stucks at some kind of read operation on buffer of external process. I've tried to upgrade distribution from Debian Stretch to Debian testing and I'm trying it with stock kernel instead of compiled one. I'm asking you first, because you have most understanding of what is going on inside pstreams and I hope you can at least help me address the issue so I can report it further. PStream.hpp is copy of pstream.h, but I removed some doxygen lines to prevent warnings. I didn't make any other modifications to it, I just prepared it in case I would have to. I'm attaching it because line numbers would probably mismatch with original. https://pastebin.com/uWYKacfr

I can recompile it with original file if needed I just can't say when it will hang. It happens randomly in range of hours and not on every testing machine I run my code on. I've asked similar question on debian glibc mailing list, but may be you can help me address the issue better.

gdb:

where
#0  __libc_read (nbytes=30, buf=0x7f87e4000d12, fd=3) at ../sysdeps/unix/sysv/linux/read.c:26
#1  __libc_read (fd=3, buf=0x7f87e4000d12, nbytes=30) at ../sysdeps/unix/sysv/linux/read.c:24
#2  0x00005594c844075d in redi::basic_pstreambuf<char, std::char_traits<char> >::read (this=0x7f87fa6c10d0, s=0x7f87e4000d12 "  7.526 ms.101.84  7.339 ms  1975 ", n=30) at /root/shaperd/projects/include/PStream.hpp:1980
#3  0x00005594c84405d1 in redi::basic_pstreambuf<char, std::char_traits<char> >::fill_buffer (this=0x7f87fa6c10d0, non_blocking=false) at /root/shaperd/projects/include/PStream.hpp:1927
#4  0x00005594c8440186 in redi::basic_pstreambuf<char, std::char_traits<char> >::underflow (this=0x7f87fa6c10d0) at /root/shaperd/projects/include/PStream.hpp:1839
#5  0x00007f87fb9bd39e in std::basic_streambuf<char, std::char_traits<char> >::sgetc (this=0x7f87fa6c10d0) at /build/gcc-8-XAxxDW/gcc-8-8.3.0/build/x86_64-linux-gnu/libstdc++-v3/include/streambuf:345
#6  std::basic_streambuf<char, std::char_traits<char> >::sgetc (this=<optimized out>) at /build/gcc-8-XAxxDW/gcc-8-8.3.0/build/x86_64-linux-gnu/libstdc++-v3/include/streambuf:345
#7  std::basic_streambuf<char, std::char_traits<char> >::snextc (this=<optimized out>) at /build/gcc-8-XAxxDW/gcc-8-8.3.0/build/x86_64-linux-gnu/libstdc++-v3/include/streambuf:310
#8  std::getline<char, std::char_traits<char>, std::allocator<char> > (__in=..., __str=" 4  10.26.101.84  7.339 ms  7.526 ms", __delim=10 '\n') at ../../../../../src/libstdc++-v3/src/c++98/istream-string.cc:170
#9  0x00005594c84c0f83 in PStreams::Class::GetLine (this=0x7f87fa6c1090, rBuffer=..., rOutput=" 4  10.26.101.84  7.339 ms  7.526 ms") at /root/shaperd/projects/lib/libPStreams.cpp:73

my function from where it blocks

bool Class::GetLine(redi::basic_pstream<char>& rBuffer, string& rOutput)
{
	const string functionName = "PStreams_Class/GetLine";
	rOutput = "";

	while (rdbuf()->exited() == false && rBuffer.rdbuf()->in_avail() == 0)
	{
		WaitFor(false, 1);
	}

	if (cReadDone() == false &&
			rBuffer.rdbuf()->in_avail() > 0 &&
			std::getline(rBuffer, rOutput).good() == true) - it blocks here - libPStreams.cpp:73
	{
		return true;
	}

	else if (cReadDone() == false &&
					(rBuffer.rdbuf()->in_avail() == -1 ||
					 rBuffer.good() == false ||
					 (rBuffer.rdbuf()->in_avail() == 0 && rdbuf()->exited() == true)))
	{
		rBuffer.clear();
		mReadDone = true;
		return false;
	}

	return false;
}// _GetLine@PStreams_Class

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.