Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^9: sysread/syswrite wrappers

by BrowserUk (Pope)
on Oct 12, 2016 at 15:53 UTC ( #1173862=note: print w/replies, xml ) Need Help??


in reply to Re^8: sysread/syswrite wrappers
in thread sysread/syswrite wrappers

hat's because readline reads not only from file, but from buffer as well

It's a difference, but it doesn't mean "they don't work". The effect of the pipe buffering -- and file system caching -- means you get the same effects with sysread.

Even sockets have buffers in the tcp stack.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^10: sysread/syswrite wrappers
by vsespb (Chaplain) on Oct 12, 2016 at 16:16 UTC
    No, it means "they don't work", because if you have some data buffered, select() will return you that no data available for read. So you have data to read, but select tells that you don't. It means they don't work at all.
    File system caching is different, it's cached on OS level, so select will know about that and return "you can read".
      So you have data to read, but select tells that you don't.

      Hm. This is a simple server, using non-block sockets, select and readline.

      It reads one line every 1/10th second ensuring the client will have finished and closed its end of the socket long before the server has read the first buffer load:

      And here a simple client that connects, writes 1 full 4k buffer load, then 2k and a distinct last line.

      If the select was returning eof before the buffer was emptied, you wouldn't see the distinct last line; but I always do!:

      Perhaps you can tell me what I'm doing 'wrong' to make it work? Or maybe the behaviour you describe is just a *nix thing.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.
        I took the stacktrace, on linux: Stacktrace starts with:
        read(4, "abcdefghijklmnopqrstuvwxyz012345"..., 8192) = 6070 write(1, "01285168: 'abcdefghijklmnopqrstu"..., 7501285168: 'abcdefghi +jklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' ) = 75 select(0, NULL, NULL, NULL, {0, 100000}) = 0 (Timeout) select(8, [3 4], NULL, [3 4], NULL) = 1 (in [4]) write(1, "01285168: 'abcdefghijklmnopqrstu"..., 7501285168: 'abcdefghi +jklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' ) = 75 select(0, NULL, NULL, NULL, {0, 100000}) = 0 (Timeout) select(8, [3 4], NULL, [3 4], NULL) = 1 (in [4]) write(1, "01285168: 'abcdefghijklmnopqrstu"..., 7501285168: 'abcdefghi +jklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' ) = 75 select(0, NULL, NULL, NULL, {0, 100000}) = 0 (Timeout) select(8, [3 4], NULL, [3 4], NULL) = 1 (in [4]) write(1, "01285168: 'abcdefghijklmnopqrstu"..., 7501285168: 'abcdefghi +jklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' ) = 75
        You see that it reads 6070 bytes right in one single read. After that it reads nothing, only writes to the screen. But select indeed returns right filehandle. Okay, end of stacktrace:
        select(0, NULL, NULL, NULL, {0, 100000}) = 0 (Timeout) select(8, [3 4], NULL, [3 4], NULL) = 1 (in [4]) write(1, "01285168: 'abcdefghijklmnopqrstu"..., 7501285168: 'abcdefghi +jklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' ) = 75 select(0, NULL, NULL, NULL, {0, 100000}) = 0 (Timeout) select(8, [3 4], NULL, [3 4], NULL) = 1 (in [4]) write(1, "01285168: 'abcdefghijklmnopqrstu"..., 7501285168: 'abcdefghi +jklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' ) = 75 select(0, NULL, NULL, NULL, {0, 100000}) = 0 (Timeout) select(8, [3 4], NULL, [3 4], NULL) = 1 (in [4]) write(1, "01285168: 'This is the last line"..., 3401285168: 'This is t +he last line' ) = 34 select(0, NULL, NULL, NULL, {0, 100000}) = 0 (Timeout) select(8, [3 4], NULL, [3 4], NULL) = 1 (in [4]) read(4, "", 8192) = 0 close(3) = 0 close(4) = 0 rt_sigaction(SIG_0, NULL, {0x7fb26fce06b2, ~[RT_1 RT_2 RT_3 RT_4 RT_5 +RT_6 RT_7 RT_8 RT_9 RT_10 RT_11 RT_12 RT_13 RT_14 RT_15 RT_16 RT_17 R +T_18 RT_19 RT_20 RT_21 RT_22 RT_23 RT_24 RT_25 RT_26 RT_27 RT_28 RT_2 +9 RT_30 RT_31], 0}, 8) = -1 EINVAL (Invalid argument) rt_sigaction(SIGHUP, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGINT, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGQUIT, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGILL, NULL, {SIG_DFL, [], 0}, 8) = 0
        select returns right filehandle again, and.. read returns EOF. So whole the time select was triggered by eof event (EOF is "can_read" too). Let's check. I added sleep before closing socket in client:
        sleep; close $server;
        and server hanged in the middle. So, without EOF event it stucks. New stacktrace:
        ioctl(4, 0x8004667e, 0x1b77ff0) = -1 ENOTTY (Inappropriate ioc +tl for device) select(8, [3 4], NULL, [3 4], NULL) = 1 (in [4]) read(4, "abcdefghijklmnopqrstuvwxyz012345"..., 8192) = 1071 write(1, "01d4c168: 'abcdefghijklmnopqrstu"..., 7501d4c168: 'abcdefghi +jklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' ) = 75 select(0, NULL, NULL, NULL, {0, 100000}) = 0 (Timeout) select(8, [3 4], NULL, [3 4], NULL) = 1 (in [4]) write(1, "01d4c168: 'abcdefghijklmnopqrstu"..., 7501d4c168: 'abcdefghi +jklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' ) = 75 select(0, NULL, NULL, NULL, {0, 100000}) = 0 (Timeout) select(8, [3 4], NULL, [3 4], NULL) = 1 (in [4]) write(1, "01d4c168: 'abcdefghijklmnopqrstu"..., 7501d4c168: 'abcdefghi +jklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' ) = 75 select(0, NULL, NULL, NULL, {0, 100000}) = 0 (Timeout) select(8, [3 4], NULL, [3 4], NULL) = 1 (in [4]) write(1, "01d4c168: 'abcdefghijklmnopqrstu"..., 7501d4c168: 'abcdefghi +jklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' ) = 75 select(0, NULL, NULL, NULL, {0, 100000}) = 0 (Timeout) select(8, [3 4], NULL, [3 4], NULL) = 1 (in [4]) write(1, "01d4c168: 'abcdefghijklmnopqrstu"..., 7501d4c168: 'abcdefghi +jklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' ) = 75 select(0, NULL, NULL, NULL, {0, 100000}) = 0 (Timeout) select(8, [3 4], NULL, [3 4], NULL) = 1 (in [4]) write(1, "01d4c168: 'abcdefghijklmnopqrstu"..., 7501d4c168: 'abcdefghi +jklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' ) = 75 select(0, NULL, NULL, NULL, {0, 100000}) = 0 (Timeout) select(8, [3 4], NULL, [3 4], NULL) = 1 (in [4]) write(1, "01d4c168: 'abcdefghijklmnopqrstu"..., 7501d4c168: 'abcdefghi +jklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' ) = 75 select(0, NULL, NULL, NULL, {0, 100000}) = 0 (Timeout) select(8, [3 4], NULL, [3 4], NULL) = 1 (in [4]) write(1, "01d4c168: 'abcdefghijklmnopqrstu"..., 7501d4c168: 'abcdefghi +jklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' ) = 75 select(0, NULL, NULL, NULL, {0, 100000}) = 0 (Timeout) select(8, [3 4], NULL, [3 4], NULL) = 1 (in [4]) write(1, "01d4c168: 'abcdefghijklmnopqrstu"..., 7501d4c168: 'abcdefghi +jklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' ) = 75 [cut similar lines] select(0, NULL, NULL, NULL, {0, 100000}) = 0 (Timeout) select(8, [3 4], NULL, [3 4], NULL) = 1 (in [4]) write(1, "01d4c168: 'abcdefghijklmnopqrstu"..., 7501d4c168: 'abcdefghi +jklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' ) = 75 select(0, NULL, NULL, NULL, {0, 100000}) = 0 (Timeout) select(8, [3 4], NULL, [3 4], NULL) = 1 (in [4]) read(4, "abcdefghijklmnopqrstuvwxyz012345"..., 8192) = 4999 write(1, "01d4c168: 'abcdefghijklmnopqrstu"..., 7501d4c168: 'abcdefghi +jklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' ) = 75 select(0, NULL, NULL, NULL, {0, 100000}) = 0 (Timeout) select(8, [3 4], NULL, [3 4], NULL
        last select is not finished. means process stuck on it.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1173862]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2019-12-15 05:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?