tatsuhiro-t / spdylay

The experimental SPDY protocol version 2, 3 and 3.1 implementation in C
http://tatsuhiro-t.github.io/spdylay/
MIT License
602 stars 103 forks source link

spdycat: cannot read post data from /dev/stdin #91

Closed chobits closed 9 years ago

chobits commented 11 years ago

Reproduce: $ echo hello | spdycat -2 -v -d - https://localhost:443/test_post ... [ 0.006] send RST_STREAM frame (stream_id=1, status_code=6) ...

Error occurs when spdycat reads post data from /dev/stdin, in which case spdycat will send RST_STREAM(status_code=6(internal error)) to server.

Reason: In spdycat.cc, file_read_callback() use pread() to read post data. If post data file is /dev/stdin (pipe, socket or FIFO), pread() will returns -1 and set errno to ESPIPE. pread() is based on lseek(), but lseek() cannot works with pipe, socket or FIFO file.

tatsuhiro-t commented 11 years ago

This may not work because fd is shared by multiple streams. It would work if only one stream is involved. But once several streams are going active, then read will interleaved and the outgoing data will be corrupted.

chobits commented 11 years ago

If serveral streams are going active and reading POST data from /dev/stdin POST data, it should add a buffer to save data from /dev/stdin in file_read_callback().

It's my understanding that spdycat will use one session with only one stream via following command:

$ cat some_post_data_file | spdycat -2 -d - https://localhost:443/test_post

Is it right?

tatsuhiro-t commented 11 years ago

it should add a buffer to save data from /dev/stdin in file_read_callback().

Yes, but current code does not do this.

It's my understanding that spdycat will use one session with only one stream via following command:

Yes, but spdycat offers options to create multiple streams in one session. For example, using -m20 creates 20 streams.

tatsuhiro-t commented 9 years ago

This issue was fixed via 6c17426a9b4b0676fbde64271f6ebac1ad1ebb33

chobits commented 9 years ago

@tatsuhiro-t I have tested https://github.com/tatsuhiro-t/spdylay/commit/6c17426a9b4b0676fbde64271f6ebac1ad1ebb33. It works as expected.