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

Issues with write_socket() and read_socket() in hsocket.c #37

Open
PeterCoghlan opened this issue Mar 10, 2015 · 0 comments
Open

Issues with write_socket() and read_socket() in hsocket.c #37

PeterCoghlan opened this issue Mar 10, 2015 · 0 comments

Comments

@PeterCoghlan
Copy link
Contributor

I am attempting to create a new device emulator for Hercules based on commadpt.c I am compiling under VMS but I believe the same issues exist on the major Hercules platforms. Like commadpt.c, I am calling write_socket() and read_socket(). My main reason for using these functions is that it seems to be implied that using send() / recv() or read() / write() directly would cause difficulties on one or other of the main platforms. Firstly, I wonder if this is really the case? Both sets of routines seem to work equally well on my platform. I wonder would send() and recv() be suitable for use on any and all platforms?

Secondly and more importantly, it appears that write_socket() and read_socket() only work correctly with blocking sockets. In the case of non-blocking sockets, such as in commadpt.c and in my code, write_socket() can end up writing some of the requested data to the network and returning -1 to indicate an error, with errno containing EWOULDBLOCK. The problem is that there is no indication of how much data was successfully written and how much was not, so there is no possibility of retrying the write later and getting it to work correctly. If the code is modified to always return the amount of data successfully written, the problem can be avoided and errors can still be detected by the caller examining errno if the returned value indicates the amount of data written was less than requested.

A similar issue exists with read_socket() but I have not been able to come up with a suitable fix as there is an added complication of detecting when the connection has been closed by the other end.

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