Fixing some bugs in socket blocking.

There were some bugs in my blocking code that are fixed in this.
I had the setblocking() flag reversed, and wasn't passing the
flag along to the underlying code properly.
This commit is contained in:
Sean Reifschneider
2021-03-19 10:44:29 -06:00
parent 14e70ec876
commit 2ca8e01864
2 changed files with 7 additions and 7 deletions

View File

@@ -28,24 +28,24 @@
int zts_py_setblocking(int fd, int block) int zts_py_setblocking(int fd, int block)
{ {
int new_flags, flags, err = 0; int new_flags, cur_flags, err = 0;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
flags = zts_fcntl(fd, F_GETFL, 0); cur_flags = zts_fcntl(fd, F_GETFL, 0);
if (flags < 0) { if (cur_flags < 0) {
err = ZTS_ERR_SOCKET; err = ZTS_ERR_SOCKET;
goto done; goto done;
} }
if (block) { if (!block) {
new_flags |= ZTS_O_NONBLOCK; new_flags |= ZTS_O_NONBLOCK;
} else { } else {
new_flags &= ~ZTS_O_NONBLOCK; new_flags &= ~ZTS_O_NONBLOCK;
} }
if (new_flags != flags) { if (new_flags != cur_flags) {
err = zts_fcntl(fd, F_SETFL, flags); err = zts_fcntl(fd, F_SETFL, new_flags);
} }
done: done:

View File

@@ -435,7 +435,7 @@ class socket:
"""setblocking(flag) """setblocking(flag)
Sets the socket to blocking mode if flag=True, non-blocking if flag=False.""" Sets the socket to blocking mode if flag=True, non-blocking if flag=False."""
libzt.zts_py_setblocking(self._fd, block) libzt.zts_py_setblocking(self._fd, flag)
def settimeout(self, value): def settimeout(self, value):
"""libzt does not support this (yet)""" """libzt does not support this (yet)"""