Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The sock program doesn't output “You wrote: ” to standard output in the centos6.9 #31

Open
dongbiao830415 opened this issue May 16, 2017 · 2 comments

Comments

@dongbiao830415
Copy link

1、 Result
[root@bogon preeny]# LD_PRELOAD=/root/src/preeny/x86_64-redhat-linux/desock.so ./tests/sock
HI!
1234
[root@bogon preeny]#
2、 This piece of code here doesn't seem to be working。
“FILE *zomg = fdopen(s, "w");”“

@singleghost
Copy link

fflush(zomg); 

Add this line at the end of the file and try again?

@singleghost
Copy link

I think this might be a bug in the 'tests/sock.c', because the socket file is block buffered by default, and if you use fprintf to write to the socket, the characters are saved up and would not be written to the socket immediately.
The debug output of the original ./sock( only print last few lines).

//...
+++ read 5 bytes from 0 (will write to 503)
+++ wrote 5 bytes to 503 (had read from 0)
+++ shutting down desock...
+++ sending SIGINT to thread 3...
+++ read poll() timed out on fd 503
+++ read poll() timed out on fd 0
+++ ... sent!
+++ read poll() timed out on fd 503
+++ ... shutdown complete!

we can observe that when shutting down desock, there is no data come from fd 503 which proves my hypothesis above.
As to resolve this problem, you can also add a line setlinebuf(zomg) before fprintf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants