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

program in loop doesn't work #10

Open
Trootyl opened this issue Mar 5, 2021 · 2 comments
Open

program in loop doesn't work #10

Trootyl opened this issue Mar 5, 2021 · 2 comments

Comments

@Trootyl
Copy link

Trootyl commented Mar 5, 2021

At first I would like to say thank you, great job.

Unfortunately, I have a problem with your code. When I use it in a loop, the program creates a new process for the socket each time. After a few times the program hangs and crashes a thread in my program that works with this code. I even tried to use the close () and socket() + close() outside loop functions (crashes too). The program crashes after a few passes of the loop (sometimes at beginning, not always at the same time). I tried to debug the code (with prinf() before and after every functions) and the program crashes at different times. Sometimes read, sometimes write. Maybe you have an idea how to solve it?

@Trootyl
Copy link
Author

Trootyl commented Mar 7, 2021

Ok, I debuged this code. In write() you sent 27 (0x1B). When you read() you should receive 28 (0x1C) in 1st byte.
But when I have error I read 220 (DC) in 1st byte. The problem is in reading. When I have bad 1st byte, program goes to sleep (do nothing), but never ends.

There is output.
test

Can you help me with this?

@Trootyl
Copy link
Author

Trootyl commented Mar 7, 2021

If somebody need helps:

fcntl( sockfd, F_SETFL, O_NONBLOCK );
and select() function helps me to unblock socket and handle errors.

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

1 participant