summaryrefslogtreecommitdiff
path: root/lib/erl_interface/src/misc
diff options
context:
space:
mode:
authorLukas Larsson <lukas@erlang.org>2021-05-04 11:10:56 +0200
committerLukas Larsson <lukas@erlang.org>2021-05-04 11:10:56 +0200
commit20912207142608b12c0574d596af55fdbc731f67 (patch)
tree7005276a62165829610c109c5d4db711671611ab /lib/erl_interface/src/misc
parentc1257880ea316be03a6fb8940889adb80d655fe6 (diff)
parente867f51f9ed482daa5c4c525ab9c25111eb20642 (diff)
downloaderlang-20912207142608b12c0574d596af55fdbc731f67.tar.gz
Merge branch 'lukas/erl_interface/send-inf-tmo-fix/OTP-17358' into maint
* lukas/erl_interface/send-inf-tmo-fix/OTP-17358: ei: Correctly check timeout value vs EI_SCLBK_INF_TMO
Diffstat (limited to 'lib/erl_interface/src/misc')
-rw-r--r--lib/erl_interface/src/misc/ei_portio.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/lib/erl_interface/src/misc/ei_portio.c b/lib/erl_interface/src/misc/ei_portio.c
index f8f777319b..8553283a0c 100644
--- a/lib/erl_interface/src/misc/ei_portio.c
+++ b/lib/erl_interface/src/misc/ei_portio.c
@@ -382,6 +382,12 @@ static int writev_ctx_t__(ei_socket_callbacks *cbs, void *ctx,
do {
error = cbs->writev(ctx, (const void *) iov, iovcnt, len, ms);
} while (error == EINTR);
+
+ /* It should not be possible for writev_ctx_t__ to return EAGAIN,
+ because when the fd is set in non-blocking we always do a select on
+ the fd before trying to write. And if we do not do the select the fd
+ is always in blocking mode. */
+
return error;
}
@@ -395,7 +401,8 @@ int ei_writev_fill_ctx_t__(ei_socket_callbacks *cbs, void *ctx,
struct iovec *current_iov;
int current_iovcnt;
int fd, error;
- int basic;
+ int non_blocking = !(cbs->flags & EI_SCLBK_FLG_FULL_IMPL) &&
+ ms != EI_SCLBK_INF_TMO;
if (!cbs->writev)
return ENOTSUP;
@@ -404,12 +411,10 @@ int ei_writev_fill_ctx_t__(ei_socket_callbacks *cbs, void *ctx,
if (error)
return error;
- basic = !(cbs->flags & EI_SCLBK_FLG_FULL_IMPL);
-
for (sum = 0, i = 0; i < iovcnt; ++i) {
sum += iov[i].iov_len;
}
- if (basic && ms != 0U) {
+ if (non_blocking) {
SET_NONBLOCKING(fd);
}
current_iovcnt = iovcnt;
@@ -420,7 +425,7 @@ int ei_writev_fill_ctx_t__(ei_socket_callbacks *cbs, void *ctx,
error = writev_ctx_t__(cbs, ctx, current_iov, current_iovcnt, &i, ms);
if (error) {
*len = done;
- if (ms != 0U) {
+ if (non_blocking) {
SET_BLOCKING(fd);
}
if (iov_base != NULL) {
@@ -456,7 +461,7 @@ int ei_writev_fill_ctx_t__(ei_socket_callbacks *cbs, void *ctx,
break;
}
}
- if (basic && ms != 0U) {
+ if (non_blocking) {
SET_BLOCKING(fd);
}
if (iov_base != NULL) {
@@ -730,9 +735,10 @@ int ei_read_fill_ctx__(ei_socket_callbacks *cbs, void *ctx, char* buf, ssize_t *
int ei_write_fill_ctx_t__(ei_socket_callbacks *cbs, void *ctx, const char *buf, ssize_t *len, unsigned ms)
{
ssize_t tot = *len, done = 0;
- int error, fd = -1, basic = !(cbs->flags & EI_SCLBK_FLG_FULL_IMPL);
+ int error, fd = -1, non_blocking = !(cbs->flags & EI_SCLBK_FLG_FULL_IMPL) &&
+ ms != EI_SCLBK_INF_TMO;
- if (basic && ms != 0U) {
+ if (non_blocking) {
error = EI_GET_FD__(cbs, ctx, &fd);
if (error)
return error;
@@ -743,14 +749,14 @@ int ei_write_fill_ctx_t__(ei_socket_callbacks *cbs, void *ctx, const char *buf,
error = write_ctx_t__(cbs, ctx, buf+done, &write_len, ms);
if (error) {
*len = done;
- if (basic && ms != 0U) {
+ if (non_blocking) {
SET_BLOCKING(fd);
}
return error;
}
done += write_len;
} while (done < tot);
- if (basic && ms != 0U) {
+ if (non_blocking) {
SET_BLOCKING(fd);
}
*len = done;