PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, October 22, 2022

[FIXED] How to simulate EAGAIN or EWOULDBLOCK when send data to socket

 October 22, 2022     c++, epoll, linux, networking, sockets     No comments   

Issue

I have a non-blocking socket to send data to. When sending data to a socket in non-blocking mode, we can get EAGAIN or EWOULDBLOCK if there is not enough space in the socket buffer. If the send call returns EAGAIN or EWOULDBLOCK, I subscribe to the EPOLLOUT event in epoll to know when the socket is ready to resend data in future.

However, in practice, I have never been in a situation where send would return EAGAIN or EWOULDBLOCK and i am not get EPOLLOUT event from epoll. For this reason, I can't test code that resend data when the EPOLLOUT event is received. How i can test my code in this case?


Solution

How i can test my code in this case?

This depends a lot on your kind of application and protocol. In general to trigger the condition the socket write buffer needs to fill up.

This can be done by sending lots of data and making sure that the receiver application does not read from the socket. But this will not work if your specific application protocol does not allow for this, like application protocol has small message size and expects every message to be acknowledged by recipient before transmitting next.

This can also be done by decreasing the size of the socket buffer (using setsockopt with SO_SNDBUFSIZ) - but it is not clear if the minimal buffer size is sufficient to trigger the condition in your specific use case.



Answered By - Steffen Ullrich
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing