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:
@@ -28,24 +28,24 @@
|
||||
|
||||
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
|
||||
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;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (block) {
|
||||
if (!block) {
|
||||
new_flags |= ZTS_O_NONBLOCK;
|
||||
} else {
|
||||
new_flags &= ~ZTS_O_NONBLOCK;
|
||||
}
|
||||
|
||||
if (new_flags != flags) {
|
||||
err = zts_fcntl(fd, F_SETFL, flags);
|
||||
if (new_flags != cur_flags) {
|
||||
err = zts_fcntl(fd, F_SETFL, new_flags);
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
@@ -435,7 +435,7 @@ class socket:
|
||||
"""setblocking(flag)
|
||||
|
||||
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):
|
||||
"""libzt does not support this (yet)"""
|
||||
|
||||
Reference in New Issue
Block a user